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

Change default value of webserver.threads to 50 #2305

Merged
merged 1 commit into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
30 changes: 11 additions & 19 deletions src/webserver/webserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
8 changes: 3 additions & 5 deletions test/pihole.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading