Apache HTTPD
Classes | Macros | Typedefs | Functions | Variables
worker.c File Reference
#include "apr.h"
#include "apr_portable.h"
#include "apr_strings.h"
#include "apr_file_io.h"
#include "apr_thread_proc.h"
#include "apr_signal.h"
#include "apr_thread_mutex.h"
#include "apr_proc_mutex.h"
#include "apr_poll.h"
#include <stdlib.h>
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_main.h"
#include "http_log.h"
#include "http_config.h"
#include "http_core.h"
#include "http_connection.h"
#include "ap_mpm.h"
#include "mpm_common.h"
#include "ap_listen.h"
#include "scoreboard.h"
#include "mpm_fdqueue.h"
#include "mpm_default.h"
#include "util_mutex.h"
#include "unixd.h"
#include <signal.h>
#include <limits.h>

Go to the source code of this file.

Classes

struct  worker_retained_data
 
struct  worker_child_bucket
 
struct  proc_info
 
struct  thread_starter
 

Macros

#define APR_WANT_STRFUNC
 
#define DEFAULT_SERVER_LIMIT   16
 
#define MAX_SERVER_LIMIT   20000
 
#define DEFAULT_THREAD_LIMIT   64
 
#define MAX_THREAD_LIMIT   20000
 
#define MAX_SPAWN_RATE   (32)
 
#define MPM_CHILD_PID(i)   (ap_scoreboard_image->parent[i].pid)
 
#define ID_FROM_CHILD_THREAD(c, t)   ((c * thread_limit) + t)
 
#define SAFE_ACCEPT(stmt)   (stmt)
 
#define LISTENER_SIGNAL   SIGHUP
 
#define WORKER_SIGNAL   AP_SIG_GRACEFUL
 
#define ST_INIT   0
 
#define ST_GRACEFUL   1
 
#define ST_UNGRACEFUL   2
 

Typedefs

typedef struct worker_retained_data worker_retained_data
 
typedef struct worker_child_bucket worker_child_bucket
 

Functions

static void close_worker_sockets (void)
 
static void wakeup_listener (void)
 
static void signal_threads (int mode)
 
static int worker_query (int query_code, int *result, apr_status_t *rv)
 
static void worker_note_child_killed (int childnum, pid_t pid, ap_generation_t gen)
 
static void worker_note_child_started (int slot, pid_t pid)
 
static void worker_note_child_lost_slot (int slot, pid_t newpid)
 
static const charworker_get_name (void)
 
static void clean_child_exit (int code) __attribute__((noreturn))
 
static void just_die (int sig)
 
static void process_socket (apr_thread_t *thd, apr_pool_t *p, apr_socket_t *sock, int my_child_num, int my_thread_num, apr_bucket_alloc_t *bucket_alloc)
 
static void check_infinite_requests (void)
 
static void unblock_signal (int sig)
 
static void dummy_signal_handler (int sig)
 
static void accept_mutex_error (const char *func, apr_status_t rv, int process_slot)
 
static void *APR_THREAD_FUNC listener_thread (apr_thread_t *thd, void *dummy)
 
static void *APR_THREAD_FUNC worker_thread (apr_thread_t *thd, void *dummy)
 
static int check_signal (int signum)
 
static void create_listener_thread (thread_starter *ts)
 
static void setup_threads_runtime (void)
 
static void *APR_THREAD_FUNC start_threads (apr_thread_t *thd, void *dummy)
 
static void join_workers (apr_thread_t *listener, apr_thread_t **threads, int mode)
 
static void join_start_thread (apr_thread_t *start_thread_id)
 
static void child_main (int child_num_arg, int child_bucket)
 
static int make_child (server_rec *s, int slot, int bucket)
 
static void startup_children (int number_to_start)
 
static void perform_idle_server_maintenance (int child_bucket)
 
static void server_main_loop (int remaining_children_to_start)
 
static int worker_run (apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
 
static int worker_open_logs (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
 
static int worker_pre_config (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
 
static int worker_check_config (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
 
static void worker_hooks (apr_pool_t *p)
 
static const charset_daemons_to_start (cmd_parms *cmd, void *dummy, const char *arg)
 
static const charset_min_spare_threads (cmd_parms *cmd, void *dummy, const char *arg)
 
static const charset_max_spare_threads (cmd_parms *cmd, void *dummy, const char *arg)
 
static const charset_max_workers (cmd_parms *cmd, void *dummy, const char *arg)
 
static const charset_threads_per_child (cmd_parms *cmd, void *dummy, const char *arg)
 
static const charset_server_limit (cmd_parms *cmd, void *dummy, const char *arg)
 
static const charset_thread_limit (cmd_parms *cmd, void *dummy, const char *arg)
 

Variables

static int threads_per_child = 0
 
static int ap_daemons_to_start = 0
 
static int min_spare_threads = 0
 
static int max_spare_threads = 0
 
static int ap_daemons_limit = 0
 
static int max_workers = 0
 
static int server_limit = 0
 
static int thread_limit = 0
 
static int had_healthy_child = 0
 
static volatile int dying = 0
 
static int workers_may_exit = 0
 
static int start_thread_may_exit = 0
 
static int listener_may_exit = 0
 
static int listener_is_wakeable = 0
 
static int requests_this_child
 
static int num_listensocks = 0
 
static int resource_shortage = 0
 
static fd_queue_tworker_queue
 
static fd_queue_info_tworker_queue_info
 
static apr_pollset_tworker_pollset
 
static worker_retained_dataretained
 
static worker_child_bucketall_buckets
 
static worker_child_bucketmy_bucket
 
static int one_process = 0
 
static apr_pool_tpconf
 
static apr_pool_tpchild
 
static apr_pool_tpruntime
 
static pid_t ap_my_pid
 
static pid_t parent_pid
 
static apr_os_thread_tlistener_os_thread
 
static apr_socket_t ** worker_sockets
 
static int terminate_mode = 0
 
static int child_fatal
 
static const command_rec worker_cmds []
 
static int *const aplog_module_index = &( mpm_worker_module.module_index)
 

Macro Definition Documentation

◆ APR_WANT_STRFUNC

#define APR_WANT_STRFUNC

Definition at line 36 of file worker.c.

◆ DEFAULT_SERVER_LIMIT

#define DEFAULT_SERVER_LIMIT   16

Definition at line 87 of file worker.c.

◆ DEFAULT_THREAD_LIMIT

#define DEFAULT_THREAD_LIMIT   64

Definition at line 105 of file worker.c.

◆ ID_FROM_CHILD_THREAD

#define ID_FROM_CHILD_THREAD (   c,
  t 
)    ((c * thread_limit) + t)

Definition at line 201 of file worker.c.

◆ LISTENER_SIGNAL

#define LISTENER_SIGNAL   SIGHUP

Definition at line 243 of file worker.c.

◆ MAX_SERVER_LIMIT

#define MAX_SERVER_LIMIT   20000

Definition at line 94 of file worker.c.

◆ MAX_SPAWN_RATE

#define MAX_SPAWN_RATE   (32)

Definition at line 168 of file worker.c.

◆ MAX_THREAD_LIMIT

#define MAX_THREAD_LIMIT   20000

Definition at line 112 of file worker.c.

◆ MPM_CHILD_PID

#define MPM_CHILD_PID (   i)    (ap_scoreboard_image->parent[i].pid)

Definition at line 182 of file worker.c.

◆ SAFE_ACCEPT

#define SAFE_ACCEPT (   stmt)    (stmt)

Definition at line 234 of file worker.c.

◆ ST_GRACEFUL

#define ST_GRACEFUL   1

Definition at line 306 of file worker.c.

◆ ST_INIT

#define ST_INIT   0

Definition at line 305 of file worker.c.

◆ ST_UNGRACEFUL

#define ST_UNGRACEFUL   2

Definition at line 307 of file worker.c.

◆ WORKER_SIGNAL

#define WORKER_SIGNAL   AP_SIG_GRACEFUL

Definition at line 256 of file worker.c.

Typedef Documentation

◆ worker_child_bucket

◆ worker_retained_data

Function Documentation

◆ accept_mutex_error()

static void accept_mutex_error ( const char func,
apr_status_t  rv,
int  process_slot 
)
static

Definition at line 529 of file worker.c.

◆ check_infinite_requests()

static void check_infinite_requests ( void  )
static

Definition at line 499 of file worker.c.

◆ check_signal()

static int check_signal ( int  signum)
static

Definition at line 835 of file worker.c.

◆ child_main()

static void child_main ( int  child_num_arg,
int  child_bucket 
)
static

Definition at line 1114 of file worker.c.

◆ clean_child_exit()

static void clean_child_exit ( int  code)
static

Definition at line 440 of file worker.c.

◆ close_worker_sockets()

static void close_worker_sockets ( void  )
static

Definition at line 262 of file worker.c.

◆ create_listener_thread()

static void create_listener_thread ( thread_starter ts)
static

Definition at line 845 of file worker.c.

◆ dummy_signal_handler()

static void dummy_signal_handler ( int  sig)
static

Definition at line 522 of file worker.c.

◆ join_start_thread()

static void join_start_thread ( apr_thread_t start_thread_id)
static

Definition at line 1098 of file worker.c.

◆ join_workers()

static void join_workers ( apr_thread_t listener,
apr_thread_t **  threads,
int  mode 
)
static

Definition at line 1035 of file worker.c.

◆ just_die()

static void just_die ( int  sig)
static

Definition at line 458 of file worker.c.

◆ listener_thread()

static void *APR_THREAD_FUNC listener_thread ( apr_thread_t thd,
void *  dummy 
)
static

Definition at line 552 of file worker.c.

◆ make_child()

static int make_child ( server_rec s,
int  slot,
int  bucket 
)
static

Definition at line 1309 of file worker.c.

◆ perform_idle_server_maintenance()

static void perform_idle_server_maintenance ( int  child_bucket)
static

Definition at line 1400 of file worker.c.

◆ process_socket()

static void process_socket ( apr_thread_t thd,
apr_pool_t p,
apr_socket_t sock,
int  my_child_num,
int  my_thread_num,
apr_bucket_alloc_t bucket_alloc 
)
static

Definition at line 477 of file worker.c.

◆ server_main_loop()

static void server_main_loop ( int  remaining_children_to_start)
static

Definition at line 1607 of file worker.c.

◆ set_daemons_to_start()

static const char * set_daemons_to_start ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

< Forbidden in <VirtualHost>

< Forbidden in <Limit>

< Forbidden in <Directory>

< Forbidden in <Location>

< Forbidden in <Files> or <If>

< Forbidden in <Proxy>

Definition at line 2354 of file worker.c.

◆ set_max_spare_threads()

static const char * set_max_spare_threads ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

< Forbidden in <VirtualHost>

< Forbidden in <Limit>

< Forbidden in <Directory>

< Forbidden in <Location>

< Forbidden in <Files> or <If>

< Forbidden in <Proxy>

Definition at line 2378 of file worker.c.

◆ set_max_workers()

static const char * set_max_workers ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

< Forbidden in <VirtualHost>

< Forbidden in <Limit>

< Forbidden in <Directory>

< Forbidden in <Location>

< Forbidden in <Files> or <If>

< Forbidden in <Proxy>

Definition at line 2390 of file worker.c.

◆ set_min_spare_threads()

static const char * set_min_spare_threads ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

< Forbidden in <VirtualHost>

< Forbidden in <Limit>

< Forbidden in <Directory>

< Forbidden in <Location>

< Forbidden in <Files> or <If>

< Forbidden in <Proxy>

Definition at line 2366 of file worker.c.

◆ set_server_limit()

static const char * set_server_limit ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

< Forbidden in <VirtualHost>

< Forbidden in <Limit>

< Forbidden in <Directory>

< Forbidden in <Location>

< Forbidden in <Files> or <If>

< Forbidden in <Proxy>

Definition at line 2418 of file worker.c.

◆ set_thread_limit()

static const char * set_thread_limit ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

< Forbidden in <VirtualHost>

< Forbidden in <Limit>

< Forbidden in <Directory>

< Forbidden in <Location>

< Forbidden in <Files> or <If>

< Forbidden in <Proxy>

Definition at line 2429 of file worker.c.

◆ set_threads_per_child()

static const char * set_threads_per_child ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

< Forbidden in <VirtualHost>

< Forbidden in <Limit>

< Forbidden in <Directory>

< Forbidden in <Location>

< Forbidden in <Files> or <If>

< Forbidden in <Proxy>

Definition at line 2406 of file worker.c.

◆ setup_threads_runtime()

static void setup_threads_runtime ( void  )
static

< Descriptors passed to apr_pollset_add() * are not copied

< Poll operations are interruptable by * apr_pollset_wakeup() or apr_pollcb_wakeup()

< Poll operations are interruptable by * apr_pollset_wakeup() or apr_pollcb_wakeup()

< Can read without blocking

Definition at line 867 of file worker.c.

◆ signal_threads()

static void signal_threads ( int  mode)
static

Definition at line 311 of file worker.c.

◆ start_threads()

static void *APR_THREAD_FUNC start_threads ( apr_thread_t thd,
void *  dummy 
)
static

Definition at line 955 of file worker.c.

◆ startup_children()

static void startup_children ( int  number_to_start)
static

Definition at line 1385 of file worker.c.

◆ unblock_signal()

static void unblock_signal ( int  sig)
static

Definition at line 509 of file worker.c.

◆ wakeup_listener()

static void wakeup_listener ( void  )
static

Definition at line 273 of file worker.c.

◆ worker_check_config()

static int worker_check_config ( apr_pool_t p,
apr_pool_t plog,
apr_pool_t ptemp,
server_rec s 
)
static

< Module has handled this stage.

Definition at line 2120 of file worker.c.

◆ worker_get_name()

static const char * worker_get_name ( void  )
static

Definition at line 433 of file worker.c.

◆ worker_hooks()

static void worker_hooks ( apr_pool_t p)
static

Definition at line 2334 of file worker.c.

◆ worker_note_child_killed()

static void worker_note_child_killed ( int  childnum,
pid_t  pid,
ap_generation_t  gen 
)
static

Definition at line 390 of file worker.c.

◆ worker_note_child_lost_slot()

static void worker_note_child_lost_slot ( int  slot,
pid_t  newpid 
)
static

Definition at line 412 of file worker.c.

◆ worker_note_child_started()

static void worker_note_child_started ( int  slot,
pid_t  pid 
)
static

Definition at line 404 of file worker.c.

◆ worker_open_logs()

static int worker_open_logs ( apr_pool_t p,
apr_pool_t plog,
apr_pool_t ptemp,
server_rec s 
)
static

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

< Module has handled this stage.

Definition at line 1960 of file worker.c.

◆ worker_pre_config()

static int worker_pre_config ( apr_pool_t pconf,
apr_pool_t plog,
apr_pool_t ptemp 
)
static

< Do not detach

< Detach

< Module has handled this stage.

Definition at line 2055 of file worker.c.

◆ worker_query()

static int worker_query ( int  query_code,
int result,
apr_status_t rv 
)
static

< This value specifies that * an MPM is using a static * number of threads or daemons

< This value specifies that * an MPM is using a dynamic * number of threads or daemons

< Module has handled this stage.

Definition at line 337 of file worker.c.

◆ worker_run()

static int worker_run ( apr_pool_t _pconf,
apr_pool_t plog,
server_rec s 
)
static

< Module has handled this stage.

< Module has handled this stage.

< Module has served the response completely * - it's safe to die() with no more output

< Module has served the response completely * - it's safe to die() with no more output

< Module has served the response completely * - it's safe to die() with no more output

< Module has handled this stage.

Definition at line 1748 of file worker.c.

◆ worker_thread()

static void *APR_THREAD_FUNC worker_thread ( apr_thread_t thd,
void *  dummy 
)
static

Definition at line 742 of file worker.c.

Variable Documentation

◆ all_buckets

worker_child_bucket* all_buckets
static

Definition at line 179 of file worker.c.

◆ ap_daemons_limit

int ap_daemons_limit = 0
static

Definition at line 123 of file worker.c.

◆ ap_daemons_to_start

int ap_daemons_to_start = 0
static

Definition at line 120 of file worker.c.

◆ ap_my_pid

pid_t ap_my_pid
static

Definition at line 226 of file worker.c.

◆ aplog_module_index

int* const aplog_module_index = &( mpm_worker_module.module_index)
static

Definition at line 2462 of file worker.c.

◆ child_fatal

int child_fatal
static

Definition at line 467 of file worker.c.

◆ dying

volatile int dying = 0
static

Definition at line 128 of file worker.c.

◆ had_healthy_child

int had_healthy_child = 0
static

Definition at line 127 of file worker.c.

◆ listener_is_wakeable

int listener_is_wakeable = 0
static

Definition at line 132 of file worker.c.

◆ listener_may_exit

int listener_may_exit = 0
static

Definition at line 131 of file worker.c.

◆ listener_os_thread

apr_os_thread_t* listener_os_thread
static

Definition at line 229 of file worker.c.

◆ max_spare_threads

int max_spare_threads = 0
static

Definition at line 122 of file worker.c.

◆ max_workers

int max_workers = 0
static

Definition at line 124 of file worker.c.

◆ min_spare_threads

int min_spare_threads = 0
static

Definition at line 121 of file worker.c.

◆ my_bucket

worker_child_bucket * my_bucket
static

Definition at line 180 of file worker.c.

◆ num_listensocks

int num_listensocks = 0
static

Definition at line 134 of file worker.c.

◆ one_process

int one_process = 0
static

Definition at line 216 of file worker.c.

◆ parent_pid

pid_t parent_pid
static

Definition at line 228 of file worker.c.

◆ pchild

apr_pool_t* pchild
static

Definition at line 223 of file worker.c.

◆ pconf

apr_pool_t* pconf
static

Definition at line 222 of file worker.c.

◆ pruntime

apr_pool_t* pruntime
static

Definition at line 224 of file worker.c.

◆ requests_this_child

int requests_this_child
static

Definition at line 133 of file worker.c.

◆ resource_shortage

int resource_shortage = 0
static

Definition at line 135 of file worker.c.

◆ retained

worker_retained_data* retained
static

Definition at line 172 of file worker.c.

◆ server_limit

int server_limit = 0
static

Definition at line 125 of file worker.c.

◆ start_thread_may_exit

int start_thread_may_exit = 0
static

Definition at line 130 of file worker.c.

◆ terminate_mode

int terminate_mode = 0
static

Definition at line 309 of file worker.c.

◆ thread_limit

int thread_limit = 0
static

Definition at line 126 of file worker.c.

◆ threads_per_child

int threads_per_child = 0
static

Definition at line 119 of file worker.c.

◆ worker_cmds

const command_rec worker_cmds[]
static
Initial value:
= {
{ "ListenBacklog" , ap_set_listenbacklog , NULL , 128 , TAKE1, "Maximum length of the queue of pending connections, as used by listen(2)" }, { "ListenCoresBucketsRatio" , ap_set_listencbratio , NULL , 128 , TAKE1, "Ratio between the number of CPU cores (online) and the number of listeners buckets" }, { "Listen" , ap_set_listener , NULL , 128 , TAKE_ARGV, "A port number or a numeric IP address and a port number, and an optional protocol" }, { "SendBufferSize" , ap_set_send_buffer_size , NULL , 128 , TAKE1, "Send buffer size in bytes" }, { "ReceiveBufferSize" , ap_set_receive_buffer_size , NULL , 128 , TAKE1, "Receive buffer size in bytes" } ,
{ "StartServers" , set_daemons_to_start , NULL , 128 , TAKE1, "Number of child processes launched at server startup" },
{ "MinSpareThreads" , set_min_spare_threads , NULL , 128 , TAKE1, "Minimum number of idle threads, to handle request spikes" },
{ "MaxSpareThreads" , set_max_spare_threads , NULL , 128 , TAKE1, "Maximum number of idle threads" },
{ "MaxRequestWorkers" , set_max_workers , NULL , 128 , TAKE1, "Maximum number of threads alive at the same time" },
{ "MaxClients" , set_max_workers , NULL , 128 , TAKE1, "Deprecated name of MaxRequestWorkers" },
{ "ThreadsPerChild" , set_threads_per_child , NULL , 128 , TAKE1, "Number of threads each child creates" },
{ "ServerLimit" , set_server_limit , NULL , 128 , TAKE1, "Maximum number of child processes for this run of Apache" },
{ "ThreadLimit" , set_thread_limit , NULL , 128 , TAKE1, "Maximum number of worker threads per child process for this run of Apache - Upper limit for ThreadsPerChild" },
{ "GracefulShutdownTimeout" , ap_mpm_set_graceful_shutdown , NULL , 128 , TAKE1, "Maximum time in seconds to wait for child " "processes to complete transactions during shutdown" } ,
{ NULL }
}
@ TAKE1
Definition http_config.h:51
@ TAKE_ARGV
Definition http_config.h:66
const char * ap_set_listenbacklog(cmd_parms *cmd, void *dummy, const char *arg)
Definition listen.c:901
const char * ap_set_send_buffer_size(cmd_parms *cmd, void *dummy, const char *arg)
Definition listen.c:941
const char * ap_set_listencbratio(cmd_parms *cmd, void *dummy, const char *arg)
Definition listen.c:921
const char * ap_set_listener(cmd_parms *cmd, void *dummy, int argc, char *const argv[])
Definition listen.c:847
const char * ap_set_receive_buffer_size(cmd_parms *cmd, void *dummy, const char *arg)
Definition listen.c:960
const char * ap_mpm_set_graceful_shutdown(cmd_parms *cmd, void *dummy, const char *arg)
Definition mpm_common.c:369
return NULL
Definition mod_so.c:359
static const char * set_max_workers(cmd_parms *cmd, void *dummy, const char *arg)
Definition worker.c:2390
static const char * set_server_limit(cmd_parms *cmd, void *dummy, const char *arg)
Definition worker.c:2418
static const char * set_min_spare_threads(cmd_parms *cmd, void *dummy, const char *arg)
Definition worker.c:2366
static const char * set_thread_limit(cmd_parms *cmd, void *dummy, const char *arg)
Definition worker.c:2429
static const char * set_max_spare_threads(cmd_parms *cmd, void *dummy, const char *arg)
Definition worker.c:2378
static const char * set_threads_per_child(cmd_parms *cmd, void *dummy, const char *arg)
Definition worker.c:2406
static const char * set_daemons_to_start(cmd_parms *cmd, void *dummy, const char *arg)
Definition worker.c:2354

Definition at line 2440 of file worker.c.

◆ worker_pollset

apr_pollset_t* worker_pollset
static

Definition at line 138 of file worker.c.

◆ worker_queue

fd_queue_t* worker_queue
static

Definition at line 136 of file worker.c.

◆ worker_queue_info

fd_queue_info_t* worker_queue_info
static

Definition at line 137 of file worker.c.

◆ worker_sockets

apr_socket_t** worker_sockets
static

Definition at line 260 of file worker.c.

◆ workers_may_exit

int workers_may_exit = 0
static

Definition at line 129 of file worker.c.