Main Page | Modules | Namespace List | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

scoreboard.h File Reference

Apache scoreboard library. More...

#include "ap_config.h"
#include "apr_hooks.h"
#include "apr_thread_proc.h"
#include "apr_portable.h"
#include "apr_shm.h"
#include "apr_optional.h"

Go to the source code of this file.

Classes

struct  worker_score
struct  global_score
struct  process_score
struct  lb_score
struct  scoreboard

Defines

#define DEFAULT_SCOREBOARD   "logs/apache_runtime_status"
#define SERVER_DEAD   0
#define SERVER_STARTING   1
#define SERVER_READY   2
#define SERVER_BUSY_READ   3
#define SERVER_BUSY_WRITE   4
#define SERVER_BUSY_KEEPALIVE   5
#define SERVER_BUSY_LOG   6
#define SERVER_BUSY_DNS   7
#define SERVER_CLOSING   8
#define SERVER_GRACEFUL   9
#define SERVER_IDLE_KILL   10
#define SERVER_NUM_STATUS   11
#define SB_WORKING   0
#define SB_IDLE_DIE   1
#define START_PREQUEST   1
#define STOP_PREQUEST   2

Typedefs

typedef int ap_generation_t
typedef worker_score worker_score
typedef process_score process_score
typedef lb_score lb_score
typedef ap_sb_handle_t ap_sb_handle_t

Enumerations

enum  ap_scoreboard_e { SB_NOT_SHARED = 1, SB_SHARED = 2 }

Functions

 AP_DECLARE (int) ap_exists_scoreboard_image(void)
int ap_create_scoreboard (apr_pool_t *p, ap_scoreboard_e t)
apr_status_t ap_reopen_scoreboard (apr_pool_t *p, apr_shm_t **shm, int detached)
void ap_init_scoreboard (void *shared_score)
apr_status_t ap_cleanup_scoreboard (void *d)
int find_child_by_pid (apr_proc_t *pid)
void ap_time_process_request (ap_sb_handle_t *sbh, int status)
 AP_DECLARE_HOOK (int, pre_mpm,(apr_pool_t *p, ap_scoreboard_e sb_type)) APR_DECLARE_OPTIONAL_FN(int

Variables

request_recr
apr_pool_tp
apr_pool_t int child_num
apr_pool_t int int thread_num
int status
int y
AP_DECLARE_DATA scoreboardap_scoreboard_image
AP_DECLARE_DATA const char * ap_scoreboard_fname
AP_DECLARE_DATA int ap_extended_status
AP_DECLARE_DATA int ap_mod_status_reqtail
AP_DECLARE_DATA ap_generation_t
volatile 
ap_my_generation
 ap_proxy_lb_workers
 void


Detailed Description

Apache scoreboard library.

Definition in file scoreboard.h.


Define Documentation

#define DEFAULT_SCOREBOARD   "logs/apache_runtime_status"
 

Definition at line 45 of file scoreboard.h.

Referenced by open_scoreboard(), show_compile_settings(), and show_server_settings().

#define SB_IDLE_DIE   1
 

Definition at line 91 of file scoreboard.h.

#define SB_WORKING   0
 

Definition at line 90 of file scoreboard.h.

#define SERVER_BUSY_DNS   7
 

Definition at line 65 of file scoreboard.h.

Referenced by display_settings(), status_handler(), and status_init().

#define SERVER_BUSY_KEEPALIVE   5
 

Definition at line 63 of file scoreboard.h.

Referenced by ap_process_http_connection(), display_settings(), status_handler(), and status_init().

#define SERVER_BUSY_LOG   6
 

Definition at line 64 of file scoreboard.h.

Referenced by ap_process_request(), ap_read_request(), display_settings(), status_handler(), and status_init().

#define SERVER_BUSY_READ   3
 

Definition at line 61 of file scoreboard.h.

Referenced by ap_process_http_async_connection(), ap_process_http_connection(), core_create_conn(), display_settings(), status_handler(), and status_init().

#define SERVER_BUSY_WRITE   4
 

Definition at line 62 of file scoreboard.h.

Referenced by ap_process_http_async_connection(), ap_process_http_connection(), display_settings(), status_handler(), and status_init().

#define SERVER_CLOSING   8
 

Definition at line 66 of file scoreboard.h.

Referenced by AP_DECLARE(), display_settings(), status_handler(), and status_init().

#define SERVER_DEAD   0
 

Definition at line 58 of file scoreboard.h.

Referenced by add_worker(), ap_mpm_child_main(), ap_mpm_run(), clean_child_exit(), display_settings(), make_child(), make_worker(), perform_idle_server_maintenance(), server_main_loop(), start_threads(), startup_children(), status_handler(), status_init(), thread_exception_handler(), worker_main(), and worker_thread().

#define SERVER_GRACEFUL   9
 

Definition at line 67 of file scoreboard.h.

Referenced by ap_mpm_run(), display_settings(), perform_idle_server_maintenance(), start_threads(), status_handler(), status_init(), and worker_thread().

#define SERVER_IDLE_KILL   10
 

Definition at line 68 of file scoreboard.h.

Referenced by display_settings(), status_handler(), and status_init().

#define SERVER_NUM_STATUS   11
 

Definition at line 69 of file scoreboard.h.

Referenced by display_settings().

#define SERVER_READY   2
 

Definition at line 60 of file scoreboard.h.

Referenced by child_main(), display_settings(), perform_idle_server_maintenance(), server_maintenance(), status_handler(), status_init(), worker_main(), and worker_thread().

#define SERVER_STARTING   1
 

Definition at line 59 of file scoreboard.h.

Referenced by add_worker(), display_settings(), make_child(), make_worker(), start_threads(), status_handler(), status_init(), and worker_thread().

#define START_PREQUEST   1
 

Definition at line 222 of file scoreboard.h.

Referenced by ap_process_request(), and ap_time_process_request().

#define STOP_PREQUEST   2
 

Definition at line 223 of file scoreboard.h.

Referenced by ap_process_request(), and ap_time_process_request().


Typedef Documentation

typedef int ap_generation_t
 

Definition at line 80 of file scoreboard.h.

typedef struct ap_sb_handle_t ap_sb_handle_t
 

Definition at line 172 of file scoreboard.h.

typedef struct lb_score lb_score
 

Definition at line 155 of file scoreboard.h.

typedef struct process_score process_score
 

Definition at line 144 of file scoreboard.h.

typedef struct worker_score worker_score
 

Definition at line 100 of file scoreboard.h.


Enumeration Type Documentation

enum ap_scoreboard_e
 

Enumerator:
SB_NOT_SHARED 
SB_SHARED 

Definition at line 85 of file scoreboard.h.

00085              {
00086     SB_NOT_SHARED = 1,
00087     SB_SHARED = 2
00088 } ap_scoreboard_e;


Function Documentation

apr_status_t ap_cleanup_scoreboard void *  d  ) 
 

Definition at line 249 of file scoreboard.c.

References ap_cleanup_shared_mem(), ap_scoreboard_image, APR_SUCCESS, scoreboard::global, NULL, SB_SHARED, and global_score::sb_type.

Referenced by ap_create_scoreboard().

00250 {
00251     if (ap_scoreboard_image == NULL) {
00252         return APR_SUCCESS;
00253     }
00254     if (ap_scoreboard_image->global->sb_type == SB_SHARED) {
00255         ap_cleanup_shared_mem(NULL);
00256     }
00257     else {
00258         free(ap_scoreboard_image->global);
00259         free(ap_scoreboard_image);
00260         ap_scoreboard_image = NULL;
00261     }
00262     return APR_SUCCESS;
00263 }

int ap_create_scoreboard apr_pool_t p,
ap_scoreboard_e  t
 

Definition at line 268 of file scoreboard.c.

References ap_cleanup_scoreboard(), ap_init_scoreboard(), ap_scoreboard_image, APLOG_CRIT, APLOG_MARK, scoreboard::balancers, scoreboard::global, HTTP_INTERNAL_SERVER_ERROR, NULL, OK, open_scoreboard(), scoreboard::parent, global_score::restart_time, global_score::running_generation, SB_SHARED, global_score::sb_type, scoreboard::servers, and strerror().

Referenced by register_hooks().

00269 {
00270     int running_gen = 0;
00271     int i;
00272 #if APR_HAS_SHARED_MEMORY
00273     apr_status_t rv;
00274 #endif
00275 
00276     if (ap_scoreboard_image) {
00277         running_gen = ap_scoreboard_image->global->running_generation;
00278         ap_scoreboard_image->global->restart_time = apr_time_now();
00279         memset(ap_scoreboard_image->parent, 0,
00280                sizeof(process_score) * server_limit);
00281         for (i = 0; i < server_limit; i++) {
00282             memset(ap_scoreboard_image->servers[i], 0,
00283                    sizeof(worker_score) * thread_limit);
00284         }
00285         /* Clean up the lb workers data */
00286         if (lb_limit) {
00287             memset(ap_scoreboard_image->balancers, 0,
00288                    sizeof(lb_score) * lb_limit);
00289         }
00290         return OK;
00291     }
00292 
00293     ap_calc_scoreboard_size();
00294 #if APR_HAS_SHARED_MEMORY
00295     if (sb_type == SB_SHARED) {
00296         void *sb_shared;
00297         rv = open_scoreboard(p);
00298         if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
00299             return HTTP_INTERNAL_SERVER_ERROR;
00300         }
00301         memset(sb_shared, 0, scoreboard_size);
00302         ap_init_scoreboard(sb_shared);
00303     }
00304     else
00305 #endif
00306     {
00307         /* A simple malloc will suffice */
00308         void *sb_mem = calloc(1, scoreboard_size);
00309         if (sb_mem == NULL) {
00310             ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL,
00311                          "(%d)%s: cannot allocate scoreboard",
00312                          errno, strerror(errno));
00313             return HTTP_INTERNAL_SERVER_ERROR;
00314         }
00315         ap_init_scoreboard(sb_mem);
00316     }
00317 
00318     ap_scoreboard_image->global->sb_type = sb_type;
00319     ap_scoreboard_image->global->running_generation = running_gen;
00320     ap_scoreboard_image->global->restart_time = apr_time_now();
00321 
00322     apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
00323 
00324     return OK;
00325 }

void ap_init_scoreboard void *  shared_score  ) 
 

Definition at line 114 of file scoreboard.c.

References ap_assert, ap_scoreboard_image, scoreboard::balancers, scoreboard::global, global_score::lb_limit, scoreboard::parent, global_score::server_limit, scoreboard::servers, and global_score::thread_limit.

Referenced by ap_create_scoreboard(), ap_mpm_child_main(), and master_main().

00115 {
00116     char *more_storage;
00117     int i;
00118 
00119     ap_calc_scoreboard_size();
00120     ap_scoreboard_image =
00121         calloc(1, sizeof(scoreboard) + server_limit * sizeof(worker_score *) +
00122                server_limit * lb_limit * sizeof(lb_score *));
00123     more_storage = shared_score;
00124     ap_scoreboard_image->global = (global_score *)more_storage;
00125     more_storage += sizeof(global_score);
00126     ap_scoreboard_image->parent = (process_score *)more_storage;
00127     more_storage += sizeof(process_score) * server_limit;
00128     ap_scoreboard_image->servers =
00129         (worker_score **)((char*)ap_scoreboard_image + sizeof(scoreboard));
00130     for (i = 0; i < server_limit; i++) {
00131         ap_scoreboard_image->servers[i] = (worker_score *)more_storage;
00132         more_storage += thread_limit * sizeof(worker_score);
00133     }
00134     if (lb_limit) {
00135         ap_scoreboard_image->balancers = (lb_score *)more_storage;
00136         more_storage += lb_limit * sizeof(lb_score);
00137     }
00138     ap_assert(more_storage == (char*)shared_score + scoreboard_size);
00139     ap_scoreboard_image->global->server_limit = server_limit;
00140     ap_scoreboard_image->global->thread_limit = thread_limit;
00141     ap_scoreboard_image->global->lb_limit     = lb_limit;
00142 }

apr_status_t ap_reopen_scoreboard apr_pool_t p,
apr_shm_t **  shm,
int  detached
 

Definition at line 228 of file scoreboard.c.

References APLOG_CRIT, APLOG_MARK, APR_EINVAL, APR_SUCCESS, and NULL.

Referenced by child_main().

00229 {
00230 #if APR_HAS_SHARED_MEMORY
00231     if (!detached) {
00232         return APR_SUCCESS;
00233     }
00234     if (apr_shm_size_get(ap_scoreboard_shm) < scoreboard_size) {
00235         ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL,
00236                      "Fatal error: shared scoreboard too small for child!");
00237         apr_shm_detach(ap_scoreboard_shm);
00238         ap_scoreboard_shm = NULL;
00239         return APR_EINVAL;
00240     }
00241     /* everything will be cleared shortly */
00242     if (*shm) {
00243         *shm = ap_scoreboard_shm;
00244     }
00245 #endif
00246     return APR_SUCCESS;
00247 }

void ap_time_process_request ap_sb_handle_t sbh,
int  status
 

Definition at line 478 of file scoreboard.c.

References ap_scoreboard_image, scoreboard::servers, START_PREQUEST, worker_score::start_time, STOP_PREQUEST, and worker_score::stop_time.

Referenced by ap_process_request().

00479 {
00480     worker_score *ws;
00481 
00482     if (sbh->child_num < 0) {
00483         return;
00484     }
00485 
00486     ws = &ap_scoreboard_image->servers[sbh->child_num][sbh->thread_num];
00487 
00488     if (status == START_PREQUEST) {
00489         ws->start_time = apr_time_now();
00490     }
00491     else if (status == STOP_PREQUEST) {
00492         ws->stop_time = apr_time_now();
00493     }
00494 }

int find_child_by_pid apr_proc_t pid  ) 
 

Definition at line 360 of file scoreboard.c.

References AP_MPMQ_MAX_DAEMONS, ap_scoreboard_image, max_daemons_limit, scoreboard::parent, process_score::pid, and apr_proc_t::pid.

Referenced by ap_mpm_run(), and server_main_loop().

00361 {
00362     int i;
00363     int max_daemons_limit;
00364 
00365     ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit);
00366 
00367     for (i = 0; i < max_daemons_limit; ++i) {
00368         if (ap_scoreboard_image->parent[i].pid == pid->pid) {
00369             return i;
00370         }
00371     }
00372 
00373     return -1;
00374 }


Variable Documentation

AP_DECLARE_DATA int ap_extended_status
 

Definition at line 42 of file scoreboard.c.

Referenced by ap_process_http_async_connection(), ap_process_http_connection(), ap_process_request(), APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(), mpmt_os2_pre_config(), netware_pre_config(), prefork_pre_config(), status_handler(), and worker_pre_config().

AP_DECLARE_DATA int ap_mod_status_reqtail
 

Definition at line 43 of file scoreboard.c.

Referenced by copy_request(), and set_reqtail().

AP_DECLARE_DATA ap_generation_t volatile ap_my_generation
 

Definition at line 159 of file beos.c.

Referenced by accept_mutex_off(), accept_mutex_on(), ap_mpm_child_main(), ap_mpm_run(), child_main(), os_fork(), spawn_child(), status_handler(), and worker_thread().

ap_proxy_lb_workers
 

Definition at line 218 of file scoreboard.h.

Referenced by AP_DECLARE(), and register_hooks().

AP_DECLARE_DATA const char* ap_scoreboard_fname
 

Definition at line 41 of file scoreboard.c.

Referenced by ap_mpm_child_main(), ap_mpm_run(), master_main(), and open_scoreboard().

AP_DECLARE_DATA scoreboard* ap_scoreboard_image
 

Definition at line 40 of file scoreboard.c.

Referenced by accept_mutex_off(), accept_mutex_on(), add_worker(), ap_cleanup_scoreboard(), ap_cleanup_shared_mem(), ap_create_scoreboard(), AP_DECLARE(), ap_init_scoreboard(), ap_mpm_child_main(), ap_mpm_run(), ap_time_process_request(), child_main(), clean_child_exit(), display_settings(), find_child_by_pid(), listener_thread(), make_child(), make_worker(), master_main(), os_fork(), perform_idle_server_maintenance(), server_main_loop(), server_maintenance(), spawn_child(), start_threads(), startup_children(), startup_threads(), startup_workers(), status_handler(), thread_exception_handler(), worker_main(), and worker_thread().

apr_pool_t int child_num
 

Definition at line 183 of file scoreboard.h.

Referenced by APR_HOOK_STRUCT().

int int request_rec* r
 

Definition at line 188 of file scoreboard.h.

int int status
 

Definition at line 188 of file scoreboard.h.

int thread_num
 

Definition at line 188 of file scoreboard.h.

Referenced by APR_HOOK_STRUCT().

void
 

Definition at line 218 of file scoreboard.h.

Referenced by alloc_socket(), AP_DECLARE(), ap_mpm_run(), apprentice(), apr_create_nt_pipe(), APR_DECLARE(), apr_wait_for_io_or_timeout(), apr_wastrtoastr(), APU_DECLARE(), callout(), child_main(), clean_child_exit(), core_create_conn(), database_cleanup(), dav_core_is_writable(), dav_dbm_open(), DAV_DECLARE(), DAV_DECLARE_NONSTD(), dav_format_time(), dav_fs_add_locknull_state(), dav_fs_copymove_walker(), dav_fs_copymoveset(), dav_fs_dbm_error(), dav_fs_deleteset(), dav_fs_ensure_state_dir(), dav_fs_get_locknull_members(), dav_fs_insert_all_liveprops(), dav_fs_insert_prop(), dav_fs_is_writable(), dav_fs_save_lock_record(), dav_generic_dbm_new_error(), dav_method_copymove(), dav_method_proppatch(), dav_propdb_apply_rollback(), default_handler(), fsmagic(), get_random_info(), global_mutex_cleanup(), htdbm_make(), init_cache(), isapi_handler(), listener_thread(), magic_process(), main(), make_child(), make_worker(), makroom(), match(), mkrecord(), mprint(), output_results(), pcre_compile(), pcre_study(), prefork_hooks(), prep(), proxy_send_dir_filter(), putpair(), server_main_loop(), ServerSupportFunction(), splpage(), ssl_pphrase_Handle(), terminate_header(), test_withlock(), warrsztoastr(), wmain(), and worker_thread().

int y
 

Definition at line 192 of file scoreboard.h.

Referenced by AP_DECLARE(), find_title(), gen_unique_id(), getword(), pointinpoly(), PROXY_DECLARE(), and ServiceDlgProc().


© sourcejam.com 2005-2008