]> code.citadel.org Git - citadel.git/commitdiff
* Changed the thread pool management algorithm. Detecting idle time between
authorArt Cancro <ajc@citadel.org>
Mon, 9 Feb 2004 03:37:57 +0000 (03:37 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 9 Feb 2004 03:37:57 +0000 (03:37 +0000)
  socket accepts was not working reliably on all systems, so we now follow
  the same algorithm as the Citadel server (spawn more threads when number
  of sessions < number of threads, but keep constrained to pre-defined
  minimum and maximum thread count)

webcit/ChangeLog
webcit/context_loop.c
webcit/webcit.h
webcit/webserver.c

index 7a0ff9cc659befa6679f689ff69061e4c32ad7d6..79365084b917260a74323c0e95376d4efc097567 100644 (file)
@@ -1,4 +1,11 @@
 $Log$
+Revision 504.2  2004/02/09 03:37:57  ajc
+* Changed the thread pool management algorithm.  Detecting idle time between
+  socket accepts was not working reliably on all systems, so we now follow
+  the same algorithm as the Citadel server (spawn more threads when number
+  of sessions < number of threads, but keep constrained to pre-defined
+  minimum and maximum thread count)
+
 Revision 504.1  2004/02/03 03:09:51  ajc
 * THIS IS 5.04
 
@@ -1636,4 +1643,3 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index ec6605924284dfd6ffa0b3bf725ec5069eee9f68..1832afb795466b0adc86a7f1ca9017e3c728fee0 100644 (file)
@@ -61,11 +61,15 @@ void free_attachments(struct wcsession *sess) {
 void do_housekeeping(void)
 {
        struct wcsession *sptr, *ss, *session_to_kill;
+       int num_sessions = 0;
+       static int num_threads = MIN_WORKER_THREADS;
 
        do {
                session_to_kill = NULL;
                pthread_mutex_lock(&SessionListMutex);
+               num_sessions = 0;
                for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
+                       ++num_sessions;
 
                        /* Kill idle sessions */
                        if ((time(NULL) - (sptr->lastreq)) >
@@ -107,6 +111,17 @@ BREAKOUT:  pthread_mutex_unlock(&SessionListMutex);
                }
 
        } while (session_to_kill != NULL);
+
+       /*
+        * See if we need more worker threads
+        */
+       while ( (num_sessions > num_threads)
+             && (num_threads <= MAX_WORKER_THREADS) ) {
+               spawn_another_worker_thread();
+               ++num_threads;
+               lprintf(3, "There are %d sessions and %d threads active.\n",
+                       num_sessions, num_threads);
+       }
 }
 
 
index 233770a1f9f3ba69728eb0ddfc0bc0d1a18ce585..eb08e8b5f77eae6ca16faf50d0bf3de2fd45fc99 100644 (file)
@@ -37,7 +37,8 @@
 #define QU                     (3)
 #define TARGET                 "webcit01"      /* Target for inline URL's */
 #define HOUSEKEEPING           15              /* Housekeeping frequency */
-#define INITIAL_WORKER_THREADS 5
+#define MIN_WORKER_THREADS     5
+#define MAX_WORKER_THREADS     250
 #define LISTEN_QUEUE_LENGTH    100             /* listen() backlog queue */
 
 #define USERCONFIGROOM         "My Citadel Config"
@@ -427,3 +428,4 @@ void do_iconbar(void);
 void display_customize_iconbar(void);
 void commit_iconbar(void);
 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
+void spawn_another_worker_thread(void);
index 7924feaeb0809ba36986277cfaee8086a2837ba5..199379dc567273d733da9d50d5502408ac31f659 100644 (file)
@@ -307,7 +307,7 @@ int main(int argc, char **argv)
 
 
        /* Start a few initial worker threads */
-       for (i=0; i<(INITIAL_WORKER_THREADS); ++i) {
+       for (i=0; i<(MIN_WORKER_THREADS); ++i) {
                spawn_another_worker_thread();
        }
 
@@ -324,19 +324,10 @@ void worker_entry(void) {
        int ssock;
        int i = 0;
        int time_to_die = 0;
-       time_t start_time, stop_time;
 
        do {
                /* Only one thread can accept at a time */
-               start_time = time(NULL);
                ssock = accept(msock, NULL, 0);
-               stop_time = time(NULL);
-
-               /* Augment the thread pool if we're not blocking at all */
-               if ( (stop_time - start_time) == 0L) {
-                       spawn_another_worker_thread();
-               }
-
                if (ssock < 0) {
                        lprintf(2, "accept() failed: %s\n", strerror(errno));
                } else {