home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / include / scoreboard.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-01  |  7.5 KB  |  203 lines

  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. #ifdef TPF
  67. #include <time.h>
  68. #else
  69. #include <sys/times.h>
  70. #endif /* TPF */
  71. #endif
  72.  
  73. /* Scoreboard info on a process is, for now, kept very brief --- 
  74.  * just status value and pid (the latter so that the caretaker process
  75.  * can properly update the scoreboard when a process dies).  We may want
  76.  * to eventually add a separate set of long_score structures which would
  77.  * give, for each process, the number of requests serviced, and info on
  78.  * the current, or most recent, request.
  79.  *
  80.  * Status values:
  81.  */
  82.  
  83. #define SERVER_DEAD 0
  84. #define SERVER_STARTING 1    /* Server Starting up */
  85. #define SERVER_READY 2        /* Waiting for connection (or accept() lock) */
  86. #define SERVER_BUSY_READ 3    /* Reading a client request */
  87. #define SERVER_BUSY_WRITE 4    /* Processing a client request */
  88. #define SERVER_BUSY_KEEPALIVE 5    /* Waiting for more requests via keepalive */
  89. #define SERVER_BUSY_LOG 6    /* Logging the request */
  90. #define SERVER_BUSY_DNS 7    /* Looking up a hostname */
  91. #define SERVER_GRACEFUL 8    /* server is gracefully finishing request */
  92. #define SERVER_NUM_STATUS 9    /* number of status settings */
  93.  
  94. /* A "virtual time" is simply a counter that indicates that a child is
  95.  * making progress.  The parent checks up on each child, and when they have
  96.  * made progress it resets the last_rtime element.  But when the child hasn't
  97.  * made progress in a time that's roughly timeout_len seconds long, it is
  98.  * sent a SIGALRM.
  99.  *
  100.  * vtime is an optimization that is used only when the scoreboard is in
  101.  * shared memory (it's not easy/feasible to do it in a scoreboard file).
  102.  * The essential observation is that timeouts rarely occur, the vast majority
  103.  * of hits finish before any timeout happens.  So it really sucks to have to
  104.  * ask the operating system to set up and destroy alarms many times during
  105.  * a request.
  106.  */
  107. typedef unsigned vtime_t;
  108.  
  109. /* Type used for generation indicies.  Startup and every restart cause a
  110.  * new generation of children to be spawned.  Children within the same
  111.  * generation share the same configuration information -- pointers to stuff
  112.  * created at config time in the parent are valid across children.  For
  113.  * example, the vhostrec pointer in the scoreboard below is valid in all
  114.  * children of the same generation.
  115.  *
  116.  * The safe way to access the vhost pointer is like this:
  117.  *
  118.  * short_score *ss = pointer to whichver slot is interesting;
  119.  * parent_score *ps = pointer to whichver slot is interesting;
  120.  * server_rec *vh = ss->vhostrec;
  121.  *
  122.  * if (ps->generation != ap_my_generation) {
  123.  *     vh = NULL;
  124.  * }
  125.  *
  126.  * then if vh is not NULL it's valid in this child.
  127.  *
  128.  * This avoids various race conditions around restarts.
  129.  */
  130. typedef int ap_generation_t;
  131.  
  132. /* stuff which the children generally write, and the parent mainly reads */
  133. typedef struct {
  134. #ifdef OPTIMIZE_TIMEOUTS
  135.     vtime_t cur_vtime;        /* the child's current vtime */
  136.     unsigned short timeout_len;    /* length of the timeout */
  137. #endif
  138.     unsigned char status;
  139.     unsigned long access_count;
  140.     unsigned long bytes_served;
  141.     unsigned long my_access_count;
  142.     unsigned long my_bytes_served;
  143.     unsigned long conn_bytes;
  144.     unsigned short conn_count;
  145. #if defined(NO_GETTIMEOFDAY)
  146.     clock_t start_time;
  147.     clock_t stop_time;
  148. #else
  149.     struct timeval start_time;
  150.     struct timeval stop_time;
  151. #endif
  152. #ifndef NO_TIMES
  153.     struct tms times;
  154. #endif
  155. #ifndef OPTIMIZE_TIMEOUTS
  156.     time_t last_used;
  157. #endif
  158.     char client[32];        /* Keep 'em small... */
  159.     char request[64];        /* We just want an idea... */
  160.     server_rec *vhostrec;    /* What virtual host is being accessed? */
  161.                                 /* SEE ABOVE FOR SAFE USAGE! */
  162. } short_score;
  163.  
  164. typedef struct {
  165.     ap_generation_t running_generation;    /* the generation of children which
  166.                                          * should still be serving requests. */
  167. } global_score;
  168.  
  169. /* stuff which the parent generally writes and the children rarely read */
  170. typedef struct {
  171.     pid_t pid;
  172. #ifdef OPTIMIZE_TIMEOUTS
  173.     time_t last_rtime;        /* time(0) of the last change */
  174.     vtime_t last_vtime;        /* the last vtime the parent has seen */
  175. #endif
  176.     ap_generation_t generation;    /* generation of this child */
  177. } parent_score;
  178.  
  179. typedef struct {
  180.     short_score servers[HARD_SERVER_LIMIT];
  181.     parent_score parent[HARD_SERVER_LIMIT];
  182.     global_score global;
  183. } scoreboard;
  184.  
  185. #define SCOREBOARD_SIZE        sizeof(scoreboard)
  186.  
  187. API_EXPORT(void) ap_sync_scoreboard_image(void);
  188. API_EXPORT(int) ap_exists_scoreboard_image(void);
  189.  
  190. API_VAR_EXPORT extern scoreboard *ap_scoreboard_image;
  191.  
  192. API_VAR_EXPORT extern ap_generation_t volatile ap_my_generation;
  193.  
  194. /* for time_process_request() in http_main.c */
  195. #define START_PREQUEST 1
  196. #define STOP_PREQUEST  2
  197.  
  198. #ifdef __cplusplus
  199. }
  200. #endif
  201.  
  202. #endif    /* !APACHE_SCOREBOARD_H */
  203.