scoreboard.h revision dd6c2b6a1c20c2d0fef568e694be8d8cad669c0e
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* ====================================================================
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * The Apache Software License, Version 1.1
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Copyright (c) 2000 The Apache Software Foundation. All rights
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * reserved.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Redistribution and use in source and binary forms, with or without
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * modification, are permitted provided that the following conditions
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * are met:
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen *
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 1. Redistributions of source code must retain the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * 2. Redistributions in binary form must reproduce the above copyright
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * notice, this list of conditions and the following disclaimer in
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen * the documentation and/or other materials provided with the
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * distribution.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * 3. The end-user documentation included with the redistribution,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * if any, must include the following acknowledgment:
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * "This product includes software developed by the
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Apache Software Foundation (http://www.apache.org/)."
9472e4d3c410be3b3f1addbf3b1db1769f64e765nd * Alternately, this acknowledgment may appear in the software itself,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * if and wherever such third-party acknowledgments normally appear.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
1c8f2418892d98febb00a06b9a4f45f8bcfd80a3nd * 4. The names "Apache" and "Apache Software Foundation" must
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * not be used to endorse or promote products derived from this
fac8c35bfb158112226ab43ddf84d59daca5dc30nd * software without prior written permission. For written
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * permission, please contact apache@apache.org.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * 5. Products derived from this software may not be called "Apache",
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * nor may "Apache" appear in their name, without prior written
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * permission of the Apache Software Foundation.
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * SUCH DAMAGE.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * ====================================================================
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * This software consists of voluntary contributions made by many
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * individuals on behalf of the Apache Software Foundation. For more
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * information on the Apache Software Foundation, please see
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * <http://www.apache.org/>.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Portions of this software are based upon public domain software
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * originally written at the National Center for Supercomputing Applications,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * University of Illinois, Urbana-Champaign.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#ifndef APACHE_SCOREBOARD_H
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define APACHE_SCOREBOARD_H
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#ifdef __cplusplus
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndextern "C" {
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#endif
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#ifdef HAVE_SYS_TIMES_H
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#include <sys/time.h>
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#include <sys/times.h>
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#elif defined(TPF)
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#include <time.h>
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#endif
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#include "mpm_default.h" /* For HARD_.*_LIMIT */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#include "apr_thread_proc.h"
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/*The optimized timeout code only works if we're not using a scoreboard file*/
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#if defined(AP_USE_MEM_BASED_SCOREBOARD)
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define OPTIMIZE_TIMEOUTS
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#endif
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* Scoreboard info on a process is, for now, kept very brief ---
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * just status value and pid (the latter so that the caretaker process
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * can properly update the scoreboard when a process dies). We may want
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * to eventually add a separate set of long_score structures which would
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * give, for each process, the number of requests serviced, and info on
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * the current, or most recent, request.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Status values:
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_DEAD 0
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_STARTING 1 /* Server Starting up */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_READY 2 /* Waiting for connection (or accept() lock) */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_BUSY_READ 3 /* Reading a client request */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_BUSY_WRITE 4 /* Processing a client request */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_BUSY_LOG 6 /* Logging the request */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_BUSY_DNS 7 /* Looking up a hostname */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_GRACEFUL 8 /* server is gracefully finishing request */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_ACCEPTING 9 /* thread is accepting connections */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_QUEUEING 10 /* thread is putting connection on the queue */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define SERVER_NUM_STATUS 11 /* number of status settings */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* A "virtual time" is simply a counter that indicates that a child is
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * making progress. The parent checks up on each child, and when they have
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * made progress it resets the last_rtime element. But when the child hasn't
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * made progress in a time that's roughly timeout_len seconds long, it is
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * sent a SIGALRM.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * vtime is an optimization that is used only when the scoreboard is in
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * shared memory (it's not easy/feasible to do it in a scoreboard file).
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * The essential observation is that timeouts rarely occur, the vast majority
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * of hits finish before any timeout happens. So it really sucks to have to
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * ask the operating system to set up and destroy alarms many times during
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * a request.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndtypedef unsigned vtime_t;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* Type used for generation indicies. Startup and every restart cause a
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * new generation of children to be spawned. Children within the same
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * generation share the same configuration information -- pointers to stuff
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * created at config time in the parent are valid across children. For
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * example, the vhostrec pointer in the scoreboard below is valid in all
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * children of the same generation.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * The safe way to access the vhost pointer is like this:
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * short_score *ss = pointer to whichver slot is interesting;
51b60896224b408a35684bd6ec0fafe5e4abe322rbowen * parent_score *ps = pointer to whichver slot is interesting;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * server_rec *vh = ss->vhostrec;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * if (ps->generation != ap_my_generation) {
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * vh = NULL;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * }
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * then if vh is not NULL it's valid in this child.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd *
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * This avoids various race conditions around restarts.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndtypedef int ap_generation_t;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* stuff which is thread/process specific */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndtypedef struct {
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#ifdef OPTIMIZE_TIMEOUTS
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd vtime_t cur_vtime; /* the child's current vtime */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned short timeout_len; /* length of the timeout */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#endif
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd int thread_num;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned char status;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned long access_count;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned long bytes_served;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned long my_access_count;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned long my_bytes_served;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned long conn_bytes;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd unsigned short conn_count;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd apr_time_t start_time;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd apr_time_t stop_time;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#ifdef HAVE_TIMES
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd struct tms times;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#endif
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#ifndef OPTIMIZE_TIMEOUTS
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd time_t last_used;
9472e4d3c410be3b3f1addbf3b1db1769f64e765nd#endif
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd char client[32]; /* Keep 'em small... */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd char request[64]; /* We just want an idea... */
1c8f2418892d98febb00a06b9a4f45f8bcfd80a3nd server_rec *vhostrec; /* What virtual host is being accessed? */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* SEE ABOVE FOR SAFE USAGE! */
fac8c35bfb158112226ab43ddf84d59daca5dc30nd} short_score;
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedoohtypedef struct {
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh ap_generation_t running_generation; /* the generation of children which
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * should still be serving requests. */
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh} global_score;
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh/* stuff which the parent generally writes and the children rarely read */
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedoohtypedef struct {
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh pid_t pid;
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh ap_generation_t generation; /* generation of this child */
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh int worker_threads;
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh#ifdef OPTIMIZE_TIMEOUTS
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh time_t last_rtime; /* time(0) of the last change */
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh vtime_t last_vtime; /* the last vtime the parent has seen */
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh#endif
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh} parent_score;
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh
5effc8b39fae5cd169d17f342bfc265705840014rbowentypedef struct {
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen short_score servers[HARD_SERVER_LIMIT][HARD_THREAD_LIMIT];
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd parent_score parent[HARD_SERVER_LIMIT];
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd global_score global;
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd} scoreboard;
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define KEY_LENGTH 16
#define VALUE_LENGTH 64
typedef struct {
char key[KEY_LENGTH];
char value[VALUE_LENGTH];
} status_table_entry;
#define STATUSES_PER_CONNECTION 10
typedef struct {
status_table_entry
table[HARD_SERVER_LIMIT*HARD_THREAD_LIMIT][STATUSES_PER_CONNECTION];
} new_scoreboard;
#define SCOREBOARD_SIZE sizeof(scoreboard)
#define NEW_SCOREBOARD_SIZE sizeof(new_scoreboard)
#ifdef TPF
#define SCOREBOARD_NAME "SCOREBRD"
#define SCOREBOARD_FRAMES SCOREBOARD_SIZE/4095 + 1
#endif
AP_DECLARE(int) ap_exists_scoreboard_image(void);
void reinit_scoreboard(apr_pool_t *p);
apr_status_t ap_cleanup_shared_mem(void *d);
AP_DECLARE(void) reopen_scoreboard(apr_pool_t *p);
apr_inline void ap_sync_scoreboard_image(void);
void increment_counts(int child_num, int thread_num, request_rec *r);
void update_scoreboard_global(void);
AP_DECLARE(int) find_child_by_pid(apr_proc_t *pid);
int ap_update_child_status(int child_num, int thread_num, int status, request_rec *r);
void ap_time_process_request(int child_num, int thread_num, int status);
AP_DECLARE_DATA extern scoreboard *ap_scoreboard_image;
AP_DECLARE_DATA extern const char *ap_scoreboard_fname;
AP_DECLARE_DATA extern int ap_extended_status;
AP_DECLARE_DATA apr_time_t ap_restart_time;
AP_DECLARE_DATA extern ap_generation_t volatile ap_my_generation;
/* for time_process_request() in http_main.c */
#define START_PREQUEST 1
#define STOP_PREQUEST 2
#ifdef __cplusplus
}
#endif
#endif /* !APACHE_SCOREBOARD_H */