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