Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
scoreboard.h
Go to the documentation of this file.
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements. See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #ifndef APACHE_SCOREBOARD_H
23 #define APACHE_SCOREBOARD_H
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #if APR_HAVE_SYS_TIME_H
30 #include <sys/time.h>
31 #include <sys/times.h>
32 #endif
33 
34 #include "ap_config.h"
35 #include "http_config.h"
36 #include "apr_thread_proc.h"
37 #include "apr_portable.h"
38 #include "apr_shm.h"
39 #include "apr_optional.h"
40 
41 /* Scoreboard file, if there is one */
42 #ifndef DEFAULT_SCOREBOARD
43 #define DEFAULT_SCOREBOARD "apache_runtime_status" /* within DEFAULT_REL_RUNTIMEDIR */
44 #endif
45 
46 /* Scoreboard info on a process is, for now, kept very brief ---
47  * just status value and pid (the latter so that the caretaker process
48  * can properly update the scoreboard when a process dies). We may want
49  * to eventually add a separate set of long_score structures which would
50  * give, for each process, the number of requests serviced, and info on
51  * the current, or most recent, request.
52  *
53  * Status values:
54  */
55 
56 #define SERVER_DEAD 0
57 #define SERVER_STARTING 1 /* Server Starting up */
58 #define SERVER_READY 2 /* Waiting for connection (or accept() lock) */
59 #define SERVER_BUSY_READ 3 /* Reading a client request */
60 #define SERVER_BUSY_WRITE 4 /* Processing a client request */
61 #define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */
62 #define SERVER_BUSY_LOG 6 /* Logging the request */
63 #define SERVER_BUSY_DNS 7 /* Looking up a hostname */
64 #define SERVER_CLOSING 8 /* Closing the connection */
65 #define SERVER_GRACEFUL 9 /* server is gracefully finishing request */
66 #define SERVER_IDLE_KILL 10 /* Server is cleaning up idle children. */
67 #define SERVER_NUM_STATUS 11 /* number of status settings */
68 
69 /* Type used for generation indicies. Startup and every restart cause a
70  * new generation of children to be spawned. Children within the same
71  * generation share the same configuration information -- pointers to stuff
72  * created at config time in the parent are valid across children. However,
73  * this can't work effectively with non-forked architectures. So while the
74  * arrays in the scoreboard never change between the parent and forked
75  * children, so they do not require shm storage, the contents of the shm
76  * may contain no pointers.
77  */
78 typedef int ap_generation_t;
79 
80 /* Is the scoreboard shared between processes or not?
81  * Set by the MPM when the scoreboard is created.
82  */
83 typedef enum {
87 
88 /* stuff which is worker specific */
89 typedef struct worker_score worker_score;
90 struct worker_score {
91 #if APR_HAS_THREADS
93 #endif
95  /* With some MPMs (e.g., worker), a worker_score can represent
96  * a thread in a terminating process which is no longer
97  * represented by the corresponding process_score. These MPMs
98  * should set pid and generation fields in the worker_score.
99  */
100  pid_t pid;
101  ap_generation_t generation;
102  unsigned char status;
103  unsigned short conn_count;
105  unsigned long access_count;
107  unsigned long my_access_count;
112 #ifdef HAVE_TIMES
113  struct tms times;
114 #endif
115  char client[32]; /* DEPRECATED: Keep 'em small... */
116  char request[64]; /* We just want an idea... */
117  char vhost[32]; /* What virtual host is being accessed? */
118  char protocol[16]; /* What protocol is used on the connection? */
119  char client64[64];
121 };
122 
123 typedef struct {
126  ap_generation_t running_generation; /* the generation of children which
127  * should still be serving requests.
128  */
130 #ifdef HAVE_TIMES
131  struct tms times;
132 #endif
133 } global_score;
134 
135 /* stuff which the parent generally writes and the children rarely read */
138  pid_t pid;
139  ap_generation_t generation; /* generation of this child */
140  char quiescing; /* the process whose pid is stored above is
141  * going down gracefully
142  */
143  char not_accepting; /* the process is busy and is not accepting more
144  * connections (for async MPMs)
145  */
146  apr_uint32_t connections; /* total connections (for async MPMs) */
147  apr_uint32_t write_completion; /* async connections doing write completion */
148  apr_uint32_t lingering_close; /* async connections in lingering close */
149  apr_uint32_t keep_alive; /* async connections in keep alive */
150  apr_uint32_t suspended; /* connections suspended by some module */
151  int bucket; /* Listener bucket used by this child */
152 };
153 
154 /* Scoreboard is now in 'local' memory, since it isn't updated once created,
155  * even in forked architectures. Child created-processes (non-fork) will
156  * set up these indicies into the (possibly relocated) shmem records.
157  */
158 typedef struct {
162 } scoreboard;
163 
165 
166 /*
167  * Creation and deletion (internal)
168  */
171 
172 /*
173  * APIs for MPMs and other modules
174  */
177 AP_DECLARE(void) ap_set_conn_count(ap_sb_handle_t *sb, request_rec *r, unsigned short conn_count);
178 
180 AP_DECLARE(void) ap_init_scoreboard(void *shared_score);
182 
184  int child_num, int thread_num);
186  int child_num, int thread_num);
187 
190 AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num, int thread_num,
191  int status, request_rec *r);
194  conn_rec *c, server_rec *s);
195 AP_DECLARE(int) ap_update_child_status_descr(ap_sb_handle_t *sbh, int status, const char *descr);
196 
197 AP_DECLARE(void) ap_time_process_request(ap_sb_handle_t *sbh, int status);
198 
200 
202 
209  int thread_num);
210 
219  int child_num, int thread_num);
220 
223 
225 AP_DECLARE_DATA extern const char *ap_scoreboard_fname;
228 
229 /*
230  * Command handlers [internal]
231  */
232 const char *ap_set_scoreboard(cmd_parms *cmd, void *dummy, const char *arg);
233 const char *ap_set_extended_status(cmd_parms *cmd, void *dummy, int arg);
234 const char *ap_set_reqtail(cmd_parms *cmd, void *dummy, int arg);
235 
236 /* Hooks */
245 
246 /* for time_process_request() in http_main.c */
247 #define START_PREQUEST 1
248 #define STOP_PREQUEST 2
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #endif /* !APACHE_SCOREBOARD_H */
void ap_time_process_request(ap_sb_handle_t *sbh, int status)
int ap_generation_t
Definition: scoreboard.h:78
int thread_num
Definition: scoreboard.h:94
apr_uint32_t keep_alive
Definition: scoreboard.h:149
apr_status_t ap_cleanup_scoreboard(void *d)
Apache Configuration.
ap_generation_t generation
Definition: scoreboard.h:139
apr_uint32_t connections
Definition: scoreboard.h:146
Definition: scoreboard.h:158
pthread_t apr_os_thread_t
Definition: apr_portable.h:152
void ap_update_sb_handle(ap_sb_handle_t *sbh, int child_num, int thread_num)
Definition: scoreboard.h:123
int ap_update_child_status_descr(ap_sb_handle_t *sbh, int status, const char *descr)
void ap_init_scoreboard(void *shared_score)
apr_time_t restart_time
Definition: scoreboard.h:129
process_score * parent
Definition: scoreboard.h:160
Definition: scoreboard.h:84
int ap_update_child_status_from_indexes(int child_num, int thread_num, int status, request_rec *r)
apr_off_t conn_bytes
Definition: scoreboard.h:104
void ap_set_conn_count(ap_sb_handle_t *sb, request_rec *r, unsigned short conn_count)
int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t)
Definition: scoreboard.h:90
#define AP_DECLARE(x)
Definition: macros.h:1
int pre_mpm(apr_pool_t *p, ap_scoreboard_e sb_type)
apr_time_t start_time
Definition: scoreboard.h:109
AP_DECLARE_DATA scoreboard * ap_scoreboard_image
struct ap_sb_handle_t ap_sb_handle_t
Definition: scoreboard.h:164
Definition: apr_arch_shm.h:61
int ap_update_child_status(ap_sb_handle_t *sbh, int status, request_rec *r)
apr_off_t my_bytes_served
Definition: scoreboard.h:108
apr_uint32_t lingering_close
Definition: scoreboard.h:148
Definition: apr_thread_proc.h:144
process_score * ap_get_scoreboard_process(int x)
int thread_limit
Definition: scoreboard.h:125
char client[32]
Definition: scoreboard.h:115
void ap_copy_scoreboard_worker(worker_score *dest, int child_num, int thread_num)
apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached)
char quiescing
Definition: scoreboard.h:140
Structure to store things which are per connection.
Definition: httpd.h:1124
APR-UTIL registration of functions exported by modules.
void ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p, int child_num, int thread_num)
Symbol export macros and hook functions.
int ap_update_child_status_from_server(ap_sb_handle_t *sbh, int status, conn_rec *c, server_rec *s)
#define AP_DECLARE_HOOK(ret, name, args)
Definition: ap_hooks.h:74
char protocol[16]
Definition: scoreboard.h:118
Definition: http_config.h:295
apr_int64_t apr_time_t
Definition: apr_time.h:45
global_score * ap_get_scoreboard_global(void)
unsigned short conn_count
Definition: scoreboard.h:103
A structure to store information for each virtual server.
Definition: httpd.h:1311
apr_off_t bytes_served
Definition: scoreboard.h:106
AP_DECLARE_DATA const char * ap_scoreboard_fname
apr_time_t duration
Definition: scoreboard.h:120
char not_accepting
Definition: scoreboard.h:143
APR Shared Memory Routines.
apr_os_thread_t tid
Definition: scoreboard.h:92
unsigned int apr_uint32_t
Definition: apr.h:334
int ap_calc_scoreboard_size(void)
worker_score * ap_get_scoreboard_worker_from_indexes(int child_num, int thread_num)
ap_generation_t generation
Definition: scoreboard.h:101
int ap_exists_scoreboard_image(void)
ap_scoreboard_e
Definition: scoreboard.h:83
pid_t pid
Definition: scoreboard.h:100
const char * ap_set_scoreboard(cmd_parms *cmd, void *dummy, const char *arg)
const char * ap_set_extended_status(cmd_parms *cmd, void *dummy, int arg)
apr_uint32_t suspended
Definition: scoreboard.h:150
char request[64]
Definition: scoreboard.h:116
int ap_find_child_by_pid(apr_proc_t *pid)
apr_pool_t * p
APR Thread and Process Library.
ap_generation_t running_generation
Definition: scoreboard.h:126
const char * ap_set_reqtail(cmd_parms *cmd, void *dummy, int arg)
A structure that represents the current request.
Definition: httpd.h:811
unsigned long my_access_count
Definition: scoreboard.h:107
int ap_update_global_status(void)
Definition: scoreboard.h:85
#define AP_DECLARE_DATA
Definition: macros.h:15
apr_uint32_t write_completion
Definition: scoreboard.h:147
int status
Definition: mod_dav.h:141
global_score * global
Definition: scoreboard.h:159
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
char vhost[32]
Definition: scoreboard.h:117
apr_time_t stop_time
Definition: scoreboard.h:110
struct tms times
Definition: scoreboard.h:113
worker_score * ap_get_scoreboard_worker(ap_sb_handle_t *sbh)
char client64[64]
Definition: scoreboard.h:119
int apr_status_t
Definition: apr_errno.h:44
unsigned char status
Definition: scoreboard.h:102
Definition: scoreboard.h:137
request_rec * r
Definition: mod_dav.h:515
unsigned long access_count
Definition: scoreboard.h:105
apr_time_t last_used
Definition: scoreboard.h:111
pid_t pid
Definition: scoreboard.h:138
int server_limit
Definition: scoreboard.h:124
int bucket
Definition: scoreboard.h:151
worker_score ** servers
Definition: scoreboard.h:161
int ap_update_child_status_from_conn(ap_sb_handle_t *sbh, int status, conn_rec *c)
AP_DECLARE_DATA int ap_mod_status_reqtail
off_t apr_off_t
Definition: apr.h:377
APR Portability Routines.
AP_DECLARE_DATA int ap_extended_status
void ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r)