Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

异步队列日志容量没有设置成功吧 #108

Open
peng-yq opened this issue May 13, 2024 · 0 comments
Open

异步队列日志容量没有设置成功吧 #108

peng-yq opened this issue May 13, 2024 · 0 comments

Comments

@peng-yq
Copy link

peng-yq commented May 13, 2024

main.cpp

int main() {
    /* 守护进程 后台运行 */
    //daemon(1, 0); 

    WebServer server(
        1316, 3, 60000, false,             /* 端口 ET模式 timeoutMs 优雅退出  */
        3306, "root", "root", "webserver", /* Mysql配置 */
        12, 6, true, 1, 1024);             /* 连接池数量 线程池数量 日志开关 日志等级 日志异步队列容量 */
    server.Start();
} 

webserver,cpp

Log::Instance()->init(logLevel, "./log", ".log", logQueSize);

log.cpp

void Log::init(int level = 1, const char* path, const char* suffix,
    int maxQueueSize) {
    isOpen_ = true;
    level_ = level;
    if(maxQueueSize > 0) {
        isAsync_ = true;
        if(!deque_) {
            unique_ptr<BlockDeque<std::string>> newDeque(new BlockDeque<std::string>);
            deque_ = move(newDeque);
            
            std::unique_ptr<std::thread> NewThread(new thread(FlushLogThread));
            writeThread_ = move(NewThread);
        }
    } else {
        isAsync_ = false;
    }
}

blockqueue.h

explicit BlockDeque(size_t MaxCapacity = 1000);
template<class T>
BlockDeque<T>::BlockDeque(size_t MaxCapacity) :capacity_(MaxCapacity) {
    assert(MaxCapacity > 0);
    isClose_ = false;
}

当设置了 logQueSize > 0,实际的异步日志队列容量并不是设置的logQueSize,而是默认的1000

unique_ptr<BlockDeque<std::string>> newDeque(new BlockDeque<std::string>);

应该修改为

unique_ptr<BlockDeque<std::string>> newDeque(new BlockDeque<std::string>(logQueSize));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant