scoreboard.h revision dd6c2b6a1c20c2d0fef568e694be8d8cad669c0e
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* ====================================================================
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * The Apache Software License, Version 1.1
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Copyright (c) 2000 The Apache Software Foundation. All rights
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * reserved.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Redistribution and use in source and binary forms, with or without
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * modification, are permitted provided that the following conditions
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * are met:
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 1. Redistributions of source code must retain the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * 2. Redistributions in binary form must reproduce the above copyright
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * notice, this list of conditions and the following disclaimer in
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen * the documentation and/or other materials provided with the
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * distribution.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * 3. The end-user documentation included with the redistribution,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * if any, must include the following acknowledgment:
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * "This product includes software developed by the
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Apache Software Foundation (http://www.apache.org/)."
9472e4d3c410be3b3f1addbf3b1db1769f64e765nd * Alternately, this acknowledgment may appear in the software itself,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * if and wherever such third-party acknowledgments normally appear.
1c8f2418892d98febb00a06b9a4f45f8bcfd80a3nd * 4. The names "Apache" and "Apache Software Foundation" must
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * not be used to endorse or promote products derived from this
fac8c35bfb158112226ab43ddf84d59daca5dc30nd * software without prior written permission. For written
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * permission, please contact apache@apache.org.
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * 5. Products derived from this software may not be called "Apache",
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * nor may "Apache" appear in their name, without prior written
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * permission of the Apache Software Foundation.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * SUCH DAMAGE.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * ====================================================================
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * This software consists of voluntary contributions made by many
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * individuals on behalf of the Apache Software Foundation. For more
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * information on the Apache Software Foundation, please see
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Portions of this software are based upon public domain software
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * originally written at the National Center for Supercomputing Applications,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * University of Illinois, Urbana-Champaign.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndextern "C" {
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/*The optimized timeout code only works if we're not using a scoreboard file*/
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* Scoreboard info on a process is, for now, kept very brief ---
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * just status value and pid (the latter so that the caretaker process
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * can properly update the scoreboard when a process dies). We may want
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * to eventually add a separate set of long_score structures which would
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * give, for each process, the number of requests serviced, and info on
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * the current, or most recent, request.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Status values:
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_READY 2 /* Waiting for connection (or accept() lock) */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_BUSY_WRITE 4 /* Processing a client request */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_GRACEFUL 8 /* server is gracefully finishing request */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_ACCEPTING 9 /* thread is accepting connections */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_QUEUEING 10 /* thread is putting connection on the queue */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_NUM_STATUS 11 /* number of status settings */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* A "virtual time" is simply a counter that indicates that a child is
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * making progress. The parent checks up on each child, and when they have
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * made progress it resets the last_rtime element. But when the child hasn't
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * made progress in a time that's roughly timeout_len seconds long, it is
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * sent a SIGALRM.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * vtime is an optimization that is used only when the scoreboard is in
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * shared memory (it's not easy/feasible to do it in a scoreboard file).
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * The essential observation is that timeouts rarely occur, the vast majority
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * of hits finish before any timeout happens. So it really sucks to have to
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * ask the operating system to set up and destroy alarms many times during
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * a request.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndtypedef unsigned vtime_t;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* Type used for generation indicies. Startup and every restart cause a
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * new generation of children to be spawned. Children within the same
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * generation share the same configuration information -- pointers to stuff
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * created at config time in the parent are valid across children. For
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * example, the vhostrec pointer in the scoreboard below is valid in all
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * children of the same generation.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * The safe way to access the vhost pointer is like this:
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * short_score *ss = pointer to whichver slot is interesting;
51b60896224b408a35684bd6ec0fafe5e4abe322rbowen * parent_score *ps = pointer to whichver slot is interesting;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * server_rec *vh = ss->vhostrec;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * if (ps->generation != ap_my_generation) {
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * vh = NULL;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * then if vh is not NULL it's valid in this child.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * This avoids various race conditions around restarts.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* stuff which is thread/process specific */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndtypedef struct {
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned char status;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned long access_count;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned long bytes_served;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned long my_access_count;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned long my_bytes_served;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned long conn_bytes;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned short conn_count;
1c8f2418892d98febb00a06b9a4f45f8bcfd80a3nd server_rec *vhostrec; /* What virtual host is being accessed? */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* SEE ABOVE FOR SAFE USAGE! */
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedoohtypedef struct {
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh ap_generation_t running_generation; /* the generation of children which
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * should still be serving requests. */
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh/* stuff which the parent generally writes and the children rarely read */
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedoohtypedef struct {
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh ap_generation_t generation; /* generation of this child */
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh time_t last_rtime; /* time(0) of the last change */
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh vtime_t last_vtime; /* the last vtime the parent has seen */
5effc8b39fae5cd169d17f342bfc265705840014rbowentypedef struct {
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen short_score servers[HARD_SERVER_LIMIT][HARD_THREAD_LIMIT];
#ifdef TPF
void update_scoreboard_global(void);
/* for time_process_request() in http_main.c */
#ifdef __cplusplus