From b26b9a4af7901e3a80354248c92baafb8a994c18 Mon Sep 17 00:00:00 2001 From: Dave West Date: Fri, 30 Nov 2007 22:24:26 +0000 Subject: [PATCH] Changed the way we create aditional threads. One for every connection is wastefull. Each worker can usually handle 3-4 connections with ease. --- citadel/server_main.c | 37 ++++++++++++++++++++++++++++++++----- citadel/sysdep.c | 9 --------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/citadel/server_main.c b/citadel/server_main.c index 69dea6881..3715bb356 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -407,24 +407,51 @@ void go_threading(void) ); #endif CtdlThreadStop(last_worker); -// ctdl_thread_internal_change_state (last_worker, CTDL_THREAD_STOP_REQ); -// pthread_mutex_lock(&last_worker->ThreadMutex); -// pthread_cond_signal(&last_worker->ThreadCond); -// pthread_mutex_unlock(&last_worker->ThreadMutex); } } + /* + * If all our workers are working hard, start some more to help out + * with things + */ + begin_critical_section(S_THREAD_LIST); + /* FIXME: come up with a better way to dynamically alter the number of threads + * based on the system load + */ +// if ((CtdlThreadGetWorkers() < config.c_max_workers) && (CtdlThreadGetWorkers() < num_sessions)) + // && (CtdlThreadLoadAvg < 90) ) + if ((CtdlThreadGetWorkers() < config.c_max_workers) && (CtdlThreadWorkerAvg > 60) && (CtdlThreadLoadAvg < 90) ) + { + end_critical_section(S_THREAD_LIST); + for (i=0; i<5 ; i++) +// for (i=0; i< (num_sessions - CtdlThreadGetWorkers()) ; i++) +// for (i=0; i< (10 - (55 - CtdlThreadWorkerAvg) / CtdlThreadWorkerAvg / CtdlThreadGetWorkers()) ; i++) + { + begin_critical_section(S_THREAD_LIST); + ctdl_internal_create_thread("Worker Thread", + CTDLTHREAD_BIGSTACK + CTDLTHREAD_WORKER, + worker_thread, + NULL + ); + end_critical_section(S_THREAD_LIST); + } + } + else + end_critical_section(S_THREAD_LIST); - CtdlThreadSleep(1); begin_critical_section(S_THREAD_LIST); ctdl_internal_thread_gc(); end_critical_section(S_THREAD_LIST); + if (CtdlThreadGetCount() <= 1) // Shutting down clean up the garbage collector { begin_critical_section(S_THREAD_LIST); ctdl_internal_thread_gc(); end_critical_section(S_THREAD_LIST); } + + if (CtdlThreadGetCount()) + CtdlThreadSleep(1); } /* * If the above loop exits we must be shutting down since we obviously have no threads diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 552183dd2..6be3f2cca 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -1863,15 +1863,6 @@ void dead_session_purge(int force) { rem = rem->next; free(ptr); } - - /* Raise the size of the worker thread pool if necessary. */ - begin_critical_section(S_THREAD_LIST); - if ( (num_sessions > num_workers) - && (num_workers < config.c_max_workers) ) { - ctdl_internal_create_thread("Worker Thread", CTDLTHREAD_BIGSTACK + CTDLTHREAD_WORKER, worker_thread, NULL); - } - end_critical_section(S_THREAD_LIST); - // FIXME: reduce the number of worker threads too } -- 2.30.2