$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
1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
* webserver.c: warning fix
-
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)) >
}
} 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);
+ }
}
#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"
void display_customize_iconbar(void);
void commit_iconbar(void);
int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
+void spawn_another_worker_thread(void);
/* 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();
}
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 {