Google
 

include/scoreboard.h

Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00022 #ifndef APACHE_SCOREBOARD_H
00023 #define APACHE_SCOREBOARD_H
00024 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 #ifdef HAVE_SYS_TIMES_H
00030 #include <sys/time.h>
00031 #include <sys/times.h>
00032 #elif defined(TPF)
00033 #include <time.h>
00034 #endif
00035 
00036 #include "ap_config.h"
00037 #include "apr_hooks.h"
00038 #include "apr_thread_proc.h"
00039 #include "apr_portable.h"
00040 #include "apr_shm.h"
00041 #include "apr_optional.h"
00042 
00043 /* Scoreboard file, if there is one */
00044 #ifndef DEFAULT_SCOREBOARD
00045 #define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
00046 #endif
00047 
00048 /* Scoreboard info on a process is, for now, kept very brief --- 
00049  * just status value and pid (the latter so that the caretaker process
00050  * can properly update the scoreboard when a process dies).  We may want
00051  * to eventually add a separate set of long_score structures which would
00052  * give, for each process, the number of requests serviced, and info on
00053  * the current, or most recent, request.
00054  *
00055  * Status values:
00056  */
00057 
00058 #define SERVER_DEAD 0
00059 #define SERVER_STARTING 1       /* Server Starting up */
00060 #define SERVER_READY 2          /* Waiting for connection (or accept() lock) */
00061 #define SERVER_BUSY_READ 3      /* Reading a client request */
00062 #define SERVER_BUSY_WRITE 4     /* Processing a client request */
00063 #define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */
00064 #define SERVER_BUSY_LOG 6       /* Logging the request */
00065 #define SERVER_BUSY_DNS 7       /* Looking up a hostname */
00066 #define SERVER_CLOSING 8        /* Closing the connection */
00067 #define SERVER_GRACEFUL 9       /* server is gracefully finishing request */
00068 #define SERVER_IDLE_KILL 10     /* Server is cleaning up idle children. */
00069 #define SERVER_NUM_STATUS 11    /* number of status settings */
00070 
00071 /* Type used for generation indicies.  Startup and every restart cause a
00072  * new generation of children to be spawned.  Children within the same
00073  * generation share the same configuration information -- pointers to stuff
00074  * created at config time in the parent are valid across children.  However,
00075  * this can't work effectively with non-forked architectures.  So while the
00076  * arrays in the scoreboard never change between the parent and forked
00077  * children, so they do not require shm storage, the contents of the shm
00078  * may contain no pointers.
00079  */
00080 typedef int ap_generation_t;
00081 
00082 /* Is the scoreboard shared between processes or not? 
00083  * Set by the MPM when the scoreboard is created.
00084  */
00085 typedef enum {
00086     SB_NOT_SHARED = 1,
00087     SB_SHARED = 2
00088 } ap_scoreboard_e;
00089 
00090 /* stuff which is worker specific */
00091 typedef struct worker_score worker_score;
00092 struct worker_score {
00093     int thread_num;
00094 #if APR_HAS_THREADS
00095     apr_os_thread_t tid;
00096 #endif
00097     /* With some MPMs (e.g., worker), a worker_score can represent
00098      * a thread in a terminating process which is no longer
00099      * represented by the corresponding process_score.  These MPMs
00100      * should set pid and generation fields in the worker_score.
00101      */
00102     pid_t pid;
00103     ap_generation_t generation;
00104     unsigned char status;
00105     unsigned long access_count;
00106     apr_off_t     bytes_served;
00107     unsigned long my_access_count;
00108     apr_off_t     my_bytes_served;
00109     apr_off_t     conn_bytes;
00110     unsigned short conn_count;
00111     apr_time_t start_time;
00112     apr_time_t stop_time;
00113 #ifdef HAVE_TIMES
00114     struct tms times;
00115 #endif
00116     apr_time_t last_used;
00117     char client[32];            /* Keep 'em small... */
00118     char request[64];           /* We just want an idea... */
00119     char vhost[32];             /* What virtual host is being accessed? */
00120 };
00121 
00122 typedef struct {
00123     int             server_limit;
00124     int             thread_limit;
00125     ap_scoreboard_e sb_type;
00126     ap_generation_t running_generation; /* the generation of children which
00127                                          * should still be serving requests.
00128                                          */
00129     apr_time_t restart_time;
00130     int             lb_limit;
00131 } global_score;
00132 
00133 /* stuff which the parent generally writes and the children rarely read */
00134 typedef struct process_score process_score;
00135 struct process_score {
00136     pid_t pid;
00137     ap_generation_t generation; /* generation of this child */
00138     ap_scoreboard_e sb_type;
00139     int quiescing;          /* the process whose pid is stored above is
00140                              * going down gracefully
00141                              */
00142 };
00143 
00144 /* stuff which is lb specific */
00145 typedef struct lb_score lb_score;
00146 struct lb_score {
00147     /* TODO: make a real stuct from this */
00148     unsigned char data[1024];
00149 };
00150 
00151 /* Scoreboard is now in 'local' memory, since it isn't updated once created,
00152  * even in forked architectures.  Child created-processes (non-fork) will
00153  * set up these indicies into the (possibly relocated) shmem records.
00154  */
00155 typedef struct {
00156     global_score *global;
00157     process_score *parent;
00158     worker_score **servers;
00159     lb_score     *balancers;
00160 } scoreboard;
00161 
00162 typedef struct ap_sb_handle_t ap_sb_handle_t;
00163 
00164 AP_DECLARE(int) ap_exists_scoreboard_image(void);
00165 AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r);
00166 
00167 int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
00168 apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached);
00169 void ap_init_scoreboard(void *shared_score);
00170 AP_DECLARE(int) ap_calc_scoreboard_size(void);
00171 apr_status_t ap_cleanup_scoreboard(void *d);
00172 
00173 AP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p,
00174                                      int child_num, int thread_num);
00175     
00176 int find_child_by_pid(apr_proc_t *pid);
00177 AP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status, request_rec *r);
00178 AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num, int thread_num,
00179                                                     int status, request_rec *r);
00180 void ap_time_process_request(ap_sb_handle_t *sbh, int status);
00181 
00182 AP_DECLARE(worker_score *) ap_get_scoreboard_worker(int x, int y);
00183 AP_DECLARE(process_score *) ap_get_scoreboard_process(int x);
00184 AP_DECLARE(global_score *) ap_get_scoreboard_global(void);
00185 AP_DECLARE(lb_score *) ap_get_scoreboard_lb(int lb_num);
00186 
00187 AP_DECLARE_DATA extern scoreboard *ap_scoreboard_image;
00188 AP_DECLARE_DATA extern const char *ap_scoreboard_fname;
00189 AP_DECLARE_DATA extern int ap_extended_status;
00190 
00191 AP_DECLARE_DATA extern ap_generation_t volatile ap_my_generation;
00192 
00193 /* Hooks */
00201 AP_DECLARE_HOOK(int, pre_mpm, (apr_pool_t *p, ap_scoreboard_e sb_type))
00202 
00207 APR_DECLARE_OPTIONAL_FN(int, ap_proxy_lb_workers,
00208                         (void));
00209 
00210 /* for time_process_request() in http_main.c */
00211 #define START_PREQUEST 1
00212 #define STOP_PREQUEST  2
00213 
00214 #ifdef __cplusplus
00215 }
00216 #endif
00217 
00218 #endif  /* !APACHE_SCOREBOARD_H */

Generated on Sun Jul 1 10:07:05 2007 by Doxygen 1.5.2. This rendition of the open source Apache HTTP Server header documentation is not endorsed by or affiliated with the Apache Software Foundation.