]> granicus.if.org Git - apache/blob - include/scoreboard.h
fix name of The Apache Software Foundation
[apache] / include / scoreboard.h
1 /* Copyright 2001-2004 The Apache Software Foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef APACHE_SCOREBOARD_H
17 #define APACHE_SCOREBOARD_H
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 #ifdef HAVE_SYS_TIMES_H
24 #include <sys/time.h>
25 #include <sys/times.h>
26 #elif defined(TPF)
27 #include <time.h>
28 #endif
29
30 #include "ap_config.h"
31 #include "apr_hooks.h"
32 #include "apr_thread_proc.h"
33 #include "apr_portable.h"
34 #include "apr_shm.h"
35
36 /* Scoreboard file, if there is one */
37 #ifndef DEFAULT_SCOREBOARD
38 #define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
39 #endif
40
41 /* Scoreboard info on a process is, for now, kept very brief --- 
42  * just status value and pid (the latter so that the caretaker process
43  * can properly update the scoreboard when a process dies).  We may want
44  * to eventually add a separate set of long_score structures which would
45  * give, for each process, the number of requests serviced, and info on
46  * the current, or most recent, request.
47  *
48  * Status values:
49  */
50
51 #define SERVER_DEAD 0
52 #define SERVER_STARTING 1       /* Server Starting up */
53 #define SERVER_READY 2          /* Waiting for connection (or accept() lock) */
54 #define SERVER_BUSY_READ 3      /* Reading a client request */
55 #define SERVER_BUSY_WRITE 4     /* Processing a client request */
56 #define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */
57 #define SERVER_BUSY_LOG 6       /* Logging the request */
58 #define SERVER_BUSY_DNS 7       /* Looking up a hostname */
59 #define SERVER_CLOSING 8        /* Closing the connection */
60 #define SERVER_GRACEFUL 9       /* server is gracefully finishing request */
61 #define SERVER_IDLE_KILL 10     /* Server is cleaning up idle children. */
62 #define SERVER_NUM_STATUS 11    /* number of status settings */
63
64 /* Type used for generation indicies.  Startup and every restart cause a
65  * new generation of children to be spawned.  Children within the same
66  * generation share the same configuration information -- pointers to stuff
67  * created at config time in the parent are valid across children.  However,
68  * this can't work effectively with non-forked architectures.  So while the
69  * arrays in the scoreboard never change between the parent and forked
70  * children, so they do not require shm storage, the contents of the shm
71  * may contain no pointers.
72  */
73 typedef int ap_generation_t;
74
75 /* Is the scoreboard shared between processes or not? 
76  * Set by the MPM when the scoreboard is created.
77  */
78 typedef enum {
79     SB_NOT_SHARED = 1,
80     SB_SHARED = 2
81 } ap_scoreboard_e;
82
83 #define SB_WORKING  0  /* The server is busy and the child is useful. */
84 #define SB_IDLE_DIE 1  /* The server is idle and the child is superfluous. */
85                        /*   The child should check for this and exit gracefully. */
86
87 /* stuff which is worker specific */
88 /***********************WARNING***************************************/
89 /* These are things that are used by mod_status. Do not put anything */
90 /*   in here that you cannot live without. This structure will not   */
91 /*   be available if mod_status is not loaded.                       */
92 /*********************************************************************/
93 typedef struct worker_score worker_score;
94
95 struct worker_score {
96     int thread_num;
97 #if APR_HAS_THREADS
98     apr_os_thread_t tid;
99 #endif
100     unsigned char status;
101     unsigned long access_count;
102     apr_off_t     bytes_served;
103     unsigned long my_access_count;
104     apr_off_t     my_bytes_served;
105     apr_off_t     conn_bytes;
106     unsigned short conn_count;
107     apr_time_t start_time;
108     apr_time_t stop_time;
109 #ifdef HAVE_TIMES
110     struct tms times;
111 #endif
112     apr_time_t last_used;
113     char client[32];            /* Keep 'em small... */
114     char request[64];           /* We just want an idea... */
115     char vhost[32];             /* What virtual host is being accessed? */
116 };
117
118 typedef struct {
119     int             server_limit;
120     int             thread_limit;
121     ap_scoreboard_e sb_type;
122     ap_generation_t running_generation; /* the generation of children which
123                                          * should still be serving requests. */
124     apr_time_t restart_time;
125 } global_score;
126
127 /* stuff which the parent generally writes and the children rarely read */
128 typedef struct process_score process_score;
129 struct process_score{
130     pid_t pid;
131     ap_generation_t generation; /* generation of this child */
132     ap_scoreboard_e sb_type;
133     int quiescing;          /* the process whose pid is stored above is
134                              * going down gracefully
135                              */
136 };
137
138 /* Scoreboard is now in 'local' memory, since it isn't updated once created,
139  * even in forked architectures.  Child created-processes (non-fork) will
140  * set up these indicies into the (possibly relocated) shmem records.
141  */
142 typedef struct {
143     global_score *global;
144     process_score *parent;
145     worker_score **servers;
146 } scoreboard;
147
148 typedef struct ap_sb_handle_t ap_sb_handle_t;
149
150 AP_DECLARE(int) ap_exists_scoreboard_image(void);
151 AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r);
152
153 int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
154 apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached);
155 void ap_init_scoreboard(void *shared_score);
156 AP_DECLARE(int) ap_calc_scoreboard_size(void);
157 apr_status_t ap_cleanup_scoreboard(void *d);
158
159 AP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p,
160                                      int child_num, int thread_num);
161     
162 AP_DECLARE(int) find_child_by_pid(apr_proc_t *pid);
163 AP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status, request_rec *r);
164 AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num, int thread_num,
165                                                     int status, request_rec *r);
166 void ap_time_process_request(int child_num, int thread_num, int status);
167
168 AP_DECLARE(worker_score *) ap_get_scoreboard_worker(int x, int y);
169 AP_DECLARE(process_score *) ap_get_scoreboard_process(int x);
170 AP_DECLARE(global_score *) ap_get_scoreboard_global(void);
171
172 AP_DECLARE_DATA extern scoreboard *ap_scoreboard_image;
173 AP_DECLARE_DATA extern const char *ap_scoreboard_fname;
174 AP_DECLARE_DATA extern int ap_extended_status;
175
176 AP_DECLARE_DATA extern ap_generation_t volatile ap_my_generation;
177
178 /* Hooks */
179 /**
180   * Hook for post scoreboard creation, pre mpm.
181   * @param p       Apache pool to allocate from.
182   * @param sb_type 
183   * @ingroup hooks
184   * @return OK or DECLINE on success; anything else is a error
185   */  
186 AP_DECLARE_HOOK(int, pre_mpm, (apr_pool_t *p, ap_scoreboard_e sb_type))
187
188 /* for time_process_request() in http_main.c */
189 #define START_PREQUEST 1
190 #define STOP_PREQUEST  2
191
192 #ifdef __cplusplus
193 }
194 #endif
195
196 #endif  /* !APACHE_SCOREBOARD_H */