From 8b461326d85241ef39bb59dd1daea50d6c0de7f4 Mon Sep 17 00:00:00 2001 From: antao Date: Mon, 17 Dec 2018 14:22:25 +0800 Subject: [PATCH] Modify the ConfigLoader.cc file --- config.example.json | 7 ++++--- lib/src/ConfigLoader.cc | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/config.example.json b/config.example.json index d9329e86..3a0ca063 100644 --- a/config.example.json +++ b/config.example.json @@ -47,8 +47,9 @@ } ],*/ "app": { - //threads_num:num of threads,1 by default - "threads_num": 16, + //threads_num:the number of IO threads,1 by default, if the value is set to 0, the number of threads + //will be the number of processors. + "threads_num": 1, //enable_session:false by default "enable_session": false, "session_timeout": 0, @@ -132,4 +133,4 @@ //of the connection without read or write "idle_connection_timeout": 60 } -} \ No newline at end of file +} diff --git a/lib/src/ConfigLoader.cc b/lib/src/ConfigLoader.cc index c30b726b..7ce11cea 100644 --- a/lib/src/ConfigLoader.cc +++ b/lib/src/ConfigLoader.cc @@ -19,6 +19,8 @@ #include #include #include +#include + using namespace drogon; ConfigLoader::ConfigLoader(const std::string &configFile) @@ -136,6 +138,14 @@ static void loadApp(const Json::Value &app) return; //threads number auto threadsNum = app.get("threads_num", 1).asUInt64(); + if (threadsNum == 0) + { + //set the number to the number of processors. + threadsNum = std::thread::hardware_concurrency(); + LOG_DEBUG << "The number of processors is " << threadsNum; + } + if (threadsNum < 1) + threadsNum = 1; drogon::app().setThreadNum(threadsNum); //session auto enableSession = app.get("enable_session", false).asBool();