cvs commit: apache-2.0/mpm/src/modules/mpm/dexter dexter.c
manoj 99/08/13 12:47:02 Modified:mpm/src/modules/mpm/dexter dexter.c Log: Get rid of the single-child worker thread implementation for now. It's a pain keeping track of them both, and it can be added back easily.. Revision ChangesPath 1.23 +1 -133apache-2.0/mpm/src/modules/mpm/dexter/dexter.c Index: dexter.c === RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/dexter/dexter.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -u -r1.22 -r1.23 --- dexter.c 1999/08/13 06:57:46 1.22 +++ dexter.c 1999/08/13 19:47:01 1.23 @@ -893,23 +893,15 @@ } static void *worker_thread(void *); -static void *worker_thread_one_child(void *); /* Starts a thread as long as we're below max_threads */ static int start_thread(void) { pthread_t thread; -void *(*thread_function)(void *); pthread_mutex_lock(worker_thread_count_mutex); if (worker_thread_count max_threads) { -if (num_daemons == 1) { -thread_function = worker_thread_one_child; -} -else { -thread_function = worker_thread; -} -if (pthread_create(thread, worker_thread_attr, thread_function, +if (pthread_create(thread, worker_thread_attr, worker_thread, worker_thread_free_ids[worker_thread_count])) { ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, pthread_create: unable to create worker thread); @@ -964,130 +956,6 @@ } /* idle_thread_count should be incremented before starting a worker_thread */ - -static void *worker_thread_one_child(void *arg) -{ -struct sockaddr sa_client; -int csd = -1; -pool *tpool;/* Pool for this thread */ -pool *ptrans;/* Pool for per-transaction stuff */ -int sd = -1; -int srv; -int poll_count = 0; -static int curr_pollfd = 0; -size_t len = sizeof(struct sockaddr); -int thread_just_started = 1; -int thread_num = *((int *) arg); -long conn_id = child_num * HARD_THREAD_LIMIT + thread_num; - -pthread_mutex_lock(thread_pool_create_mutex); -tpool = ap_make_sub_pool(thread_pool_parent); -pthread_mutex_unlock(thread_pool_create_mutex); -ptrans = ap_make_sub_pool(tpool); - -while (!workers_may_exit) { -workers_may_exit |= (max_requests_per_child != 0) (requests_this_child = 0); -if (workers_may_exit) break; -if (!thread_just_started) { -pthread_mutex_lock(idle_thread_count_mutex); -if (idle_thread_count max_spare_threads) { -idle_thread_count++; -pthread_mutex_unlock(idle_thread_count_mutex); -} -else { -pthread_mutex_unlock(idle_thread_count_mutex); -break; -} -} -else { -thread_just_started = 0; -} -SAFE_ACCEPT(intra_mutex_on(0)); -while (!workers_may_exit) { -if (poll_count 0) { -/* Just check the pipe_of_death */ -srv = poll(listenfds, 1, 0); -} else { -srv = poll_count = poll(listenfds, num_listenfds + 1, -1); -curr_pollfd = 0; -} -if (srv 0) { -if (errno == EINTR) { -continue; -} - -/* poll() will only return errors in catastrophic - * circumstances. Let's try exiting gracefully, for now. */ -ap_log_error(APLOG_MARK, APLOG_ERR, (const server_rec *) - ap_get_server_conf(), poll: (listen)); -workers_may_exit = 1; -} -if (workers_may_exit) break; - -if (listenfds[0].revents POLLIN) { -/* A process got a signal on the shutdown pipe. Check if - * we're the lucky process to die. */ -check_pipe_of_death(); -continue; -} - -if (num_listenfds == 1) { -sd = ap_listeners-fd; -poll_count = 0; -goto got_fd; -} -else { -/* find a listener. */ -for(;;) { -curr_pollfd++; -/* XXX: Should we check for POLLERR? */ -if (listenfds[curr_pollfd].revents POLLIN) { -poll_count--; -sd = listenfds[curr_pollfd].fd; -goto got_fd; -} -} -} -} -got_fd: -if
cvs commit: apache-2.0/mpm/src/modules/mpm/dexter dexter.c
manoj 99/08/11 19:02:28 Modified:mpm/src/modules/mpm/dexter dexter.c Log: A little experiment. Add a special worker thread function for the case when only one child process is running. It eliminates cross-process serialization and can reuse the data from a poll call. Revision ChangesPath 1.21 +131 -3apache-2.0/mpm/src/modules/mpm/dexter/dexter.c Index: dexter.c === RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/dexter/dexter.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -u -r1.20 -r1.21 --- dexter.c 1999/08/11 23:55:38 1.20 +++ dexter.c 1999/08/12 02:02:27 1.21 @@ -892,16 +892,24 @@ } static void *worker_thread(void *); +static void *worker_thread_one_child(void *); /* Starts a thread as long as we're below max_threads */ static int start_thread(worker_thread_info *thread_info) { pthread_t thread; +void *(*thread_function)(void *); pthread_mutex_lock(worker_thread_count_mutex); if (worker_thread_count max_threads) { +if (num_daemons == 1) { +thread_function = worker_thread_one_child; +} +else { +thread_function = worker_thread; +} worker_thread_count++; -if (pthread_create(thread, (thread_info-attr), worker_thread, thread_info)) { +if (pthread_create(thread, (thread_info-attr), thread_function, thread_info)) { ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, pthread_create: unable to create worker thread); /* In case system resources are maxxed out, we don't want @@ -954,6 +962,128 @@ /* idle_thread_count should be incremented before starting a worker_thread */ +static void *worker_thread_one_child(void *arg) +{ +struct sockaddr sa_client; +int csd = -1; +pool *tpool;/* Pool for this thread */ +pool *ptrans;/* Pool for per-transaction stuff */ +int sd = -1; +int srv; +int poll_count = 0; +static int curr_pollfd = 0; +size_t len = sizeof(struct sockaddr); +worker_thread_info *thread_info = arg; +int thread_just_started = 1; + +pthread_mutex_lock(thread_info-mutex); +tpool = ap_make_sub_pool(thread_info-pool); +pthread_mutex_unlock(thread_info-mutex); +ptrans = ap_make_sub_pool(tpool); + +while (!workers_may_exit) { +workers_may_exit |= (max_requests_per_child != 0) (requests_this_child = 0); +if (workers_may_exit) break; +if (!thread_just_started) { +pthread_mutex_lock(idle_thread_count_mutex); +if (idle_thread_count max_spare_threads) { +idle_thread_count++; +pthread_mutex_unlock(idle_thread_count_mutex); +} +else { +pthread_mutex_unlock(idle_thread_count_mutex); +break; +} +} +else { +thread_just_started = 0; +} +SAFE_ACCEPT(intra_mutex_on(0)); +while (!workers_may_exit) { +if (poll_count 0) { +/* Just check the pipe_of_death */ +srv = poll(listenfds, 1, 0); +} else { +srv = poll_count = poll(listenfds, num_listenfds + 1, -1); +curr_pollfd = 0; +} +if (srv 0) { +if (errno == EINTR) { +continue; +} + +/* poll() will only return errors in catastrophic + * circumstances. Let's try exiting gracefully, for now. */ +ap_log_error(APLOG_MARK, APLOG_ERR, (const server_rec *) + ap_get_server_conf(), poll: (listen)); +workers_may_exit = 1; +} +if (workers_may_exit) break; + +if (listenfds[0].revents POLLIN) { +/* A process got a signal on the shutdown pipe. Check if + * we're the lucky process to die. */ +check_pipe_of_death(); +continue; +} + +if (num_listenfds == 1) { +sd = ap_listeners-fd; +poll_count = 0; +goto got_fd; +} +else { +/* find a listener. */ +for(;;) { +curr_pollfd++; +/* XXX: Should we check for POLLERR? */ +if (listenfds[curr_pollfd].revents POLLIN) { +poll_count--; +sd = listenfds[curr_pollfd].fd; +goto got_fd; +} +
cvs commit: apache-2.0/mpm/src/modules/mpm/dexter dexter.c
manoj 99/08/03 16:43:08 Modified:mpm/src/modules/mpm/dexter dexter.c Log: Eliminate a spurious runtime warning. Revision ChangesPath 1.16 +1 -1 apache-2.0/mpm/src/modules/mpm/dexter/dexter.c Index: dexter.c === RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/dexter/dexter.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -u -r1.15 -r1.16 --- dexter.c 1999/08/03 23:36:41 1.15 +++ dexter.c 1999/08/03 23:43:02 1.16 @@ -1598,7 +1598,7 @@ } max_threads = atoi(arg); -if (max_threads = HARD_THREAD_LIMIT) { +if (max_threads HARD_THREAD_LIMIT) { fprintf(stderr, WARNING: detected MaxThreadsPerChild set higher than\n); fprintf(stderr, HARD_THREAD_LIMIT. Resetting to %d\n, HARD_THREAD_LIMIT); max_threads = HARD_THREAD_LIMIT;
cvs commit: apache-2.0/mpm/src/modules/mpm/dexter dexter.c
manoj 99/07/25 20:28:16 Modified:mpm/src/modules/mpm/mpmt_pthread mpmt_pthread.c mpm/src/modules/mpm/dexter dexter.c Log: Update for newest hooks Revision ChangesPath 1.12 +0 -2 apache-2.0/mpm/src/modules/mpm/mpmt_pthread/mpmt_pthread.c Index: mpmt_pthread.c === RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/mpmt_pthread/mpmt_pthread.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -u -r1.11 -r1.12 --- mpmt_pthread.c1999/07/21 22:32:36 1.11 +++ mpmt_pthread.c1999/07/26 03:28:14 1.12 @@ -1777,8 +1777,6 @@ NULL,/* handlers */ NULL,/* check auth */ NULL,/* check access */ -NULL,/* type_checker */ -NULL,/* pre-run fixups */ NULL /* register hooks */ }; 1.8 +0 -2 apache-2.0/mpm/src/modules/mpm/dexter/dexter.c Index: dexter.c === RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/dexter/dexter.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -u -r1.7 -r1.8 --- dexter.c 1999/07/23 23:35:20 1.7 +++ dexter.c 1999/07/26 03:28:15 1.8 @@ -1704,8 +1704,6 @@ NULL,/* handlers */ NULL,/* check auth */ NULL,/* check access */ -NULL,/* type_checker */ -NULL,/* pre-run fixups */ NULL /* register hooks */ };
cvs commit: apache-2.0/mpm/src/modules/mpm/dexter dexter.c
manoj 99/07/23 16:35:23 Modified:mpm/src/modules/mpm/dexter dexter.c Log: Add a MaxThreadsPerChild directive Revision ChangesPath 1.7 +62 -15apache-2.0/mpm/src/modules/mpm/dexter/dexter.c Index: dexter.c === RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/dexter/dexter.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -u -r1.6 -r1.7 --- dexter.c 1999/07/23 22:43:47 1.6 +++ dexter.c 1999/07/23 23:35:20 1.7 @@ -81,6 +81,7 @@ static int threads_to_start = 0; /* Worker threads per child */ static int min_spare_threads = 0; static int max_spare_threads = 0; +static int max_threads = 0; static int max_requests_per_child = 0; static char *ap_pid_fname=NULL; static int num_daemons=0; @@ -842,19 +843,42 @@ static void *worker_thread(void *); -static void start_thread(worker_thread_info *thread_info) +/* Starts a thread as long as we're below max_threads */ +static int start_thread(worker_thread_info *thread_info) { pthread_t thread; -if (pthread_create(thread, (thread_info-attr), worker_thread, thread_info)) { -ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, - pthread_create: unable to create worker thread); -/* In case system resources are maxxed out, we don't want - Apache running away with the CPU trying to fork over and - over and over again if we exit. */ -sleep(10); -workers_may_exit = 1; +pthread_mutex_lock(worker_thread_count_mutex); +if (worker_thread_count max_threads) { +worker_thread_count++; +if (pthread_create(thread, (thread_info-attr), worker_thread, thread_info)) { +ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, + pthread_create: unable to create worker thread); +/* In case system resources are maxxed out, we don't want + Apache running away with the CPU trying to fork over and + over and over again if we exit. */ +sleep(10); +worker_thread_count--; +workers_may_exit = 1; +pthread_mutex_unlock(worker_thread_count_mutex); +return 0; +} +} +else { +static int reported = 0; + +if (!reported) { +ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, server_conf, + server reached MaxThreadsPerChild setting, consider raising the + MaxThreadsPerChild or NumServers settings); +reported = 1; +} +pthread_mutex_unlock(worker_thread_count_mutex); +return 0; } +pthread_mutex_unlock(worker_thread_count_mutex); +return 1; + } /* idle_thread_count should be incremented before starting a worker_thread */ @@ -879,10 +903,6 @@ pthread_mutex_unlock(thread_info-mutex); ptrans = ap_make_sub_pool(tpool); -pthread_mutex_lock(worker_thread_count_mutex); -worker_thread_count++; -pthread_mutex_unlock(worker_thread_count_mutex); - /* TODO: Switch to a system where threads reuse the results from earlier poll calls - manoj */ while (!workers_may_exit) { @@ -978,7 +998,9 @@ idle_thread_count--; } else { -start_thread(thread_info); +if (!start_thread(thread_info)) { +idle_thread_count--; +} } pthread_mutex_unlock(idle_thread_count_mutex); } else { @@ -1053,6 +1075,9 @@ /* Setup worker threads */ +if (threads_to_start max_threads) { +threads_to_start = max_threads; +} idle_thread_count = threads_to_start; worker_thread_count = 0; thread_info.pool = ap_make_sub_pool(pconf); @@ -1065,7 +1090,10 @@ /* We are creating worker threads right now */ for (i=0; i threads_to_start; i++) { -start_thread(thread_info); +/* start_thread shouldn't fail here */ +if (!start_thread(thread_info)) { +break; +} } /* This thread will be the one responsible for handling signals */ @@ -1444,6 +1472,7 @@ threads_to_start = DEFAULT_START_THREAD; min_spare_threads = DEFAULT_MIN_SPARE_THREAD; max_spare_threads = DEFAULT_MAX_SPARE_THREAD; +max_threads = HARD_THREAD_LIMIT; ap_pid_fname = DEFAULT_PIDLOG; ap_lock_fname = DEFAULT_LOCKFILE; max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD; @@ -1556,6 +1585,22 @@ return NULL; } +static const char *set_max_threads(cmd_parms *cmd, void *dummy, char *arg) +{ +const char *err =
cvs commit: apache-2.0/mpm/src/modules/mpm/dexter dexter.c dexter.h
manoj 99/07/23 15:15:18 Modified:mpm/src/modules/mpm/dexter dexter.c dexter.h Log: Add support for dynamically creating and destroying threads based on a Min/MaxSpareThreads algorithm, and clean up a couple of stray pieces of gunk from the days of scoreboardhood. Revision ChangesPath 1.4 +138 -65 apache-2.0/mpm/src/modules/mpm/dexter/dexter.c Index: dexter.c === RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/dexter/dexter.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -u -r1.3 -r1.4 --- dexter.c 1999/07/21 22:18:30 1.3 +++ dexter.c 1999/07/23 22:15:10 1.4 @@ -78,12 +78,12 @@ * Actual definitions of config globals */ -int ap_threads_per_child=0; /* Worker threads per child */ -int ap_max_requests_per_child=0; +static int threads_to_start=0; /* Worker threads per child */ +static int min_spare_threads=0; +static int max_spare_threads=HARD_THREAD_LIMIT; +static int max_requests_per_child=0; static char *ap_pid_fname=NULL; -static int ap_num_daemons=0; -static time_t ap_restart_time=0; -API_VAR_EXPORT int ap_extended_status = 0; +static int num_daemons=0; static int workers_may_exit = 0; static int requests_this_child; static int num_listenfds = 0; @@ -145,12 +145,22 @@ static pool *pconf; /* Pool for config stuff */ static pool *pchild; /* Pool for httpd child stuff */ +typedef struct { +pool *pool; +pthread_mutex_t mutex; +pthread_attr_t attr; +} worker_thread_info; + static int my_pid; /* Linux getpid() doesn't work except in main thread. Use this instead */ /* Keep track of the number of worker threads currently active */ static int worker_thread_count; static pthread_mutex_t worker_thread_count_mutex; +/* Keep track of the number of idle worker threads */ +static int idle_thread_count; +static pthread_mutex_t idle_thread_count_mutex; + /* Global, alas, so http_core can talk to us */ enum server_token_type ap_server_tokens = SrvTk_FULL; @@ -830,11 +840,30 @@ ap_process_connection(current_conn); } -static void * worker_thread(void *thread_pool) +static void *worker_thread(void *); + +static void start_thread(worker_thread_info *thread_info) { -pool *tpool = thread_pool; +pthread_t thread; + +if (pthread_create(thread, (thread_info-attr), worker_thread, thread_info)) { +ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, + pthread_create: unable to create worker thread); +/* In case system resources are maxxed out, we don't want + Apache running away with the CPU trying to fork over and + over and over again if we exit. */ +sleep(10); +workers_may_exit = 1; +} +} + +/* idle_thread_count should be incremented before starting a worker_thread */ + +static void *worker_thread(void *arg) +{ struct sockaddr sa_client; int csd = -1; +pool *tpool; /* Pool for this thread */ pool *ptrans;/* Pool for per-transaction stuff */ int sd = -1; int srv; @@ -842,7 +871,12 @@ char pipe_read_char; int curr_pollfd, last_pollfd = 0; size_t len = sizeof(struct sockaddr); +worker_thread_info *thread_info = arg; +int thread_just_started = 1; +pthread_mutex_lock(thread_info-mutex); +tpool = ap_make_sub_pool(thread_info-pool); +pthread_mutex_unlock(thread_info-mutex); ptrans = ap_make_sub_pool(tpool); pthread_mutex_lock(worker_thread_count_mutex); @@ -852,9 +886,22 @@ /* TODO: Switch to a system where threads reuse the results from earlier poll calls - manoj */ while (!workers_may_exit) { -workers_may_exit |= (ap_max_requests_per_child != 0) (requests_this_child = 0); +workers_may_exit |= (max_requests_per_child != 0) (requests_this_child = 0); if (workers_may_exit) break; - +if (!thread_just_started) { +pthread_mutex_lock(idle_thread_count_mutex); +if (idle_thread_count max_spare_threads) { +idle_thread_count++; +pthread_mutex_unlock(idle_thread_count_mutex); +} +else { +pthread_mutex_unlock(idle_thread_count_mutex); +break; +} +} +else { +thread_just_started = 0; +} SAFE_ACCEPT(intra_mutex_on(0)); if (workers_may_exit) { SAFE_ACCEPT(intra_mutex_off(0)); @@ -863,6 +910,7 @@ SAFE_ACCEPT(accept_mutex_on(0)); while (!workers_may_exit) { srv = poll(listenfds, num_listenfds + 1, -1); +
cvs commit: apache-2.0/mpm/src/modules/mpm/dexter dexter.c
manoj 99/07/23 15:20:22 Modified:mpm/src/modules/mpm/dexter dexter.c Log: Add a little naming consistency, and put in an error condition for MaxSpareThreads being too high. Revision ChangesPath 1.5 +10 -5 apache-2.0/mpm/src/modules/mpm/dexter/dexter.c Index: dexter.c === RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/dexter/dexter.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -u -r1.4 -r1.5 --- dexter.c 1999/07/23 22:15:10 1.4 +++ dexter.c 1999/07/23 22:20:20 1.5 @@ -79,7 +79,7 @@ */ static int threads_to_start=0; /* Worker threads per child */ -static int min_spare_threads=0; +static int min_spare_threads=1; static int max_spare_threads=HARD_THREAD_LIMIT; static int max_requests_per_child=0; static char *ap_pid_fname=NULL; @@ -1520,7 +1520,7 @@ return NULL; } -static const char *set_min_free_threads(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_min_spare_threads(cmd_parms *cmd, void *dummy, char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err != NULL) { @@ -1538,7 +1538,7 @@ return NULL; } -static const char *set_max_free_threads(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_max_spare_threads(cmd_parms *cmd, void *dummy, char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err != NULL) { @@ -1546,6 +1546,11 @@ } max_spare_threads = atoi(arg); +if (max_spare_threads = HARD_THREAD_LIMIT) { + fprintf(stderr, WARNING: detected MinSpareThreads set higher than\n); + fprintf(stderr, HARD_THREAD_LIMIT. Resetting to %d\n, HARD_THREAD_LIMIT); + max_spare_threads = HARD_THREAD_LIMIT; +} return NULL; } @@ -1624,9 +1629,9 @@ Number of children alive at the same time }, { StartThreads, set_threads_to_start, NULL, RSRC_CONF, TAKE1, Number of threads each child creates }, -{ MinSpareThreads, set_min_free_threads, NULL, RSRC_CONF, TAKE1, +{ MinSpareThreads, set_min_spare_threads, NULL, RSRC_CONF, TAKE1, Minimum number of idle threads per child, to handle request spikes }, -{ MaxSpareThreads, set_max_free_threads, NULL, RSRC_CONF, TAKE1, +{ MaxSpareThreads, set_max_spare_threads, NULL, RSRC_CONF, TAKE1, Maximum number of idle threads per child }, { MaxRequestsPerChild, set_max_requests, NULL, RSRC_CONF, TAKE1, Maximum number of requests a particular child serves before dying. },
cvs commit: apache-2.0/mpm/src/modules/mpm/dexter dexter.c mpm_default.h
manoj 99/07/23 15:43:48 Modified:mpm/src/modules/mpm/dexter dexter.c mpm_default.h Log: Clean up and properly specify defaults for the new directives. Revision ChangesPath 1.6 +8 -6 apache-2.0/mpm/src/modules/mpm/dexter/dexter.c Index: dexter.c === RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/dexter/dexter.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -u -r1.5 -r1.6 --- dexter.c 1999/07/23 22:20:20 1.5 +++ dexter.c 1999/07/23 22:43:47 1.6 @@ -78,10 +78,10 @@ * Actual definitions of config globals */ -static int threads_to_start=0; /* Worker threads per child */ -static int min_spare_threads=1; -static int max_spare_threads=HARD_THREAD_LIMIT; -static int max_requests_per_child=0; +static int threads_to_start = 0; /* Worker threads per child */ +static int min_spare_threads = 0; +static int max_spare_threads = 0; +static int max_requests_per_child = 0; static char *ap_pid_fname=NULL; static int num_daemons=0; static int workers_may_exit = 0; @@ -1440,8 +1440,10 @@ unixd_pre_config(); ap_listen_pre_config(); -num_daemons = HARD_SERVER_LIMIT; -threads_to_start = DEFAULT_THREADS_PER_CHILD; +num_daemons = DEFAULT_NUM_DAEMON; +threads_to_start = DEFAULT_START_THREAD; +min_spare_threads = DEFAULT_MIN_SPARE_THREAD; +max_spare_threads = DEFAULT_MAX_SPARE_THREAD; ap_pid_fname = DEFAULT_PIDLOG; ap_lock_fname = DEFAULT_LOCKFILE; max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD; 1.2 +25 -23apache-2.0/mpm/src/modules/mpm/dexter/mpm_default.h Index: mpm_default.h === RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/dexter/mpm_default.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -u -r1.1 -r1.2 --- mpm_default.h 1999/07/21 19:07:06 1.1 +++ mpm_default.h 1999/07/23 22:43:47 1.2 @@ -58,25 +58,42 @@ #ifndef APACHE_MPM_DEFAULT_H #define APACHE_MPM_DEFAULT_H -/* Number of servers to spawn off by default --- also, if fewer than +/* Number of threads to spawn off by default --- also, if fewer than * this free when the caretaker checks, it will spawn more. */ -#ifndef DEFAULT_START_DAEMON -#define DEFAULT_START_DAEMON 5 +#ifndef DEFAULT_START_THREAD +#define DEFAULT_START_THREAD 5 #endif -/* Maximum number of *free* server processes --- more than this, and +/* Maximum number of *free* server threads --- more than this, and * they will die off. */ -#ifndef DEFAULT_MAX_FREE_DAEMON -#define DEFAULT_MAX_FREE_DAEMON 10 +#ifndef DEFAULT_MAX_SPARE_THREAD +#define DEFAULT_MAX_SPARE_THREAD 10 #endif /* Minimum --- fewer than this, and more will be created */ -#ifndef DEFAULT_MIN_FREE_DAEMON -#define DEFAULT_MIN_FREE_DAEMON 5 +#ifndef DEFAULT_MIN_SPARE_THREAD +#define DEFAULT_MIN_SPARE_THREAD 5 +#endif + +/* Limit on the threads per process. Clients will be locked out if more than + * this * HARD_SERVER_LIMIT are needed. + * + * We keep this for one reason it keeps the size of the scoreboard file small + * enough that we can read the whole thing without worrying too much about + * the overhead. + */ +#ifndef HARD_THREAD_LIMIT +#define HARD_THREAD_LIMIT 64 +#endif + +/* Number of servers to spawn off by default + */ +#ifndef DEFAULT_NUM_DAEMON +#define DEFAULT_NUM_DAEMON 2 #endif /* Limit on the total --- clients will be locked out if more servers than @@ -92,21 +109,6 @@ */ #ifndef HARD_SERVER_LIMIT #define HARD_SERVER_LIMIT 8 -#endif - -/* Limit on the threads per process. Clients will be locked out if more than - * this * HARD_SERVER_LIMIT are needed. - * - * We keep this for one reason it keeps the size of the scoreboard file small - * enough that we can read the whole thing without worrying too much about - * the overhead. - */ -#ifndef HARD_THREAD_LIMIT -#define HARD_THREAD_LIMIT 64 -#endif - -#ifndef DEFAULT_THREADS_PER_CHILD -#define DEFAULT_THREADS_PER_CHILD 50 #endif #endif /* AP_MPM_DEFAULT_H */
cvs commit: apache-2.0/mpm/src/modules/mpm/dexter dexter.c
manoj 99/07/21 15:18:32 Modified:mpm/src/modules/mpm/dexter dexter.c Log: Cleanups and fixes. Get rid of more stuff having to do with scoreboard slots in the children. Also squashes a couple of bugs. Revision ChangesPath 1.3 +22 -40apache-2.0/mpm/src/modules/mpm/dexter/dexter.c Index: dexter.c === RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/dexter/dexter.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -u -r1.2 -r1.3 --- dexter.c 1999/07/21 20:44:41 1.2 +++ dexter.c 1999/07/21 22:18:30 1.3 @@ -89,14 +89,6 @@ static int num_listenfds = 0; static struct pollfd *listenfds; -/* The structure used to pass unique initialization info to each thread */ -typedef struct { -int pid; -int tid; -int sd; -pool *tpool; /* pthread would be confusing */ -} proc_info; - #if 0 #define SAFE_ACCEPT(stmt) do {if (ap_listeners-next != NULL) {stmt;}} while (0) #else @@ -795,7 +787,7 @@ * Child process main loop. */ -static void process_socket(pool *p, struct sockaddr *sa_client, int csd, int my_child_num, int my_thread_num) +static void process_socket(pool *p, struct sockaddr *sa_client, int csd) { struct sockaddr sa_server; /* */ size_t len = sizeof(struct sockaddr); @@ -833,17 +825,14 @@ current_conn = ap_new_connection(p, server_conf, conn_io, (const struct sockaddr_in *) sa_client, (const struct sockaddr_in *) sa_server, - my_child_num, my_thread_num); + 0, 0); ap_process_connection(current_conn); } -static void * worker_thread(void * dummy) +static void * worker_thread(void *thread_pool) { -proc_info * ti = dummy; -int process_slot = ti-pid; -int thread_slot = ti-tid; -pool *tpool = ti-tpool; +pool *tpool = thread_pool; struct sockaddr sa_client; int csd = -1; pool *ptrans;/* Pool for per-transaction stuff */ @@ -854,8 +843,6 @@ int curr_pollfd, last_pollfd = 0; size_t len = sizeof(struct sockaddr); -free(ti); - ptrans = ap_make_sub_pool(tpool); pthread_mutex_lock(worker_thread_count_mutex); @@ -935,11 +922,17 @@ } } got_fd: -SAFE_ACCEPT(accept_mutex_off(0)); -SAFE_ACCEPT(intra_mutex_off(0)); -if (workers_may_exit) break; -csd = ap_accept(sd, sa_client, len); -process_socket(ptrans, sa_client, csd, process_slot, thread_slot); +if (!workers_may_exit) { +csd = ap_accept(sd, sa_client, len); +SAFE_ACCEPT(accept_mutex_off(0)); +SAFE_ACCEPT(intra_mutex_off(0)); + } else { +SAFE_ACCEPT(accept_mutex_off(0)); +SAFE_ACCEPT(intra_mutex_off(0)); + break; + } + +process_socket(ptrans, sa_client, csd); ap_clear_pool(ptrans); requests_this_child--; } @@ -957,15 +950,14 @@ return NULL; } -static void child_main(int child_num_arg) +static void child_main(void) { sigset_t sig_mask; int signal_received; pthread_t thread; pthread_attr_t thread_attr; int i; -int my_child_num = child_num_arg; -proc_info *my_info = NULL; +pool *tpool; ap_listen_rec *lr; my_pid = getpid(); @@ -1012,20 +1004,10 @@ pthread_attr_init(thread_attr); pthread_attr_setdetachstate(thread_attr, PTHREAD_CREATE_DETACHED); for (i=0; i ap_threads_per_child; i++) { - - my_info = (proc_info *)malloc(sizeof(proc_info)); -if (my_info == NULL) { -ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, - malloc: out of memory); -clean_child_exit(APEXIT_CHILDFATAL); -} - my_info-pid = my_child_num; -my_info-tid = i; - my_info-sd = 0; - my_info-tpool = ap_make_sub_pool(pchild); + tpool = ap_make_sub_pool(pchild); /* We are creating threads right now */ - if (pthread_create(thread, thread_attr, worker_thread, my_info)) { + if (pthread_create(thread, thread_attr, worker_thread, tpool)) { ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, pthread_create: unable to create worker thread); /* In case system resources are maxxed out, we don't want @@ -1072,7 +1054,7 @@ if (one_process) { set_signals(); ap_scoreboard_image[slot].pid = getpid(); - child_main(slot); + child_main(); } if ((pid = fork()) == -1) { @@ -1103,7 +1085,7 @@ /* XXX - For an unthreaded server, a