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
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.
b686b6a420bde7f78c416b90be11db94cb789979nd * @brief Apache scoreboard library
b686b6a420bde7f78c416b90be11db94cb789979ndextern "C" {
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive/* Scoreboard file, if there is one */
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive#define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
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.
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive * Status values:
1422a46130adacd1ee80183aaddffc8e65f64996covener#define SERVER_READY 2 /* Waiting for connection (or accept() lock) */
1422a46130adacd1ee80183aaddffc8e65f64996covener#define SERVER_BUSY_WRITE 4 /* Processing a client request */
8c150dd80c97896ccf1db42d19b8efca2602232bcovener#define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */
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 */
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/* Is the scoreboard shared between processes or not?
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * Set by the MPM when the scoreboard is created.
1f1b6bf13313fdd14a45e52e553d3ff28689b717coartypedef enum {
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar/* stuff which is worker specific */
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 unsigned char status;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar unsigned long access_count;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar unsigned long my_access_count;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar unsigned short conn_count;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar char vhost[32]; /* What virtual host is being accessed? */
1f1b6bf13313fdd14a45e52e553d3ff28689b717coartypedef struct {
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar ap_generation_t running_generation; /* the generation of children which
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * should still be serving requests.
b686b6a420bde7f78c416b90be11db94cb789979nd/* stuff which the parent generally writes and the children rarely read */
b686b6a420bde7f78c416b90be11db94cb789979nd ap_generation_t generation; /* generation of this child */
b686b6a420bde7f78c416b90be11db94cb789979nd int quiescing; /* the process whose pid is stored above is
b686b6a420bde7f78c416b90be11db94cb789979nd * going down gracefully
06ba4a61654b3763ad65f52283832ebf058fdf1cslive/* stuff which is lb specific */
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive /* TODO: make a real stuct from this */
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.
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slivetypedef struct {
b686b6a420bde7f78c416b90be11db94cb789979ndAP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r);
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);
b686b6a420bde7f78c416b90be11db94cb789979ndAP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p,
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,
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slivevoid ap_time_process_request(ap_sb_handle_t *sbh, int status);
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);
06ba4a61654b3763ad65f52283832ebf058fdf1csliveAP_DECLARE_DATA extern scoreboard *ap_scoreboard_image;
06ba4a61654b3763ad65f52283832ebf058fdf1csliveAP_DECLARE_DATA extern const char *ap_scoreboard_fname;
e55e60efce8a3e2139132c1d6ad9f6f0d2976614ndAP_DECLARE_DATA extern ap_generation_t volatile ap_my_generation;
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
06ba4a61654b3763ad65f52283832ebf058fdf1csliveAP_DECLARE_HOOK(int, pre_mpm, (apr_pool_t *p, ap_scoreboard_e sb_type))
4aa603e6448b99f9371397d439795c91a93637eand * proxy load balancer
17ade6df5ec233536985eb1c130a906c725dd614humbedooh * @return the number of load balancer workers.
4aa603e6448b99f9371397d439795c91a93637eand/* for time_process_request() in http_main.c */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive#endif /* !APACHE_SCOREBOARD_H */