Changed the way we create aditional threads. One for every connection is
authorDave West <davew@uncensored.citadel.org>
Fri, 30 Nov 2007 22:24:26 +0000 (22:24 +0000)
committerDave West <davew@uncensored.citadel.org>
Fri, 30 Nov 2007 22:24:26 +0000 (22:24 +0000)
wastefull. Each worker can usually handle 3-4 connections with ease.

citadel/server_main.c
citadel/sysdep.c

index 69dea688188025edb7d2ba56e68a1bea3224a7b7..3715bb356fba85b797906885d5c864317f92bb60 100644 (file)
@@ -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
index 552183dd2a215eafc4ba30a6c77228be1b94ba59..6be3f2cca11739d35cabfda447d548cdc57bbcb3 100644 (file)
@@ -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
 }