From 99e5e9fca01d8a1c5ca33a731353eb2294f78107 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 19 Jan 2023 08:34:33 +0100 Subject: [PATCH] customizable number of threadpool threads --- src/librssguard/definitions/definitions.h | 3 +++ src/librssguard/miscellaneous/application.cpp | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/librssguard/definitions/definitions.h b/src/librssguard/definitions/definitions.h index 59660aedf..1a11db6c4 100644 --- a/src/librssguard/definitions/definitions.h +++ b/src/librssguard/definitions/definitions.h @@ -94,6 +94,7 @@ #define RELOAD_MODEL_BORDER_NUM 10 #define COOKIE_URL_IDENTIFIER ":COOKIE:" #define DEFAULT_NOTIFICATION_VOLUME 50 +#define MAX_THREADPOOL_THREADS 32 #define GOOGLE_SEARCH_URL "https://www.google.com/search?q=%1&ie=utf-8&oe=utf-8" #define GOOGLE_SUGGEST_URL "http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=%1" @@ -139,6 +140,8 @@ #define CLI_QUIT_INSTANCE "q" #define CLI_IS_RUNNING "a" +#define CLI_THREADS "threads" + #define HTTP_HEADERS_ACCEPT "Accept" #define HTTP_HEADERS_CONTENT_TYPE "Content-Type" #define HTTP_HEADERS_CONTENT_LENGTH "Content-Length" diff --git a/src/librssguard/miscellaneous/application.cpp b/src/librssguard/miscellaneous/application.cpp index d62f431fd..4631089b4 100644 --- a/src/librssguard/miscellaneous/application.cpp +++ b/src/librssguard/miscellaneous/application.cpp @@ -946,9 +946,13 @@ void Application::setupCustomDataFolder(const QString& data_folder) { void Application::setupGlobalThreadPool() { auto ideal_th_count = QThread::idealThreadCount(); + int custom_threads = m_cmdParser.value(QSL(CLI_THREADS)).toInt(); - if (ideal_th_count > 1) { - QThreadPool::globalInstance()->setMaxThreadCount((std::min)(32, 2 * ideal_th_count)); + if (custom_threads > 0) { + QThreadPool::globalInstance()->setMaxThreadCount((std::min)(MAX_THREADPOOL_THREADS, custom_threads)); + } + else if (ideal_th_count > 1) { + QThreadPool::globalInstance()->setMaxThreadCount((std::min)(MAX_THREADPOOL_THREADS, 2 * ideal_th_count)); } // NOTE: Do not expire threads so that their IDs are not reused. @@ -1156,12 +1160,17 @@ void Application::fillCmdArgumentsParser(QCommandLineParser& parser) { QSL("Use custom port for AdBlock server. It is highly recommended to use values higher than 1024."), QSL("port")); + QCommandLineOption custom_threads(QSL(CLI_THREADS), + QSL("Specify number of threads. Note that number cannot be higher than %1.") + .arg(MAX_THREADPOOL_THREADS), + QSL("count")); + parser.addOptions({ help, version, log_file, custom_data_folder, disable_singleinstance, disable_only_debug, disable_debug, #if defined(USE_WEBENGINE) force_nowebengine, #endif - forced_style, adblock_port, custom_ua + forced_style, adblock_port, custom_ua, custom_threads }); parser.addPositionalArgument(QSL("urls"), QSL("List of URL addresses pointing to individual online feeds which should be added."),