]> granicus.if.org Git - apache/blob - include/scoreboard.h
cleanup handle_set function
[apache] / include / scoreboard.h
1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * 3. The end-user documentation included with the redistribution,
20  *    if any, must include the following acknowledgment:
21  *       "This product includes software developed by the
22  *        Apache Software Foundation (http://www.apache.org/)."
23  *    Alternately, this acknowledgment may appear in the software itself,
24  *    if and wherever such third-party acknowledgments normally appear.
25  *
26  * 4. The names "Apache" and "Apache Software Foundation" must
27  *    not be used to endorse or promote products derived from this
28  *    software without prior written permission. For written
29  *    permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache",
32  *    nor may "Apache" appear in their name, without prior written
33  *    permission of the Apache Software Foundation.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation.  For more
51  * information on the Apache Software Foundation, please see
52  * <http://www.apache.org/>.
53  *
54  * Portions of this software are based upon public domain software
55  * originally written at the National Center for Supercomputing Applications,
56  * University of Illinois, Urbana-Champaign.
57  */
58
59 #ifndef APACHE_SCOREBOARD_H
60 #define APACHE_SCOREBOARD_H
61
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65
66 #ifdef HAVE_SYS_TIMES_H
67 #include <sys/time.h>
68 #include <sys/times.h>
69 #elif defined(TPF)
70 #include <time.h>
71 #endif
72
73 #include "ap_config.h"
74 #include "apr_hooks.h"
75 #include "apr_thread_proc.h"
76 #include "apr_portable.h"
77 #include "apr_shm.h"
78
79 /* Scoreboard file, if there is one */
80 #ifndef DEFAULT_SCOREBOARD
81 #define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
82 #endif
83
84 /* Scoreboard info on a process is, for now, kept very brief --- 
85  * just status value and pid (the latter so that the caretaker process
86  * can properly update the scoreboard when a process dies).  We may want
87  * to eventually add a separate set of long_score structures which would
88  * give, for each process, the number of requests serviced, and info on
89  * the current, or most recent, request.
90  *
91  * Status values:
92  */
93
94 #define SERVER_DEAD 0
95 #define SERVER_STARTING 1       /* Server Starting up */
96 #define SERVER_READY 2          /* Waiting for connection (or accept() lock) */
97 #define SERVER_BUSY_READ 3      /* Reading a client request */
98 #define SERVER_BUSY_WRITE 4     /* Processing a client request */
99 #define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */
100 #define SERVER_BUSY_LOG 6       /* Logging the request */
101 #define SERVER_BUSY_DNS 7       /* Looking up a hostname */
102 #define SERVER_CLOSING 8        /* Closing the connection */
103 #define SERVER_GRACEFUL 9       /* server is gracefully finishing request */
104 #define SERVER_IDLE_KILL 10     /* Server is cleaning up idle children. */
105 #define SERVER_NUM_STATUS 11    /* number of status settings */
106
107 /* Type used for generation indicies.  Startup and every restart cause a
108  * new generation of children to be spawned.  Children within the same
109  * generation share the same configuration information -- pointers to stuff
110  * created at config time in the parent are valid across children.  However,
111  * this can't work effectively with non-forked architectures.  So while the
112  * arrays in the scoreboard never change between the parent and forked
113  * children, so they do not require shm storage, the contents of the shm
114  * may contain no pointers.
115  */
116 typedef int ap_generation_t;
117
118 /* Is the scoreboard shared between processes or not? 
119  * Set by the MPM when the scoreboard is created.
120  */
121 typedef enum {
122     SB_NOT_SHARED = 1,
123     SB_SHARED = 2
124 } ap_scoreboard_e;
125
126 #define SB_WORKING  0  /* The server is busy and the child is useful. */
127 #define SB_IDLE_DIE 1  /* The server is idle and the child is superfluous. */
128                        /*   The child should check for this and exit gracefully. */
129
130 /* stuff which is worker specific */
131 /***********************WARNING***************************************/
132 /* These are things that are used by mod_status. Do not put anything */
133 /*   in here that you cannot live without. This structure will not   */
134 /*   be available if mod_status is not loaded.                       */
135 /*********************************************************************/
136 typedef struct worker_score worker_score;
137
138 struct worker_score {
139     int thread_num;
140 #if APR_HAS_THREADS
141     apr_os_thread_t tid;
142 #endif
143     unsigned char status;
144     unsigned long access_count;
145     apr_off_t     bytes_served;
146     unsigned long my_access_count;
147     apr_off_t     my_bytes_served;
148     apr_off_t     conn_bytes;
149     unsigned short conn_count;
150     apr_time_t start_time;
151     apr_time_t stop_time;
152 #ifdef HAVE_TIMES
153     struct tms times;
154 #endif
155     apr_time_t last_used;
156     char client[32];            /* Keep 'em small... */
157     char request[64];           /* We just want an idea... */
158     char vhost[32];             /* What virtual host is being accessed? */
159 };
160
161 typedef struct {
162     int             server_limit;
163     int             thread_limit;
164     ap_scoreboard_e sb_type;
165     ap_generation_t running_generation; /* the generation of children which
166                                          * should still be serving requests. */
167     apr_time_t restart_time;
168 } global_score;
169
170 /* stuff which the parent generally writes and the children rarely read */
171 typedef struct process_score process_score;
172 struct process_score{
173     pid_t pid;
174     ap_generation_t generation; /* generation of this child */
175     ap_scoreboard_e sb_type;
176     int quiescing;          /* the process whose pid is stored above is
177                              * going down gracefully
178                              */
179 };
180
181 /* Scoreboard is now in 'local' memory, since it isn't updated once created,
182  * even in forked architectures.  Child created-processes (non-fork) will
183  * set up these indicies into the (possibly relocated) shmem records.
184  */
185 typedef struct {
186     global_score *global;
187     process_score *parent;
188     worker_score **servers;
189 } scoreboard;
190
191 typedef struct ap_sb_handle_t ap_sb_handle_t;
192
193 AP_DECLARE(int) ap_exists_scoreboard_image(void);
194 AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r);
195
196 int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
197 apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached);
198 void ap_init_scoreboard(void *shared_score);
199 AP_DECLARE(int) ap_calc_scoreboard_size(void);
200 apr_status_t ap_cleanup_scoreboard(void *d);
201
202 AP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p,
203                                      int child_num, int thread_num);
204     
205 AP_DECLARE(int) find_child_by_pid(apr_proc_t *pid);
206 AP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status, request_rec *r);
207 AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num, int thread_num,
208                                                     int status, request_rec *r);
209 void ap_time_process_request(int child_num, int thread_num, int status);
210
211 AP_DECLARE(worker_score *) ap_get_scoreboard_worker(int x, int y);
212 AP_DECLARE(process_score *) ap_get_scoreboard_process(int x);
213 AP_DECLARE(global_score *) ap_get_scoreboard_global(void);
214
215 AP_DECLARE_DATA extern scoreboard *ap_scoreboard_image;
216 AP_DECLARE_DATA extern const char *ap_scoreboard_fname;
217 AP_DECLARE_DATA extern int ap_extended_status;
218
219 AP_DECLARE_DATA extern ap_generation_t volatile ap_my_generation;
220
221 /* Hooks */
222 /**
223   * Hook for post scoreboard creation, pre mpm.
224   * @param p       Apache pool to allocate from.
225   * @param sb_type 
226   * @ingroup hooks
227   * @return OK or DECLINE on success; anything else is a error
228   */  
229 AP_DECLARE_HOOK(int, pre_mpm, (apr_pool_t *p, ap_scoreboard_e sb_type))
230
231 /* for time_process_request() in http_main.c */
232 #define START_PREQUEST 1
233 #define STOP_PREQUEST  2
234
235 #ifdef __cplusplus
236 }
237 #endif
238
239 #endif  /* !APACHE_SCOREBOARD_H */