File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -227,11 +227,17 @@ bool server_http_context::init(const common_params & params) {
227227
228228 int n_threads_http = params.n_threads_http ;
229229 if (n_threads_http < 1 ) {
230- // +2 threads for monitoring endpoints
231- n_threads_http = std::max (params.n_parallel + 2 , (int32_t ) std::thread::hardware_concurrency () - 1 );
230+ // +4 threads for monitoring, health and some threads reserved for MCP and other tasks in the future
231+ n_threads_http = std::max (params.n_parallel + 4 , (int32_t ) std::thread::hardware_concurrency () - 1 );
232232 }
233233 LOG_INF (" %s: using %d threads for HTTP server\n " , __func__, n_threads_http);
234- srv->new_task_queue = [n_threads_http] { return new httplib::ThreadPool (n_threads_http); };
234+ srv->new_task_queue = [n_threads_http] {
235+ // spawn n_threads_http fixed thread (always alive), while allow up to 1024 max possible additional threads
236+ // when n_threads_http is used, server will create new "dynamic" threads that will be destroyed after processing each request
237+ // ref: https://github.com/yhirose/cpp-httplib/pull/2368
238+ size_t max_threads = (size_t )n_threads_http + 1024 ;
239+ return new httplib::ThreadPool (n_threads_http, max_threads);
240+ };
235241
236242 //
237243 // Web UI setup
You can’t perform that action at this time.
0 commit comments