1 /* Copyright 2001-2004 The Apache Software Foundation
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef APACHE_SCOREBOARD_H
17 #define APACHE_SCOREBOARD_H
23 #ifdef HAVE_SYS_TIMES_H
25 #include <sys/times.h>
30 #include "ap_config.h"
31 #include "apr_hooks.h"
32 #include "apr_thread_proc.h"
33 #include "apr_portable.h"
35 #include "apr_optional.h"
37 /* Scoreboard file, if there is one */
38 #ifndef DEFAULT_SCOREBOARD
39 #define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
42 /* Scoreboard info on a process is, for now, kept very brief ---
43 * just status value and pid (the latter so that the caretaker process
44 * can properly update the scoreboard when a process dies). We may want
45 * to eventually add a separate set of long_score structures which would
46 * give, for each process, the number of requests serviced, and info on
47 * the current, or most recent, request.
53 #define SERVER_STARTING 1 /* Server Starting up */
54 #define SERVER_READY 2 /* Waiting for connection (or accept() lock) */
55 #define SERVER_BUSY_READ 3 /* Reading a client request */
56 #define SERVER_BUSY_WRITE 4 /* Processing a client request */
57 #define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */
58 #define SERVER_BUSY_LOG 6 /* Logging the request */
59 #define SERVER_BUSY_DNS 7 /* Looking up a hostname */
60 #define SERVER_CLOSING 8 /* Closing the connection */
61 #define SERVER_GRACEFUL 9 /* server is gracefully finishing request */
62 #define SERVER_IDLE_KILL 10 /* Server is cleaning up idle children. */
63 #define SERVER_NUM_STATUS 11 /* number of status settings */
65 /* Type used for generation indicies. Startup and every restart cause a
66 * new generation of children to be spawned. Children within the same
67 * generation share the same configuration information -- pointers to stuff
68 * created at config time in the parent are valid across children. However,
69 * this can't work effectively with non-forked architectures. So while the
70 * arrays in the scoreboard never change between the parent and forked
71 * children, so they do not require shm storage, the contents of the shm
72 * may contain no pointers.
74 typedef int ap_generation_t;
76 /* Is the scoreboard shared between processes or not?
77 * Set by the MPM when the scoreboard is created.
84 #define SB_WORKING 0 /* The server is busy and the child is useful. */
85 #define SB_IDLE_DIE 1 /* The server is idle and the child is superfluous. */
86 /* The child should check for this and exit gracefully. */
88 /* stuff which is worker specific */
89 /***********************WARNING***************************************/
90 /* These are things that are used by mod_status. Do not put anything */
91 /* in here that you cannot live without. This structure will not */
92 /* be available if mod_status is not loaded. */
93 /*********************************************************************/
94 typedef struct worker_score worker_score;
101 unsigned char status;
102 unsigned long access_count;
103 apr_off_t bytes_served;
104 unsigned long my_access_count;
105 apr_off_t my_bytes_served;
106 apr_off_t conn_bytes;
107 unsigned short conn_count;
108 apr_time_t start_time;
109 apr_time_t stop_time;
113 apr_time_t last_used;
114 char client[32]; /* Keep 'em small... */
115 char request[64]; /* We just want an idea... */
116 char vhost[32]; /* What virtual host is being accessed? */
122 ap_scoreboard_e sb_type;
123 ap_generation_t running_generation; /* the generation of children which
124 * should still be serving requests.
126 apr_time_t restart_time;
130 /* stuff which the parent generally writes and the children rarely read */
131 typedef struct process_score process_score;
132 struct process_score{
134 ap_generation_t generation; /* generation of this child */
135 ap_scoreboard_e sb_type;
136 int quiescing; /* the process whose pid is stored above is
137 * going down gracefully
141 /* stuff which is lb specific */
142 typedef struct lb_score lb_score;
144 /* TODO: make a real stuct from this */
145 unsigned char data[1024];
148 /* Scoreboard is now in 'local' memory, since it isn't updated once created,
149 * even in forked architectures. Child created-processes (non-fork) will
150 * set up these indicies into the (possibly relocated) shmem records.
153 global_score *global;
154 process_score *parent;
155 worker_score **servers;
159 typedef struct ap_sb_handle_t ap_sb_handle_t;
161 AP_DECLARE(int) ap_exists_scoreboard_image(void);
162 AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r);
164 int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
165 apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached);
166 void ap_init_scoreboard(void *shared_score);
167 AP_DECLARE(int) ap_calc_scoreboard_size(void);
168 apr_status_t ap_cleanup_scoreboard(void *d);
170 AP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p,
171 int child_num, int thread_num);
173 AP_DECLARE(int) find_child_by_pid(apr_proc_t *pid);
174 AP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status, request_rec *r);
175 AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num, int thread_num,
176 int status, request_rec *r);
177 void ap_time_process_request(int child_num, int thread_num, int status);
179 AP_DECLARE(worker_score *) ap_get_scoreboard_worker(int x, int y);
180 AP_DECLARE(process_score *) ap_get_scoreboard_process(int x);
181 AP_DECLARE(global_score *) ap_get_scoreboard_global(void);
182 AP_DECLARE(lb_score *) ap_get_scoreboard_lb(int lb_num);
184 AP_DECLARE_DATA extern scoreboard *ap_scoreboard_image;
185 AP_DECLARE_DATA extern const char *ap_scoreboard_fname;
186 AP_DECLARE_DATA extern int ap_extended_status;
188 AP_DECLARE_DATA extern ap_generation_t volatile ap_my_generation;
192 * Hook for post scoreboard creation, pre mpm.
193 * @param p Apache pool to allocate from.
196 * @return OK or DECLINE on success; anything else is a error
198 AP_DECLARE_HOOK(int, pre_mpm, (apr_pool_t *p, ap_scoreboard_e sb_type))
201 * proxy load balancer
202 * @return the number of load balancer workers.
204 APR_DECLARE_OPTIONAL_FN(int, ap_proxy_lb_workers,
207 /* for time_process_request() in http_main.c */
208 #define START_PREQUEST 1
209 #define STOP_PREQUEST 2
215 #endif /* !APACHE_SCOREBOARD_H */