From: Jeff Trawick Date: Sat, 5 Mar 2005 20:06:55 +0000 (+0000) Subject: worker MPM/mod_status: Support per-worker tracking of pid and X-Git-Tag: 2.1.4~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e14f168679cb62bdd03068f50cc4836e6071283;p=apache worker MPM/mod_status: Support per-worker tracking of pid and generation in the scoreboard so that mod_status can accurately represent workers in processes which are gracefully terminating. New child processes with worker MPM can take over slots of individual threads within gracefully terminating processes. Sometimes this is a problem (too many of these gracefully terminating processes), so it is helpful to have mod_status provide the information required to recognize these processes. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@156274 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index f5b9e32594..02f3fefd90 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,12 @@ Changes with Apache 2.1.4 [Remove entries to the current 2.0 section below, when backported] + *) worker MPM/mod_status: Support per-worker tracking of pid and + generation in the scoreboard so that mod_status can accurately + represent workers in processes which are gracefully terminating. + (major MMN bump) + [Jeff Trawick] + *) Correctly export all mod_dav public functions. [Branko Èibej ] diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 8af907aa79..0c0835c1a0 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -92,6 +92,7 @@ * 20050217.0 (2.1.3-dev) Axed find_child_by_pid, mpm_*_completion_context (winnt mpm) * symbols from the public sector, and decorated real_exit_code * with ap_ in the win32 os.h. + * 20050305.0 (2.1.4-dev) added pid and generation fields to worker_score */ #define MODULE_MAGIC_COOKIE 0x41503230UL /* "AP20" */ diff --git a/include/scoreboard.h b/include/scoreboard.h index 141775581d..726ee1ee19 100644 --- a/include/scoreboard.h +++ b/include/scoreboard.h @@ -99,6 +99,13 @@ struct worker_score { #if APR_HAS_THREADS apr_os_thread_t tid; #endif + /* With some MPMs (e.g., worker), a worker_score can represent + * a thread in a terminating process which is no longer + * represented by the corresponding process_score. These MPMs + * should set pid and generation fields in the worker_score. + */ + pid_t pid; + ap_generation_t generation; unsigned char status; unsigned long access_count; apr_off_t bytes_served; diff --git a/modules/generators/mod_status.c b/modules/generators/mod_status.c index 52171323f6..6f28d024a3 100644 --- a/modules/generators/mod_status.c +++ b/modules/generators/mod_status.c @@ -229,8 +229,9 @@ static int status_handler(request_rec *r) worker_score *ws_record; process_score *ps_record; char *stat_buffer; - pid_t *pid_buffer; + pid_t *pid_buffer, worker_pid; clock_t tu, ts, tcu, tcs; + ap_generation_t worker_generation; if (strcmp(r->handler, STATUS_MAGIC_TYPE) && strcmp(r->handler, "server-status")) { @@ -584,19 +585,27 @@ static int status_handler(request_rec *r) bytes = ws_record->bytes_served; my_bytes = ws_record->my_bytes_served; conn_bytes = ws_record->conn_bytes; - + if (ws_record->pid) { /* MPM sets per-worker pid and generation */ + worker_pid = ws_record->pid; + worker_generation = ws_record->generation; + } + else { + worker_pid = ps_record->pid; + worker_generation = ps_record->generation; + } + if (no_table_report) { if (ws_record->status == SERVER_DEAD) ap_rprintf(r, "Server %d-%d (-): %d|%lu|%lu [", - i, (int)ps_record->generation, + i, (int)worker_generation, (int)conn_lres, my_lres, lres); else ap_rprintf(r, "Server %d-%d (%" APR_PID_T_FMT "): %d|%lu|%lu [", - i, (int) ps_record->generation, - ps_record->pid, + i, (int) worker_generation, + worker_pid, (int)conn_lres, my_lres, lres); switch (ws_record->status) { @@ -672,15 +681,16 @@ static int status_handler(request_rec *r) if (ws_record->status == SERVER_DEAD) ap_rprintf(r, "%d-%d-%d/%lu/%lu", - i, (int)ps_record->generation, + i, (int)worker_generation, (int)conn_lres, my_lres, lres); else ap_rprintf(r, "%d-%d%" APR_PID_T_FMT "%d/%lu/%lu", - i, (int)ps_record->generation, - ps_record->pid, (int)conn_lres, + i, (int)worker_generation, + worker_pid, + (int)conn_lres, my_lres, lres); switch (ws_record->status) { diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index 1f5deb7f55..6058624e17 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -800,6 +800,8 @@ static void * APR_THREAD_FUNC worker_thread(apr_thread_t *thd, void * dummy) free(ti); + ap_scoreboard_image->servers[process_slot][thread_slot].pid = ap_my_pid; + ap_scoreboard_image->servers[process_slot][thread_slot].generation = ap_my_generation; ap_update_child_status_from_indexes(process_slot, thread_slot, SERVER_STARTING, NULL); while (!workers_may_exit) {