diff --git a/src/config/config.c b/src/config/config.c index 5bb8f11c6..c26a1f84e 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -1008,10 +1008,10 @@ static void initConfig(struct config *conf) conf->webserver.port.c = validate_stub; // Type-based checking + civetweb syntax checking conf->webserver.threads.k = "webserver.threads"; - conf->webserver.threads.h = "Maximum number of worker threads allowed.\n The Pi-hole web server handles each incoming connection in a separate thread. Therefore, the value of this option is effectively the number of concurrent HTTP connections that can be handled. Any other connections are queued until they can be processed by a unoccupied thread.\n The default value of 0 means that the number of threads is automatically determined by the number of online CPU cores minus 1 (e.g., launching up to 8-1 = 7 threads on 8 cores). Any other value specifies the number of threads explicitly. A hard-coded maximum of 64 threads is enforced for this option.\n The total number of threads you see may be lower than the configured value as threads are only created when needed due to incoming connections."; + conf->webserver.threads.h = "Maximum number of worker threads allowed.\n The Pi-hole web server handles each incoming connection in a separate thread. Therefore, the value of this option is effectively the number of concurrent HTTP connections that can be handled. Any other connections are queued until they can be processed by a unoccupied thread.\n The total number of threads you see may be lower than the configured value as threads are only created when needed due to incoming connections.\n The value 0 means the number of threads is 50 (as per default settings of CivetWeb) for backwards-compatible behavior."; conf->webserver.threads.t = CONF_UINT; conf->webserver.threads.f = FLAG_RESTART_FTL; - conf->webserver.threads.d.ui = 0; + conf->webserver.threads.d.ui = 50; conf->webserver.threads.c = validate_stub; // Only type-based checking conf->webserver.headers.k = "webserver.headers"; diff --git a/src/webserver/webserver.c b/src/webserver/webserver.c index 4cdcf33ad..cbecb38c7 100644 --- a/src/webserver/webserver.c +++ b/src/webserver/webserver.c @@ -397,28 +397,20 @@ void http_init(void) return; } - char num_threads[3] = { 0 }; - // Calculate number of threads for the web server - // any positive number = number of threads (limited to at most MAX_WEBTHREADS) - // 0 = the number of online processors (at least 1, no more than 16) - // For the automatic option, we use the number of available (= online) - // cores which may be less than the total number of cores in the system, - // e.g., if a virtualization environment is used and fewer cores are - // assigned to the VM than are available on the host. - sprintf(num_threads, "%d", get_nprocs() > 8 ? 16 : 2*get_nprocs()); - - if(config.webserver.threads.v.ui > 0) + // Get maximum number of threads for webserver + char num_threads[16] = { 0 }; + if(config.webserver.threads.v.ui == 0) { - const unsigned int threads = LIMIT_MIN_MAX(config.webserver.threads.v.ui, 1, MAX_WEBTHREADS); - snprintf(num_threads, sizeof(num_threads), "%u", threads); - } - else // Automatic thread calculation - { - const int nprocs = get_nprocs(); - const unsigned int threads = LIMIT_MIN_MAX(nprocs - 1, 1, 16); - snprintf(num_threads, sizeof(num_threads), "%u", threads); + // For compatibility with older versions, set the number of + // threads to the default value (50) if it was 0. Before Pi-hole + // FTL v6.0.4, the number of threads was computed in dependence + // of the number of CPUs available. This is no longer the case. + config.webserver.threads.v.ui = 50; } + snprintf(num_threads, sizeof(num_threads), "%u", config.webserver.threads.v.ui); + num_threads[sizeof(num_threads) - 1] = '\0'; + /* Initialize the library */ log_web("Initializing HTTP server on ports \"%s\"", config.webserver.port.v.s); unsigned int features = MG_FEATURES_FILES | diff --git a/test/pihole.toml b/test/pihole.toml index 605d234b9..005abd5db 100644 --- a/test/pihole.toml +++ b/test/pihole.toml @@ -669,13 +669,11 @@ # Therefore, the value of this option is effectively the number of concurrent HTTP # connections that can be handled. Any other connections are queued until they can be # processed by a unoccupied thread. - # The default value of 0 means that the number of threads is automatically determined - # by the number of online CPU cores minus 1 (e.g., launching up to 8-1 = 7 threads on - # 8 cores). Any other value specifies the number of threads explicitly. A hard-coded - # maximum of 64 threads is enforced for this option. # The total number of threads you see may be lower than the configured value as # threads are only created when needed due to incoming connections. - threads = 0 + # The value 0 means the number of threads is 50 (as per default settings of CivetWeb) + # for backwards-compatible behavior. + threads = 50 # Additional HTTP headers added to the web server responses. # The headers are added to all responses, including those for the API.