upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / include / scoreboard.h
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
17 #ifndef APACHE_SCOREBOARD_H
18 #define APACHE_SCOREBOARD_H
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #ifdef HAVE_SYS_TIMES_H
25 #include <sys/time.h>
26 #include <sys/times.h>
27 #elif defined(TPF)
28 #include <time.h>
29 #endif
30
31 #include "ap_config.h"
32 #include "apr_hooks.h"
33 #include "apr_thread_proc.h"
34 #include "apr_portable.h"
35 #include "apr_shm.h"
36
37 /* Scoreboard file, if there is one */
38 #ifndef DEFAULT_SCOREBOARD
39 #define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
40 #endif
41
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.
48  *
49  * Status values:
50  */
51
52 #define SERVER_DEAD 0
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 */
64
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.
73  */
74 typedef int ap_generation_t;
75
76 /* Is the scoreboard shared between processes or not? 
77  * Set by the MPM when the scoreboard is created.
78  */
79 typedef enum {
80     SB_NOT_SHARED = 1,
81     SB_SHARED = 2
82 } ap_scoreboard_e;
83
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. */
87
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;
95
96 struct worker_score {
97     int thread_num;
98 #if APR_HAS_THREADS
99     apr_os_thread_t tid;
100 #endif
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;
110 #ifdef HAVE_TIMES
111     struct tms times;
112 #endif
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? */
117 };
118
119 typedef struct {
120     int             server_limit;
121     int             thread_limit;
122     ap_scoreboard_e sb_type;
123     ap_generation_t running_generation; /* the generation of children which
124                                          * should still be serving requests. */
125     apr_time_t restart_time;
126 } global_score;
127
128 /* stuff which the parent generally writes and the children rarely read */
129 typedef struct process_score process_score;
130 struct process_score{
131     pid_t pid;
132     ap_generation_t generation; /* generation of this child */
133     ap_scoreboard_e sb_type;
134     int quiescing;          /* the process whose pid is stored above is
135                              * going down gracefully
136                              */
137 };
138
139 /* Scoreboard is now in 'local' memory, since it isn't updated once created,
140  * even in forked architectures.  Child created-processes (non-fork) will
141  * set up these indicies into the (possibly relocated) shmem records.
142  */
143 typedef struct {
144     global_score *global;
145     process_score *parent;
146     worker_score **servers;
147 } scoreboard;
148
149 typedef struct ap_sb_handle_t ap_sb_handle_t;
150
151 AP_DECLARE(int) ap_exists_scoreboard_image(void);
152 AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r);
153
154 int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
155 apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached);
156 void ap_init_scoreboard(void *shared_score);
157 AP_DECLARE(int) ap_calc_scoreboard_size(void);
158 apr_status_t ap_cleanup_scoreboard(void *d);
159
160 AP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p,
161                                      int child_num, int thread_num);
162     
163 AP_DECLARE(int) find_child_by_pid(apr_proc_t *pid);
164 AP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status, request_rec *r);
165 AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num, int thread_num,
166                                                     int status, request_rec *r);
167 void ap_time_process_request(ap_sb_handle_t *sbh, int status);
168
169 AP_DECLARE(worker_score *) ap_get_scoreboard_worker(int x, int y);
170 AP_DECLARE(process_score *) ap_get_scoreboard_process(int x);
171 AP_DECLARE(global_score *) ap_get_scoreboard_global(void);
172
173 AP_DECLARE_DATA extern scoreboard *ap_scoreboard_image;
174 AP_DECLARE_DATA extern const char *ap_scoreboard_fname;
175 AP_DECLARE_DATA extern int ap_extended_status;
176
177 AP_DECLARE_DATA extern ap_generation_t volatile ap_my_generation;
178
179 /* Hooks */
180 /**
181   * Hook for post scoreboard creation, pre mpm.
182   * @param p       Apache pool to allocate from.
183   * @param sb_type 
184   * @ingroup hooks
185   * @return OK or DECLINE on success; anything else is a error
186   */  
187 AP_DECLARE_HOOK(int, pre_mpm, (apr_pool_t *p, ap_scoreboard_e sb_type))
188
189 /* for time_process_request() in http_main.c */
190 #define START_PREQUEST 1
191 #define STOP_PREQUEST  2
192
193 #ifdef __cplusplus
194 }
195 #endif
196
197 #endif  /* !APACHE_SCOREBOARD_H */