scoreboard.c revision 17f77e3bb7dc5bbbcfad34e974d9707cfbfde52f
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein/* ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * The Apache Software License, Version 1.1
bc8fd1b0b1afdf89b8d28eefa8cd74e26ba97986fielding * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * reserved.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Redistribution and use in source and binary forms, with or without
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * modification, are permitted provided that the following conditions
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 1. Redistributions of source code must retain the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 2. Redistributions in binary form must reproduce the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer in
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * the documentation and/or other materials provided with the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * distribution.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 3. The end-user documentation included with the redistribution,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if any, must include the following acknowledgment:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * "This product includes software developed by the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Apache Software Foundation (http://www.apache.org/)."
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Alternately, this acknowledgment may appear in the software itself,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if and wherever such third-party acknowledgments normally appear.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 4. The names "Apache" and "Apache Software Foundation" must
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * not be used to endorse or promote products derived from this
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * software without prior written permission. For written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission, please contact apache@apache.org.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 5. Products derived from this software may not be called "Apache",
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * nor may "Apache" appear in their name, without prior written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission of the Apache Software Foundation.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SUCH DAMAGE.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * This software consists of voluntary contributions made by many
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * individuals on behalf of the Apache Software Foundation. For more
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * information on the Apache Software Foundation, please see
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Portions of this software are based upon public domain software
f4c310fd2555c6faca1f980f00b161eadb089023gstein * originally written at the National Center for Supercomputing Applications,
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker * University of Illinois, Urbana-Champaign.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE_DATA scoreboard *ap_scoreboard_image = NULL;
000397350b42c6266351bd618fa07df929fa7c79gstein * This function should be renamed to cleanup_shared
000397350b42c6266351bd618fa07df929fa7c79gstein * and it should handle cleaning up a scoreboard shared
f4c310fd2555c6faca1f980f00b161eadb089023gstein * between processes using any form of IPC (file, shared memory
f4c310fd2555c6faca1f980f00b161eadb089023gstein * segment, etc.). Leave it as is now because it is being used
f4c310fd2555c6faca1f980f00b161eadb089023gstein * by various MPMs.
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* ToDo: This function should be made to handle setting up
f4c310fd2555c6faca1f980f00b161eadb089023gstein * a scoreboard shared between processes using any IPC technique,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * not just a shared memory segment
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker const char *fname;
f4c310fd2555c6faca1f980f00b161eadb089023gstein fname = ap_server_root_relative(p, ap_scoreboard_fname);
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe rv = apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p);
ef3c32d4a7accb38368c7b9face2ade88d987a8bgstein apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard: (%d)%s",
ef3c32d4a7accb38368c7b9face2ade88d987a8bgstein ap_server_argv0, rv, apr_strerror(rv, errmsg, sizeof errmsg));
ef3c32d4a7accb38368c7b9face2ade88d987a8bgstein ap_scoreboard_image = apr_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE);
5a9667916c79d8c699b069068e5570aa1c331c80gstein apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm/* ap_cleanup_scoreboard
b47464a901075041e800be2de098a603923fa4f9gstein if (ap_scoreboard_image->global.sb_type == SB_SHARED) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* ap_create_scoreboard(apr_pool_t*, ap_scoreboard_e t)
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker * Create or reinit an existing scoreboard. The MPM can control whether
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the scoreboard is shared across multiple processes or not
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ###: Is there any reason to export this symbol in the first place?
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE_NONSTD(void) ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
f4c310fd2555c6faca1f980f00b161eadb089023gstein running_gen = ap_scoreboard_image->global.running_generation;
de18a9e85398b9c79c422f578633ed56c2747bbbgstein /* A simple malloc will suffice */
de18a9e85398b9c79c422f578633ed56c2747bbbgstein ap_scoreboard_image = (scoreboard *) malloc(SCOREBOARD_SIZE);
de18a9e85398b9c79c422f578633ed56c2747bbbgstein apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->global.running_generation = running_gen;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Routines called to deal with the scoreboard image
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker * --- note that we do *not* need write locks, since update_child_status
f4c310fd2555c6faca1f980f00b161eadb089023gstein * only updates a *single* record in place, and only one process writes to
f4c310fd2555c6faca1f980f00b161eadb089023gstein * a given scoreboard slot at a time (either the child process owning that
f4c310fd2555c6faca1f980f00b161eadb089023gstein * slot, or the parent, noting that the child has died).
de18a9e85398b9c79c422f578633ed56c2747bbbgstein * As a final note --- setting the score entry to getpid() is always safe,
de18a9e85398b9c79c422f578633ed56c2747bbbgstein * since when the parent is writing an entry, it's only noting SERVER_DEAD
000397350b42c6266351bd618fa07df929fa7c79gsteinstatic APR_INLINE void put_scoreboard_info(int child_num, int thread_num,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX - needs to be fixed to account for threads */
f4c310fd2555c6faca1f980f00b161eadb089023gstein lseek(scoreboard_fd, (long) child_num * sizeof(worker_score), 0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein force_write(scoreboard_fd, new_score_rec, sizeof(worker_score));
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein (char *) &ap_scoreboard_image->global -(char *) ap_scoreboard_image, 0);
9f18c80269be35c0b5653e84b0db0a24044722c4gstein force_write(scoreboard_fd, &ap_scoreboard_image->global,
9f18c80269be35c0b5653e84b0db0a24044722c4gsteinAP_DECLARE(void) ap_increment_counts(int child_num, int thread_num, request_rec *r)
709df1e1c2e1710570f8cb4209497e88662829c3gstein ws = &ap_scoreboard_image->servers[child_num][thread_num];
000397350b42c6266351bd618fa07df929fa7c79gstein ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit);
000397350b42c6266351bd618fa07df929fa7c79gstein for (i = 0; i < max_daemons_limit; ++i)
000397350b42c6266351bd618fa07df929fa7c79gsteinAP_DECLARE(int) ap_update_child_status(int child_num, int thread_num, int status, request_rec *r)
9f18c80269be35c0b5653e84b0db0a24044722c4gstein ws = &ap_scoreboard_image->servers[child_num][thread_num];
9f18c80269be35c0b5653e84b0db0a24044722c4gstein ws->thread_num = child_num * HARD_SERVER_LIMIT + thread_num;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (status == SERVER_READY || status == SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Reset individual counters
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_cpystrn(ws->client, ap_get_remote_host(c, r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_cpystrn(ws->request, "NULL", sizeof(ws->request));
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_cpystrn(ws->request, r->the_request, sizeof(ws->request));
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Don't reveal the password in the server-status view */
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker apr_cpystrn(ws->request, apr_pstrcat(r->pool, r->method, " ",
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_uri_unparse(r->pool, &r->parsed_uri, APR_URI_UNP_OMITPASSWORD),
f4c310fd2555c6faca1f980f00b161eadb089023gsteinvoid ap_time_process_request(int child_num, int thread_num, int status)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws = &ap_scoreboard_image->servers[child_num][thread_num];
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker if (((x < 0) || (HARD_SERVER_LIMIT < x)) ||
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker ((y < 0) || (HARD_THREAD_LIMIT < y))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((x < 0) || (HARD_SERVER_LIMIT < x)) {