scoreboard.h revision b635005244526aa1031cbb2f374ef536aebcbbab
97a9a944b5887e91042b019776c41d5dd74557aferikabele/* Licensed to the Apache Software Foundation (ASF) under one or more
97a9a944b5887e91042b019776c41d5dd74557aferikabele * contributor license agreements. See the NOTICE file distributed with
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * this work for additional information regarding copyright ownership.
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * The ASF licenses this file to You under the Apache License, Version 2.0
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * (the "License"); you may not use this file except in compliance with
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive * the License. You may obtain a copy of the License at
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive *
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive * http://www.apache.org/licenses/LICENSE-2.0
b686b6a420bde7f78c416b90be11db94cb789979nd *
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * Unless required by applicable law or agreed to in writing, software
b686b6a420bde7f78c416b90be11db94cb789979nd * distributed under the License is distributed on an "AS IS" BASIS,
b686b6a420bde7f78c416b90be11db94cb789979nd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
2e545ce2450a9953665f701bb05350f0d3f26275nd * limitations under the License.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen */
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
b686b6a420bde7f78c416b90be11db94cb789979nd/**
b686b6a420bde7f78c416b90be11db94cb789979nd * @file scoreboard.h
b686b6a420bde7f78c416b90be11db94cb789979nd * @brief Apache scoreboard library
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen */
3f08db06526d6901aa08c110b5bc7dde6bc39905nd
b686b6a420bde7f78c416b90be11db94cb789979nd#ifndef APACHE_SCOREBOARD_H
b686b6a420bde7f78c416b90be11db94cb789979nd#define APACHE_SCOREBOARD_H
b686b6a420bde7f78c416b90be11db94cb789979nd
3f08db06526d6901aa08c110b5bc7dde6bc39905nd#ifdef __cplusplus
b686b6a420bde7f78c416b90be11db94cb789979ndextern "C" {
b686b6a420bde7f78c416b90be11db94cb789979nd#endif
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd
9f13a99c8f321eaaddc1253956fbd6d2d9631d14erikabele#ifdef HAVE_SYS_TIMES_H
d33f63cbb2e396bb5b6f5d36465dd9506f76fdf9gryzor#include <sys/time.h>
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0nd#include <sys/times.h>
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung#elif defined(TPF)
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd#include <time.h>
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive#endif
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive#include "ap_config.h"
b686b6a420bde7f78c416b90be11db94cb789979nd#include "apr_hooks.h"
b686b6a420bde7f78c416b90be11db94cb789979nd#include "apr_thread_proc.h"
b686b6a420bde7f78c416b90be11db94cb789979nd#include "apr_portable.h"
b686b6a420bde7f78c416b90be11db94cb789979nd#include "apr_shm.h"
b686b6a420bde7f78c416b90be11db94cb789979nd#include "apr_optional.h"
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive/* Scoreboard file, if there is one */
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive#ifndef DEFAULT_SCOREBOARD
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive#define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive#endif
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive/* Scoreboard info on a process is, for now, kept very brief ---
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive * just status value and pid (the latter so that the caretaker process
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive * can properly update the scoreboard when a process dies). We may want
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive * to eventually add a separate set of long_score structures which would
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive * give, for each process, the number of requests serviced, and info on
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive * the current, or most recent, request.
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf *
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive * Status values:
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive */
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive#define SERVER_DEAD 0
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive#define SERVER_STARTING 1 /* Server Starting up */
1422a46130adacd1ee80183aaddffc8e65f64996covener#define SERVER_READY 2 /* Waiting for connection (or accept() lock) */
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf#define SERVER_BUSY_READ 3 /* Reading a client request */
1422a46130adacd1ee80183aaddffc8e65f64996covener#define SERVER_BUSY_WRITE 4 /* Processing a client request */
8c150dd80c97896ccf1db42d19b8efca2602232bcovener#define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */
b686b6a420bde7f78c416b90be11db94cb789979nd#define SERVER_BUSY_LOG 6 /* Logging the request */
c44eeebd065e2c8cd028016b45c58afb480aaf8fdruggeri#define SERVER_BUSY_DNS 7 /* Looking up a hostname */
c44eeebd065e2c8cd028016b45c58afb480aaf8fdruggeri#define SERVER_CLOSING 8 /* Closing the connection */
c44eeebd065e2c8cd028016b45c58afb480aaf8fdruggeri#define SERVER_GRACEFUL 9 /* server is gracefully finishing request */
c44eeebd065e2c8cd028016b45c58afb480aaf8fdruggeri#define SERVER_IDLE_KILL 10 /* Server is cleaning up idle children. */
b686b6a420bde7f78c416b90be11db94cb789979nd#define SERVER_NUM_STATUS 11 /* number of status settings */
b686b6a420bde7f78c416b90be11db94cb789979nd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd/* Type used for generation indicies. Startup and every restart cause a
117c1f888a14e73cdd821dc6c23eb0411144a41cnd * new generation of children to be spawned. Children within the same
b686b6a420bde7f78c416b90be11db94cb789979nd * generation share the same configuration information -- pointers to stuff
c44eeebd065e2c8cd028016b45c58afb480aaf8fdruggeri * created at config time in the parent are valid across children. However,
b686b6a420bde7f78c416b90be11db94cb789979nd * this can't work effectively with non-forked architectures. So while the
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * arrays in the scoreboard never change between the parent and forked
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * children, so they do not require shm storage, the contents of the shm
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * may contain no pointers.
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar */
1f1b6bf13313fdd14a45e52e553d3ff28689b717coartypedef int ap_generation_t;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar/* Is the scoreboard shared between processes or not?
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * Set by the MPM when the scoreboard is created.
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar */
1f1b6bf13313fdd14a45e52e553d3ff28689b717coartypedef enum {
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar SB_NOT_SHARED = 1,
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar SB_SHARED = 2
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar} ap_scoreboard_e;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar/* stuff which is worker specific */
1f1b6bf13313fdd14a45e52e553d3ff28689b717coartypedef struct worker_score worker_score;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coarstruct worker_score {
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar int thread_num;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar#if APR_HAS_THREADS
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar apr_os_thread_t tid;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar#endif
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar /* With some MPMs (e.g., worker), a worker_score can represent
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * a thread in a terminating process which is no longer
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * represented by the corresponding process_score. These MPMs
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * should set pid and generation fields in the worker_score.
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar */
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar pid_t pid;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar ap_generation_t generation;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar unsigned char status;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar unsigned long access_count;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar apr_off_t bytes_served;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar unsigned long my_access_count;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar apr_off_t my_bytes_served;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar apr_off_t conn_bytes;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar unsigned short conn_count;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar apr_time_t start_time;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar apr_time_t stop_time;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar#ifdef HAVE_TIMES
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar struct tms times;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar#endif
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar apr_time_t last_used;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar char client[32]; /* Keep 'em small... */
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar char request[64]; /* We just want an idea... */
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar char vhost[32]; /* What virtual host is being accessed? */
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar};
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar
1f1b6bf13313fdd14a45e52e553d3ff28689b717coartypedef struct {
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar int server_limit;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar int thread_limit;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar ap_scoreboard_e sb_type;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar ap_generation_t running_generation; /* the generation of children which
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * should still be serving requests.
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar */
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar apr_time_t restart_time;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar int lb_limit;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar} global_score;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar
b686b6a420bde7f78c416b90be11db94cb789979nd/* stuff which the parent generally writes and the children rarely read */
b686b6a420bde7f78c416b90be11db94cb789979ndtypedef struct process_score process_score;
627c978514c54179736d152923478be7c8707f9bndstruct process_score {
b686b6a420bde7f78c416b90be11db94cb789979nd pid_t pid;
b686b6a420bde7f78c416b90be11db94cb789979nd ap_generation_t generation; /* generation of this child */
6d20aeba2c4aa0938bc6e0659d13adc7670ff421poirier ap_scoreboard_e sb_type;
b686b6a420bde7f78c416b90be11db94cb789979nd int quiescing; /* the process whose pid is stored above is
b686b6a420bde7f78c416b90be11db94cb789979nd * going down gracefully
b686b6a420bde7f78c416b90be11db94cb789979nd */
b686b6a420bde7f78c416b90be11db94cb789979nd};
b686b6a420bde7f78c416b90be11db94cb789979nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive/* stuff which is lb specific */
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slivetypedef struct lb_score lb_score;
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slivestruct lb_score {
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive /* TODO: make a real stuct from this */
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive unsigned char data[1024];
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive};
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive/* Scoreboard is now in 'local' memory, since it isn't updated once created,
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive * even in forked architectures. Child created-processes (non-fork) will
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive * set up these indicies into the (possibly relocated) shmem records.
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive */
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slivetypedef struct {
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive global_score *global;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive process_score *parent;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive worker_score **servers;
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive lb_score *balancers;
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive} scoreboard;
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slivetypedef struct ap_sb_handle_t ap_sb_handle_t;
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive
b686b6a420bde7f78c416b90be11db94cb789979ndAP_DECLARE(int) ap_exists_scoreboard_image(void);
b686b6a420bde7f78c416b90be11db94cb789979ndAP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r);
b686b6a420bde7f78c416b90be11db94cb789979nd
b686b6a420bde7f78c416b90be11db94cb789979ndint ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
627c978514c54179736d152923478be7c8707f9bndapr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached);
b686b6a420bde7f78c416b90be11db94cb789979ndvoid ap_init_scoreboard(void *shared_score);
b686b6a420bde7f78c416b90be11db94cb789979ndAP_DECLARE(int) ap_calc_scoreboard_size(void);
b686b6a420bde7f78c416b90be11db94cb789979ndapr_status_t ap_cleanup_scoreboard(void *d);
b686b6a420bde7f78c416b90be11db94cb789979nd
b686b6a420bde7f78c416b90be11db94cb789979ndAP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p,
b686b6a420bde7f78c416b90be11db94cb789979nd int child_num, int thread_num);
b686b6a420bde7f78c416b90be11db94cb789979nd
b686b6a420bde7f78c416b90be11db94cb789979ndint find_child_by_pid(apr_proc_t *pid);
06ba4a61654b3763ad65f52283832ebf058fdf1csliveAP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status, request_rec *r);
7f3fdc63be07f2ad39e01a44e68e9324998a5c03sliveAP_DECLARE(int) ap_update_child_status_from_indexes(int child_num, int thread_num,
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive int status, request_rec *r);
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slivevoid ap_time_process_request(ap_sb_handle_t *sbh, int status);
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive
7f3fdc63be07f2ad39e01a44e68e9324998a5c03sliveAP_DECLARE(worker_score *) ap_get_scoreboard_worker(int x, int y);
7f3fdc63be07f2ad39e01a44e68e9324998a5c03sliveAP_DECLARE(process_score *) ap_get_scoreboard_process(int x);
7f3fdc63be07f2ad39e01a44e68e9324998a5c03sliveAP_DECLARE(global_score *) ap_get_scoreboard_global(void);
06ba4a61654b3763ad65f52283832ebf058fdf1csliveAP_DECLARE(lb_score *) ap_get_scoreboard_lb(int lb_num);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveAP_DECLARE_DATA extern scoreboard *ap_scoreboard_image;
06ba4a61654b3763ad65f52283832ebf058fdf1csliveAP_DECLARE_DATA extern const char *ap_scoreboard_fname;
e55e60efce8a3e2139132c1d6ad9f6f0d2976614ndAP_DECLARE_DATA extern int ap_extended_status;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
e55e60efce8a3e2139132c1d6ad9f6f0d2976614ndAP_DECLARE_DATA extern ap_generation_t volatile ap_my_generation;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive/* Hooks */
e55e60efce8a3e2139132c1d6ad9f6f0d2976614nd/**
06ba4a61654b3763ad65f52283832ebf058fdf1cslive * Hook for post scoreboard creation, pre mpm.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive * @param p Apache pool to allocate from.
e55e60efce8a3e2139132c1d6ad9f6f0d2976614nd * @param sb_type
06ba4a61654b3763ad65f52283832ebf058fdf1cslive * @ingroup hooks
06ba4a61654b3763ad65f52283832ebf058fdf1cslive * @return OK or DECLINE on success; anything else is a error
06ba4a61654b3763ad65f52283832ebf058fdf1cslive */
06ba4a61654b3763ad65f52283832ebf058fdf1csliveAP_DECLARE_HOOK(int, pre_mpm, (apr_pool_t *p, ap_scoreboard_e sb_type))
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive/**
4aa603e6448b99f9371397d439795c91a93637eand * proxy load balancer
17ade6df5ec233536985eb1c130a906c725dd614humbedooh * @return the number of load balancer workers.
17ade6df5ec233536985eb1c130a906c725dd614humbedooh */
17ade6df5ec233536985eb1c130a906c725dd614humbedoohAPR_DECLARE_OPTIONAL_FN(int, ap_proxy_lb_workers,
17ade6df5ec233536985eb1c130a906c725dd614humbedooh (void));
17ade6df5ec233536985eb1c130a906c725dd614humbedooh
4aa603e6448b99f9371397d439795c91a93637eand/* for time_process_request() in http_main.c */
e487d6c09669296f94a5190cc34586a98e624a00nd#define START_PREQUEST 1
06ba4a61654b3763ad65f52283832ebf058fdf1cslive#define STOP_PREQUEST 2
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive#ifdef __cplusplus
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
97a9a944b5887e91042b019776c41d5dd74557aferikabele#endif
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive#endif /* !APACHE_SCOREBOARD_H */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive