summaryrefslogtreecommitdiff
path: root/server/mpm
diff options
context:
space:
mode:
Diffstat (limited to 'server/mpm')
-rw-r--r--server/mpm/event/event.c37
-rw-r--r--server/mpm/winnt/child.c11
-rw-r--r--server/mpm/worker/worker.c39
3 files changed, 51 insertions, 36 deletions
diff --git a/server/mpm/event/event.c b/server/mpm/event/event.c
index 2418471f..baeb5a76 100644
--- a/server/mpm/event/event.c
+++ b/server/mpm/event/event.c
@@ -1114,7 +1114,7 @@ read_request:
if (cs->pub.state == CONN_STATE_WRITE_COMPLETION) {
ap_filter_t *output_filter = c->output_filters;
apr_status_t rv;
- ap_update_child_status_from_conn(sbh, SERVER_BUSY_WRITE, c);
+ ap_update_child_status(sbh, SERVER_BUSY_WRITE, NULL);
while (output_filter->next != NULL) {
output_filter = output_filter->next;
}
@@ -1910,7 +1910,8 @@ static void *APR_THREAD_FUNC worker_thread(apr_thread_t * thd, void *dummy)
}
ap_update_child_status_from_indexes(process_slot, thread_slot,
- dying ? SERVER_GRACEFUL : SERVER_READY, NULL);
+ dying ? SERVER_GRACEFUL
+ : SERVER_READY, NULL);
worker_pop:
if (workers_may_exit) {
break;
@@ -1965,9 +1966,8 @@ static void *APR_THREAD_FUNC worker_thread(apr_thread_t * thd, void *dummy)
}
ap_update_child_status_from_indexes(process_slot, thread_slot,
- dying ? SERVER_DEAD :
- SERVER_GRACEFUL,
- (request_rec *) NULL);
+ dying ? SERVER_DEAD
+ : SERVER_GRACEFUL, NULL);
apr_thread_exit(thd, APR_SUCCESS);
return NULL;
@@ -2017,8 +2017,7 @@ static void *APR_THREAD_FUNC start_threads(apr_thread_t * thd, void *dummy)
thread_starter *ts = dummy;
apr_thread_t **threads = ts->threads;
apr_threadattr_t *thread_attr = ts->threadattr;
- int child_num_arg = ts->child_num_arg;
- int my_child_num = child_num_arg;
+ int my_child_num = ts->child_num_arg;
proc_info *my_info;
apr_status_t rv;
int i;
@@ -2102,7 +2101,7 @@ static void *APR_THREAD_FUNC start_threads(apr_thread_t * thd, void *dummy)
/* threads_per_child does not include the listener thread */
for (i = 0; i < threads_per_child; i++) {
int status =
- ap_scoreboard_image->servers[child_num_arg][i].status;
+ ap_scoreboard_image->servers[my_child_num][i].status;
if (status != SERVER_GRACEFUL && status != SERVER_DEAD) {
continue;
@@ -2524,13 +2523,14 @@ static void perform_idle_server_maintenance(int child_bucket, int num_buckets)
int all_dead_threads = 1;
int child_threads_active = 0;
- if (i >= retained->max_daemons_limit
- && totally_free_length == retained->idle_spawn_rate[child_bucket])
+ if (i >= retained->max_daemons_limit &&
+ totally_free_length == retained->idle_spawn_rate[child_bucket]) {
/* short cut if all active processes have been examined and
* enough empty scoreboard slots have been found
*/
break;
+ }
ps = &ap_scoreboard_image->parent[i];
for (j = 0; j < threads_per_child; j++) {
ws = &ap_scoreboard_image->servers[i][j];
@@ -2728,8 +2728,7 @@ static void server_main_loop(int remaining_children_to_start, int num_buckets)
for (i = 0; i < threads_per_child; i++)
ap_update_child_status_from_indexes(child_slot, i,
- SERVER_DEAD,
- (request_rec *) NULL);
+ SERVER_DEAD, NULL);
event_note_child_killed(child_slot, 0, 0);
ps = &ap_scoreboard_image->parent[child_slot];
@@ -2830,10 +2829,16 @@ static int event_run(apr_pool_t * _pconf, apr_pool_t * plog, server_rec * s)
ap_daemons_limit = num_buckets;
if (ap_daemons_to_start < num_buckets)
ap_daemons_to_start = num_buckets;
- if (min_spare_threads < threads_per_child * num_buckets)
- min_spare_threads = threads_per_child * num_buckets;
- if (max_spare_threads < min_spare_threads + threads_per_child * num_buckets)
- max_spare_threads = min_spare_threads + threads_per_child * num_buckets;
+ /* We want to create as much children at a time as the number of buckets,
+ * so to optimally accept connections (evenly distributed accross buckets).
+ * Thus min_spare_threads should at least maintain num_buckets children,
+ * and max_spare_threads allow num_buckets more children w/o triggering
+ * immediately (e.g. num_buckets idle threads margin, one per bucket).
+ */
+ if (min_spare_threads < threads_per_child * (num_buckets - 1) + num_buckets)
+ min_spare_threads = threads_per_child * (num_buckets - 1) + num_buckets;
+ if (max_spare_threads < min_spare_threads + (threads_per_child + 1) * num_buckets)
+ max_spare_threads = min_spare_threads + (threads_per_child + 1) * num_buckets;
/* If we're doing a graceful_restart then we're going to see a lot
* of children exiting immediately when we get into the main loop
diff --git a/server/mpm/winnt/child.c b/server/mpm/winnt/child.c
index e4d1c150..dee35df5 100644
--- a/server/mpm/winnt/child.c
+++ b/server/mpm/winnt/child.c
@@ -894,8 +894,7 @@ static DWORD __stdcall worker_main(void *thread_num_val)
}
}
- ap_update_child_status_from_indexes(0, thread_num, SERVER_DEAD,
- (request_rec *) NULL);
+ ap_update_child_status_from_indexes(0, thread_num, SERVER_DEAD, NULL);
return 0;
}
@@ -1314,13 +1313,13 @@ void child_main(apr_pool_t *pconf, DWORD parent_pid)
threads_created);
}
for (i = 0; i < threads_created; i++) {
- int *score_idx;
+ int *idx;
TerminateThread(child_handles[i], 1);
CloseHandle(child_handles[i]);
/* Reset the scoreboard entry for the thread we just whacked */
- score_idx = apr_hash_get(ht, &child_handles[i], sizeof(HANDLE));
- if (score_idx) {
- ap_update_child_status_from_indexes(0, *score_idx, SERVER_DEAD, NULL);
+ idx = apr_hash_get(ht, &child_handles[i], sizeof(HANDLE));
+ if (idx) {
+ ap_update_child_status_from_indexes(0, *idx, SERVER_DEAD, NULL);
}
}
ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf, APLOGNO(00364)
diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c
index 24aa46bd..d0ed6040 100644
--- a/server/mpm/worker/worker.c
+++ b/server/mpm/worker/worker.c
@@ -928,7 +928,8 @@ static void * APR_THREAD_FUNC worker_thread(apr_thread_t *thd, void * dummy)
ap_scoreboard_image->servers[process_slot][thread_slot].pid = ap_my_pid;
ap_scoreboard_image->servers[process_slot][thread_slot].tid = apr_os_thread_current();
ap_scoreboard_image->servers[process_slot][thread_slot].generation = retained->my_generation;
- ap_update_child_status_from_indexes(process_slot, thread_slot, SERVER_STARTING, NULL);
+ ap_update_child_status_from_indexes(process_slot, thread_slot,
+ SERVER_STARTING, NULL);
#ifdef HAVE_PTHREAD_KILL
unblock_signal(WORKER_SIGNAL);
@@ -949,7 +950,8 @@ static void * APR_THREAD_FUNC worker_thread(apr_thread_t *thd, void * dummy)
is_idle = 1;
}
- ap_update_child_status_from_indexes(process_slot, thread_slot, SERVER_READY, NULL);
+ ap_update_child_status_from_indexes(process_slot, thread_slot,
+ SERVER_READY, NULL);
worker_pop:
if (workers_may_exit) {
break;
@@ -995,7 +997,8 @@ worker_pop:
}
ap_update_child_status_from_indexes(process_slot, thread_slot,
- (dying) ? SERVER_DEAD : SERVER_GRACEFUL, (request_rec *) NULL);
+ dying ? SERVER_DEAD
+ : SERVER_GRACEFUL, NULL);
apr_thread_exit(thd, APR_SUCCESS);
return NULL;
@@ -1043,8 +1046,7 @@ static void * APR_THREAD_FUNC start_threads(apr_thread_t *thd, void *dummy)
thread_starter *ts = dummy;
apr_thread_t **threads = ts->threads;
apr_threadattr_t *thread_attr = ts->threadattr;
- int child_num_arg = ts->child_num_arg;
- int my_child_num = child_num_arg;
+ int my_child_num = ts->child_num_arg;
proc_info *my_info;
apr_status_t rv;
int i;
@@ -1078,7 +1080,7 @@ static void * APR_THREAD_FUNC start_threads(apr_thread_t *thd, void *dummy)
while (1) {
/* threads_per_child does not include the listener thread */
for (i = 0; i < threads_per_child; i++) {
- int status = ap_scoreboard_image->servers[child_num_arg][i].status;
+ int status = ap_scoreboard_image->servers[my_child_num][i].status;
if (status != SERVER_GRACEFUL && status != SERVER_DEAD) {
continue;
@@ -1515,11 +1517,13 @@ static void perform_idle_server_maintenance(int child_bucket, int num_buckets)
int all_dead_threads = 1;
int child_threads_active = 0;
- if (i >= retained->max_daemons_limit && totally_free_length == retained->idle_spawn_rate[child_bucket])
+ if (i >= retained->max_daemons_limit &&
+ totally_free_length == retained->idle_spawn_rate[child_bucket]) {
/* short cut if all active processes have been examined and
* enough empty scoreboard slots have been found
*/
break;
+ }
ps = &ap_scoreboard_image->parent[i];
for (j = 0; j < threads_per_child; j++) {
ws = &ap_scoreboard_image->servers[i][j];
@@ -1553,7 +1557,8 @@ static void perform_idle_server_maintenance(int child_bucket, int num_buckets)
}
}
active_thread_count += child_threads_active;
- if (any_dead_threads && totally_free_length < retained->idle_spawn_rate[child_bucket]
+ if (any_dead_threads
+ && totally_free_length < retained->idle_spawn_rate[child_bucket]
&& free_length < MAX_SPAWN_RATE / num_buckets
&& (!ps->pid /* no process in the slot */
|| ps->quiescing)) { /* or at least one is going away */
@@ -1730,8 +1735,8 @@ static void server_main_loop(int remaining_children_to_start, int num_buckets)
process_score *ps;
for (i = 0; i < threads_per_child; i++)
- ap_update_child_status_from_indexes(child_slot, i, SERVER_DEAD,
- (request_rec *) NULL);
+ ap_update_child_status_from_indexes(child_slot, i,
+ SERVER_DEAD, NULL);
worker_note_child_killed(child_slot, 0, 0);
ps = &ap_scoreboard_image->parent[child_slot];
@@ -1831,10 +1836,16 @@ static int worker_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
ap_daemons_limit = num_buckets;
if (ap_daemons_to_start < num_buckets)
ap_daemons_to_start = num_buckets;
- if (min_spare_threads < threads_per_child * num_buckets)
- min_spare_threads = threads_per_child * num_buckets;
- if (max_spare_threads < min_spare_threads + threads_per_child * num_buckets)
- max_spare_threads = min_spare_threads + threads_per_child * num_buckets;
+ /* We want to create as much children at a time as the number of buckets,
+ * so to optimally accept connections (evenly distributed accross buckets).
+ * Thus min_spare_threads should at least maintain num_buckets children,
+ * and max_spare_threads allow num_buckets more children w/o triggering
+ * immediately (e.g. num_buckets idle threads margin, one per bucket).
+ */
+ if (min_spare_threads < threads_per_child * (num_buckets - 1) + num_buckets)
+ min_spare_threads = threads_per_child * (num_buckets - 1) + num_buckets;
+ if (max_spare_threads < min_spare_threads + (threads_per_child + 1) * num_buckets)
+ max_spare_threads = min_spare_threads + (threads_per_child + 1) * num_buckets;
/* If we're doing a graceful_restart then we're going to see a lot
* of children exiting immediately when we get into the main loop