Annotation of win32/apache13/src/include/scoreboard.h, revision 1.1.1.1

1.1       parser      1: /* ====================================================================
                      2:  * Copyright (c) 1995-1999 The Apache Group.  All rights reserved.
                      3:  *
                      4:  * Redistribution and use in source and binary forms, with or without
                      5:  * modification, are permitted provided that the following conditions
                      6:  * are met:
                      7:  *
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer. 
                     10:  *
                     11:  * 2. Redistributions in binary form must reproduce the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer in
                     13:  *    the documentation and/or other materials provided with the
                     14:  *    distribution.
                     15:  *
                     16:  * 3. All advertising materials mentioning features or use of this
                     17:  *    software must display the following acknowledgment:
                     18:  *    "This product includes software developed by the Apache Group
                     19:  *    for use in the Apache HTTP server project (http://www.apache.org/)."
                     20:  *
                     21:  * 4. The names "Apache Server" and "Apache Group" must not be used to
                     22:  *    endorse or promote products derived from this software without
                     23:  *    prior written permission. For written permission, please contact
                     24:  *    apache@apache.org.
                     25:  *
                     26:  * 5. Products derived from this software may not be called "Apache"
                     27:  *    nor may "Apache" appear in their names without prior written
                     28:  *    permission of the Apache Group.
                     29:  *
                     30:  * 6. Redistributions of any form whatsoever must retain the following
                     31:  *    acknowledgment:
                     32:  *    "This product includes software developed by the Apache Group
                     33:  *    for use in the Apache HTTP server project (http://www.apache.org/)."
                     34:  *
                     35:  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
                     36:  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     37:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     38:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
                     39:  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
                     40:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     41:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
                     42:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     43:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
                     44:  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     45:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
                     46:  * OF THE POSSIBILITY OF SUCH DAMAGE.
                     47:  * ====================================================================
                     48:  *
                     49:  * This software consists of voluntary contributions made by many
                     50:  * individuals on behalf of the Apache Group and was originally based
                     51:  * on public domain software written at the National Center for
                     52:  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
                     53:  * For more information on the Apache Group and the Apache HTTP server
                     54:  * project, please see <http://www.apache.org/>.
                     55:  *
                     56:  */
                     57: 
                     58: #ifndef APACHE_SCOREBOARD_H
                     59: #define APACHE_SCOREBOARD_H
                     60: 
                     61: #ifdef __cplusplus
                     62: extern "C" {
                     63: #endif
                     64: 
                     65: #ifndef WIN32
                     66: #if defined(TPF) || defined(NETWARE)
                     67: #include <time.h>
                     68: #else
                     69: #include <sys/times.h>
                     70: #endif /* TPF */
                     71: #endif
                     72: 
                     73: 
                     74: /* Scoreboard info on a process is, for now, kept very brief --- 
                     75:  * just status value and pid (the latter so that the caretaker process
                     76:  * can properly update the scoreboard when a process dies).  We may want
                     77:  * to eventually add a separate set of long_score structures which would
                     78:  * give, for each process, the number of requests serviced, and info on
                     79:  * the current, or most recent, request.
                     80:  *
                     81:  * Status values:
                     82:  */
                     83: 
                     84: #define SERVER_DEAD 0
                     85: #define SERVER_STARTING 1      /* Server Starting up */
                     86: #define SERVER_READY 2         /* Waiting for connection (or accept() lock) */
                     87: #define SERVER_BUSY_READ 3     /* Reading a client request */
                     88: #define SERVER_BUSY_WRITE 4    /* Processing a client request */
                     89: #define SERVER_BUSY_KEEPALIVE 5        /* Waiting for more requests via keepalive */
                     90: #define SERVER_BUSY_LOG 6      /* Logging the request */
                     91: #define SERVER_BUSY_DNS 7      /* Looking up a hostname */
                     92: #define SERVER_GRACEFUL 8      /* server is gracefully finishing request */
                     93: #define SERVER_NUM_STATUS 9    /* number of status settings */
                     94: 
                     95: /* A "virtual time" is simply a counter that indicates that a child is
                     96:  * making progress.  The parent checks up on each child, and when they have
                     97:  * made progress it resets the last_rtime element.  But when the child hasn't
                     98:  * made progress in a time that's roughly timeout_len seconds long, it is
                     99:  * sent a SIGALRM.
                    100:  *
                    101:  * vtime is an optimization that is used only when the scoreboard is in
                    102:  * shared memory (it's not easy/feasible to do it in a scoreboard file).
                    103:  * The essential observation is that timeouts rarely occur, the vast majority
                    104:  * of hits finish before any timeout happens.  So it really sucks to have to
                    105:  * ask the operating system to set up and destroy alarms many times during
                    106:  * a request.
                    107:  */
                    108: typedef unsigned vtime_t;
                    109: 
                    110: /* Type used for generation indicies.  Startup and every restart cause a
                    111:  * new generation of children to be spawned.  Children within the same
                    112:  * generation share the same configuration information -- pointers to stuff
                    113:  * created at config time in the parent are valid across children.  For
                    114:  * example, the vhostrec pointer in the scoreboard below is valid in all
                    115:  * children of the same generation.
                    116:  *
                    117:  * The safe way to access the vhost pointer is like this:
                    118:  *
                    119:  * short_score *ss = pointer to whichver slot is interesting;
                    120:  * parent_score *ps = pointer to whichver slot is interesting;
                    121:  * server_rec *vh = ss->vhostrec;
                    122:  *
                    123:  * if (ps->generation != ap_my_generation) {
                    124:  *     vh = NULL;
                    125:  * }
                    126:  *
                    127:  * then if vh is not NULL it's valid in this child.
                    128:  *
                    129:  * This avoids various race conditions around restarts.
                    130:  */
                    131: typedef int ap_generation_t;
                    132: 
                    133: /* stuff which the children generally write, and the parent mainly reads */
                    134: typedef struct {
                    135: #ifdef OPTIMIZE_TIMEOUTS
                    136:     vtime_t cur_vtime;         /* the child's current vtime */
                    137:     unsigned short timeout_len;        /* length of the timeout */
                    138: #endif
                    139:     unsigned char status;
                    140:     unsigned long access_count;
                    141:     unsigned long bytes_served;
                    142:     unsigned long my_access_count;
                    143:     unsigned long my_bytes_served;
                    144:     unsigned long conn_bytes;
                    145:     unsigned short conn_count;
                    146: #if defined(NO_GETTIMEOFDAY)
                    147:     clock_t start_time;
                    148:     clock_t stop_time;
                    149: #else
                    150:     struct timeval start_time;
                    151:     struct timeval stop_time;
                    152: #endif
                    153: #ifndef NO_TIMES
                    154:     struct tms times;
                    155: #endif
                    156: #ifndef OPTIMIZE_TIMEOUTS
                    157:     time_t last_used;
                    158: #endif
                    159:     char client[32];           /* Keep 'em small... */
                    160:     char request[64];          /* We just want an idea... */
                    161:     server_rec *vhostrec;      /* What virtual host is being accessed? */
                    162:                                 /* SEE ABOVE FOR SAFE USAGE! */
                    163: } short_score;
                    164: 
                    165: typedef struct {
                    166:     ap_generation_t running_generation;        /* the generation of children which
                    167:                                          * should still be serving requests. */
                    168: } global_score;
                    169: 
                    170: /* stuff which the parent generally writes and the children rarely read */
                    171: typedef struct {
                    172:     pid_t pid;
                    173: #ifdef OPTIMIZE_TIMEOUTS
                    174:     time_t last_rtime;         /* time(0) of the last change */
                    175:     vtime_t last_vtime;                /* the last vtime the parent has seen */
                    176: #endif
                    177:     ap_generation_t generation;        /* generation of this child */
                    178: } parent_score;
                    179: 
                    180: typedef struct {
                    181:     short_score servers[HARD_SERVER_LIMIT];
                    182:     parent_score parent[HARD_SERVER_LIMIT];
                    183:     global_score global;
                    184: } scoreboard;
                    185: 
                    186: #define SCOREBOARD_SIZE                sizeof(scoreboard)
                    187: #ifdef TPF
                    188: #define SCOREBOARD_NAME                "SCOREBRD"
                    189: #define SCOREBOARD_FRAMES              SCOREBOARD_SIZE/4095 + 1
                    190: #endif
                    191: 
                    192: API_EXPORT(void) ap_sync_scoreboard_image(void);
                    193: API_EXPORT(int) ap_exists_scoreboard_image(void);
                    194: 
                    195: API_VAR_EXPORT extern scoreboard *ap_scoreboard_image;
                    196: 
                    197: API_VAR_EXPORT extern ap_generation_t volatile ap_my_generation;
                    198: 
                    199: /* for time_process_request() in http_main.c */
                    200: #define START_PREQUEST 1
                    201: #define STOP_PREQUEST  2
                    202: 
                    203: #ifdef __cplusplus
                    204: }
                    205: #endif
                    206: 
                    207: #endif /* !APACHE_SCOREBOARD_H */

E-mail: