1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-08 15:02:10 +03:00

The Event MPM.

Designed to minimize Apache's KeepAlive overhead.

This MPM depends on the current APR-trunk for new features added to 
the apr_pollset interface. Currently the underlying operating
system must support KQueue or EPoll.

Status:
  Should work as a drop in replacement for all non-ssl servers.
  SSL Requests that use HTTP 1.1 Pipelining do not currently work.

Testing:
  I have tested it with Linux 2.6, FreeBSD 5.2.1, and OS X 10.3.
  
Originally based on the patch by Greg Ames.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@105919 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Paul Querna
2004-11-20 02:52:36 +00:00
parent f56630d956
commit 34959f29db
14 changed files with 3192 additions and 6 deletions

View File

@@ -139,6 +139,7 @@ AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
#define AP_MPMQ_MAX_REQUESTS_DAEMON 11 /* Max # of requests per daemon */ #define AP_MPMQ_MAX_REQUESTS_DAEMON 11 /* Max # of requests per daemon */
#define AP_MPMQ_MAX_DAEMONS 12 /* Max # of daemons by config */ #define AP_MPMQ_MAX_DAEMONS 12 /* Max # of daemons by config */
#define AP_MPMQ_MPM_STATE 13 /* starting, running, stopping */ #define AP_MPMQ_MPM_STATE 13 /* starting, running, stopping */
#define AP_MPMQ_IS_ASYNC 14 /* MPM can process async connections */
/** /**
* Query a property of the current MPM. * Query a property of the current MPM.

View File

@@ -37,6 +37,7 @@
#include "apr_time.h" #include "apr_time.h"
#include "apr_network_io.h" #include "apr_network_io.h"
#include "apr_buckets.h" #include "apr_buckets.h"
#include "apr_poll.h"
#include "os.h" #include "os.h"
@@ -675,6 +676,8 @@ typedef struct server_rec server_rec;
typedef struct conn_rec conn_rec; typedef struct conn_rec conn_rec;
/** A structure that represents the current request */ /** A structure that represents the current request */
typedef struct request_rec request_rec; typedef struct request_rec request_rec;
/** A structure that represents the status of the current connection */
typedef struct conn_state_t conn_state_t;
/* ### would be nice to not include this from httpd.h ... */ /* ### would be nice to not include this from httpd.h ... */
/* This comes after we have defined the request_rec type */ /* This comes after we have defined the request_rec type */
@@ -1011,6 +1014,26 @@ struct conn_rec {
void *sbh; void *sbh;
/** The bucket allocator to use for all bucket/brigade creations */ /** The bucket allocator to use for all bucket/brigade creations */
struct apr_bucket_alloc_t *bucket_alloc; struct apr_bucket_alloc_t *bucket_alloc;
/** The current state of this connection */
conn_state_t *cs;
/** Is there data pending in the input filters? */
int data_in_input_filters;
};
typedef enum {
CONN_STATE_CHECK_REQUEST_LINE_READABLE,
CONN_STATE_READ_REQUEST_LINE,
CONN_STATE_LINGER,
} conn_state_e;
struct conn_state_t {
APR_RING_ENTRY(conn_state_t) timeout_list;
apr_time_t expiration_time;
conn_state_e state;
conn_rec *c;
apr_pool_t *p;
apr_bucket_alloc_t *bucket_alloc;
apr_pollfd_t pfd;
}; };
/* Per-vhost config... */ /* Per-vhost config... */

View File

@@ -231,6 +231,53 @@ static const char *http_method(const request_rec *r)
static apr_port_t http_port(const request_rec *r) static apr_port_t http_port(const request_rec *r)
{ return DEFAULT_HTTP_PORT; } { return DEFAULT_HTTP_PORT; }
static int ap_process_http_async_connection(conn_rec *c)
{
request_rec *r;
conn_state_t *cs = c->cs;
switch (cs->state) {
case CONN_STATE_READ_REQUEST_LINE:
ap_update_child_status(c->sbh, SERVER_BUSY_READ, NULL);
while ((r = ap_read_request(c)) != NULL) {
c->keepalive = AP_CONN_UNKNOWN;
/* process the request if it was read without error */
ap_update_child_status(c->sbh, SERVER_BUSY_WRITE, r);
if (r->status == HTTP_OK)
ap_process_request(r);
if (ap_extended_status)
ap_increment_counts(c->sbh, r);
if (c->keepalive != AP_CONN_KEEPALIVE || c->aborted) {
cs->state = CONN_STATE_LINGER;
break;
}
else {
cs->state = CONN_STATE_CHECK_REQUEST_LINE_READABLE;
}
apr_pool_destroy(r->pool);
if (ap_graceful_stop_signalled())
break;
if (c->data_in_input_filters) {
continue;
}
break;
}
break;
default:
AP_DEBUG_ASSERT(0);
cs->state = CONN_STATE_LINGER;
}
return OK;
}
static int ap_process_http_connection(conn_rec *c) static int ap_process_http_connection(conn_rec *c)
{ {
request_rec *r; request_rec *r;
@@ -290,8 +337,21 @@ static int http_create_request(request_rec *r)
static void register_hooks(apr_pool_t *p) static void register_hooks(apr_pool_t *p)
{ {
/**
* If we ae using an MPM That Supports Async Connections,
* use a different processing function
*/
int async_mpm = 0;
if(ap_mpm_query(AP_MPMQ_IS_ASYNC, &async_mpm) == APR_SUCCESS
&& async_mpm == 1) {
ap_hook_process_connection(ap_process_http_async_connection,NULL,
NULL,APR_HOOK_REALLY_LAST);
}
else {
ap_hook_process_connection(ap_process_http_connection,NULL,NULL, ap_hook_process_connection(ap_process_http_connection,NULL,NULL,
APR_HOOK_REALLY_LAST); APR_HOOK_REALLY_LAST);
}
ap_hook_map_to_storage(ap_send_http_trace,NULL,NULL,APR_HOOK_MIDDLE); ap_hook_map_to_storage(ap_send_http_trace,NULL,NULL,APR_HOOK_MIDDLE);
ap_hook_http_method(http_method,NULL,NULL,APR_HOOK_REALLY_LAST); ap_hook_http_method(http_method,NULL,NULL,APR_HOOK_REALLY_LAST);
ap_hook_default_port(http_port,NULL,NULL,APR_HOOK_REALLY_LAST); ap_hook_default_port(http_port,NULL,NULL,APR_HOOK_REALLY_LAST);

View File

@@ -205,9 +205,17 @@ static void check_pipeline_flush(request_rec *r)
*/ */
/* ### shouldn't this read from the connection input filters? */ /* ### shouldn't this read from the connection input filters? */
/* ### is zero correct? that means "read one line" */ /* ### is zero correct? that means "read one line" */
if (r->connection->keepalive == AP_CONN_CLOSE || if (r->connection->keepalive != AP_CONN_CLOSE) {
ap_get_brigade(r->input_filters, bb, AP_MODE_EATCRLF, if (ap_get_brigade(r->input_filters, bb, AP_MODE_EATCRLF,
APR_NONBLOCK_READ, 0) != APR_SUCCESS) { APR_NONBLOCK_READ, 0) != APR_SUCCESS) {
c->data_in_input_filters = 0; /* we got APR_EOF or an error */
}
else {
c->data_in_input_filters = 1;
return; /* don't flush */
}
}
apr_bucket *e = apr_bucket_flush_create(c->bucket_alloc); apr_bucket *e = apr_bucket_flush_create(c->bucket_alloc);
/* We just send directly to the connection based filters. At /* We just send directly to the connection based filters. At
@@ -218,7 +226,6 @@ static void check_pipeline_flush(request_rec *r)
*/ */
APR_BRIGADE_INSERT_HEAD(bb, e); APR_BRIGADE_INSERT_HEAD(bb, e);
ap_pass_brigade(r->connection->output_filters, bb); ap_pass_brigade(r->connection->output_filters, bb);
}
} }
void ap_process_request(request_rec *r) void ap_process_request(request_rec *r)

View File

@@ -1,7 +1,7 @@
AC_MSG_CHECKING(which MPM to use) AC_MSG_CHECKING(which MPM to use)
AC_ARG_WITH(mpm, AC_ARG_WITH(mpm,
APACHE_HELP_STRING(--with-mpm=MPM,Choose the process model for Apache to use. APACHE_HELP_STRING(--with-mpm=MPM,Choose the process model for Apache to use.
MPM={beos|worker|prefork|mpmt_os2|perchild|leader|threadpool}),[ MPM={beos|event|worker|prefork|mpmt_os2|perchild|leader|threadpool}),[
APACHE_MPM=$withval APACHE_MPM=$withval
],[ ],[
if test "x$APACHE_MPM" = "x"; then if test "x$APACHE_MPM" = "x"; then
@@ -12,7 +12,7 @@ AC_MSG_RESULT($APACHE_MPM)
apache_cv_mpm=$APACHE_MPM apache_cv_mpm=$APACHE_MPM
if test "$apache_cv_mpm" = "worker" -o "$apache_cv_mpm" = "perchild" -o "$apache_cv_mpm" = "leader" -o "$apache_cv_mpm" = "threadpool" ; then if test "$apache_cv_mpm" = "worker" -o "$apache_cv_mpm" = "event" -o "$apache_cv_mpm" = "perchild" -o "$apache_cv_mpm" = "leader" -o "$apache_cv_mpm" = "threadpool" ; then
APR_CHECK_APR_DEFINE(APR_HAS_THREADS) APR_CHECK_APR_DEFINE(APR_HAS_THREADS)
if test "x$ac_cv_define_APR_HAS_THREADS" = "xno"; then if test "x$ac_cv_define_APR_HAS_THREADS" = "xno"; then
@@ -26,7 +26,7 @@ fi
APACHE_FAST_OUTPUT(server/mpm/Makefile) APACHE_FAST_OUTPUT(server/mpm/Makefile)
MPM_NAME=$apache_cv_mpm MPM_NAME=$apache_cv_mpm
if test "$MPM_NAME" = "leader" -o "$MPM_NAME" = "threadpool" -o "$MPM_NAME" = "perchild"; then if test "$MPM_NAME" = "event" -o "$MPM_NAME" = "leader" -o "$MPM_NAME" = "threadpool" -o "$MPM_NAME" = "perchild"; then
AC_MSG_WARN(You have selected an EXPERIMENTAL MPM. Be warned!) AC_MSG_WARN(You have selected an EXPERIMENTAL MPM. Be warned!)
MPM_SUBDIR_NAME=experimental/$MPM_NAME MPM_SUBDIR_NAME=experimental/$MPM_NAME
else else

View File

@@ -0,0 +1,5 @@
LTLIBRARY_NAME = libevent.la
LTLIBRARY_SOURCES = event.c fdqueue.c pod.c
include $(top_srcdir)/build/ltlib.mk

View File

@@ -0,0 +1,6 @@
dnl ## XXX - Need a more thorough check of the proper flags to use
if test "$MPM_NAME" = "event" ; then
AC_CHECK_FUNCS(pthread_kill)
APACHE_FAST_OUTPUT(server/mpm/$MPM_SUBDIR_NAME/Makefile)
fi

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,418 @@
/* Copyright 2001-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "fdqueue.h"
#include "apr_atomic.h"
typedef struct recycled_pool
{
apr_pool_t *pool;
struct recycled_pool *next;
} recycled_pool;
struct fd_queue_info_t
{
apr_int32_t idlers; /**
* 0 or positive: number of idle worker threads
* negative: number of threads blocked waiting
* for an idle worker
*/
apr_thread_mutex_t *idlers_mutex;
apr_thread_cond_t *wait_for_idler;
int terminated;
int max_idlers;
recycled_pool *recycled_pools;
};
static apr_status_t queue_info_cleanup(void *data_)
{
fd_queue_info_t *qi = data_;
apr_thread_cond_destroy(qi->wait_for_idler);
apr_thread_mutex_destroy(qi->idlers_mutex);
/* Clean up any pools in the recycled list */
for (;;) {
struct recycled_pool *first_pool = qi->recycled_pools;
if (first_pool == NULL) {
break;
}
if (apr_atomic_casptr
((volatile void **) &(qi->recycled_pools), first_pool->next,
first_pool) == first_pool) {
apr_pool_destroy(first_pool->pool);
}
}
return APR_SUCCESS;
}
apr_status_t ap_queue_info_create(fd_queue_info_t ** queue_info,
apr_pool_t * pool, int max_idlers)
{
apr_status_t rv;
fd_queue_info_t *qi;
qi = apr_palloc(pool, sizeof(*qi));
memset(qi, 0, sizeof(*qi));
rv = apr_thread_mutex_create(&qi->idlers_mutex, APR_THREAD_MUTEX_DEFAULT,
pool);
if (rv != APR_SUCCESS) {
return rv;
}
rv = apr_thread_cond_create(&qi->wait_for_idler, pool);
if (rv != APR_SUCCESS) {
return rv;
}
qi->recycled_pools = NULL;
qi->max_idlers = max_idlers;
apr_pool_cleanup_register(pool, qi, queue_info_cleanup,
apr_pool_cleanup_null);
*queue_info = qi;
return APR_SUCCESS;
}
apr_status_t ap_queue_info_set_idle(fd_queue_info_t * queue_info,
apr_pool_t * pool_to_recycle)
{
apr_status_t rv;
int prev_idlers;
ap_push_pool(queue_info, pool_to_recycle);
/* Atomically increment the count of idle workers */
prev_idlers = apr_atomic_inc32(&(queue_info->idlers));
/* If other threads are waiting on a worker, wake one up */
if (prev_idlers < 0) {
rv = apr_thread_mutex_lock(queue_info->idlers_mutex);
if (rv != APR_SUCCESS) {
AP_DEBUG_ASSERT(0);
return rv;
}
rv = apr_thread_cond_signal(queue_info->wait_for_idler);
if (rv != APR_SUCCESS) {
apr_thread_mutex_unlock(queue_info->idlers_mutex);
return rv;
}
rv = apr_thread_mutex_unlock(queue_info->idlers_mutex);
if (rv != APR_SUCCESS) {
return rv;
}
}
return APR_SUCCESS;
}
apr_status_t ap_queue_info_wait_for_idler(fd_queue_info_t * queue_info)
{
apr_status_t rv;
int prev_idlers;
/* Atomically decrement the idle worker count, saving the old value */
prev_idlers = apr_atomic_add32(&(queue_info->idlers), -1);
/* Block if there weren't any idle workers */
if (prev_idlers <= 0) {
rv = apr_thread_mutex_lock(queue_info->idlers_mutex);
if (rv != APR_SUCCESS) {
AP_DEBUG_ASSERT(0);
apr_atomic_inc32(&(queue_info->idlers)); /* back out dec */
return rv;
}
/* Re-check the idle worker count to guard against a
* race condition. Now that we're in the mutex-protected
* region, one of two things may have happened:
* - If the idle worker count is still negative, the
* workers are all still busy, so it's safe to
* block on a condition variable.
* - If the idle worker count is non-negative, then a
* worker has become idle since the first check
* of queue_info->idlers above. It's possible
* that the worker has also signaled the condition
* variable--and if so, the listener missed it
* because it wasn't yet blocked on the condition
* variable. But if the idle worker count is
* now non-negative, it's safe for this function to
* return immediately.
*
* A negative value in queue_info->idlers tells how many
* threads are waiting on an idle worker.
*/
if (queue_info->idlers < 0) {
rv = apr_thread_cond_wait(queue_info->wait_for_idler,
queue_info->idlers_mutex);
if (rv != APR_SUCCESS) {
apr_status_t rv2;
AP_DEBUG_ASSERT(0);
rv2 = apr_thread_mutex_unlock(queue_info->idlers_mutex);
if (rv2 != APR_SUCCESS) {
return rv2;
}
return rv;
}
}
rv = apr_thread_mutex_unlock(queue_info->idlers_mutex);
if (rv != APR_SUCCESS) {
return rv;
}
}
if (queue_info->terminated) {
return APR_EOF;
}
else {
return APR_SUCCESS;
}
}
void ap_push_pool(fd_queue_info_t * queue_info,
apr_pool_t * pool_to_recycle)
{
/* If we have been given a pool to recycle, atomically link
* it into the queue_info's list of recycled pools
*/
if (pool_to_recycle) {
struct recycled_pool *new_recycle;
new_recycle = (struct recycled_pool *) apr_palloc(pool_to_recycle,
sizeof
(*new_recycle));
new_recycle->pool = pool_to_recycle;
for (;;) {
new_recycle->next = queue_info->recycled_pools;
if (apr_atomic_casptr
((volatile void **) &(queue_info->recycled_pools),
new_recycle, new_recycle->next) == new_recycle->next) {
break;
}
}
}
}
void ap_pop_pool(apr_pool_t ** recycled_pool, fd_queue_info_t * queue_info)
{
/* Atomically pop a pool from the recycled list */
/* This function is safe only as long as it is single threaded because
* it reaches into the queue and accesses "next" which can change.
* We are OK today because it is only called from the listener thread.
* cas-based pushes do not have the same limitation - any number can
* happen concurrently with a single cas-based pop.
*/
*recycled_pool = NULL;
/* Atomically pop a pool from the recycled list */
for (;;) {
struct recycled_pool *first_pool = queue_info->recycled_pools;
if (first_pool == NULL) {
break;
}
if (apr_atomic_casptr
((volatile void **) &(queue_info->recycled_pools),
first_pool->next, first_pool) == first_pool) {
*recycled_pool = first_pool->pool;
break;
}
}
}
apr_status_t ap_queue_info_term(fd_queue_info_t * queue_info)
{
apr_status_t rv;
rv = apr_thread_mutex_lock(queue_info->idlers_mutex);
if (rv != APR_SUCCESS) {
return rv;
}
queue_info->terminated = 1;
apr_thread_cond_broadcast(queue_info->wait_for_idler);
return apr_thread_mutex_unlock(queue_info->idlers_mutex);
}
/**
* Detects when the fd_queue_t is full. This utility function is expected
* to be called from within critical sections, and is not threadsafe.
*/
#define ap_queue_full(queue) ((queue)->nelts == (queue)->bounds)
/**
* Detects when the fd_queue_t is empty. This utility function is expected
* to be called from within critical sections, and is not threadsafe.
*/
#define ap_queue_empty(queue) ((queue)->nelts == 0)
/**
* Callback routine that is called to destroy this
* fd_queue_t when its pool is destroyed.
*/
static apr_status_t ap_queue_destroy(void *data)
{
fd_queue_t *queue = data;
/* Ignore errors here, we can't do anything about them anyway.
* XXX: We should at least try to signal an error here, it is
* indicative of a programmer error. -aaron */
apr_thread_cond_destroy(queue->not_empty);
apr_thread_mutex_destroy(queue->one_big_mutex);
return APR_SUCCESS;
}
/**
* Initialize the fd_queue_t.
*/
apr_status_t ap_queue_init(fd_queue_t * queue, int queue_capacity,
apr_pool_t * a)
{
int i;
apr_status_t rv;
if ((rv = apr_thread_mutex_create(&queue->one_big_mutex,
APR_THREAD_MUTEX_DEFAULT,
a)) != APR_SUCCESS) {
return rv;
}
if ((rv = apr_thread_cond_create(&queue->not_empty, a)) != APR_SUCCESS) {
return rv;
}
queue->data = apr_palloc(a, queue_capacity * sizeof(fd_queue_elem_t));
queue->bounds = queue_capacity;
queue->nelts = 0;
/* Set all the sockets in the queue to NULL */
for (i = 0; i < queue_capacity; ++i)
queue->data[i].sd = NULL;
apr_pool_cleanup_register(a, queue, ap_queue_destroy,
apr_pool_cleanup_null);
return APR_SUCCESS;
}
/**
* Push a new socket onto the queue. Blocks if the queue is full. Once
* the push operation has completed, it signals other threads waiting
* in ap_queue_pop() that they may continue consuming sockets.
*/
apr_status_t ap_queue_push(fd_queue_t * queue, apr_socket_t * sd,
conn_state_t * cs, apr_pool_t * p)
{
fd_queue_elem_t *elem;
apr_status_t rv;
if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
return rv;
}
AP_DEBUG_ASSERT(!queue->terminated);
AP_DEBUG_ASSERT(!ap_queue_full(queue));
elem = &queue->data[queue->nelts];
elem->sd = sd;
elem->cs = cs;
elem->p = p;
queue->nelts++;
apr_thread_cond_signal(queue->not_empty);
if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
return rv;
}
return APR_SUCCESS;
}
/**
* Retrieves the next available socket from the queue. If there are no
* sockets available, it will block until one becomes available.
* Once retrieved, the socket is placed into the address specified by
* 'sd'.
*/
apr_status_t ap_queue_pop(fd_queue_t * queue, apr_socket_t ** sd,
conn_state_t ** cs, apr_pool_t ** p)
{
fd_queue_elem_t *elem;
apr_status_t rv;
if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
return rv;
}
/* Keep waiting until we wake up and find that the queue is not empty. */
if (ap_queue_empty(queue)) {
if (!queue->terminated) {
apr_thread_cond_wait(queue->not_empty, queue->one_big_mutex);
}
/* If we wake up and it's still empty, then we were interrupted */
if (ap_queue_empty(queue)) {
rv = apr_thread_mutex_unlock(queue->one_big_mutex);
if (rv != APR_SUCCESS) {
return rv;
}
if (queue->terminated) {
return APR_EOF; /* no more elements ever again */
}
else {
return APR_EINTR;
}
}
}
elem = &queue->data[--queue->nelts];
*sd = elem->sd;
*cs = elem->cs;
*p = elem->p;
#ifdef AP_DEBUG
elem->sd = NULL;
elem->p = NULL;
#endif /* AP_DEBUG */
rv = apr_thread_mutex_unlock(queue->one_big_mutex);
return rv;
}
apr_status_t ap_queue_interrupt_all(fd_queue_t * queue)
{
apr_status_t rv;
if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
return rv;
}
apr_thread_cond_broadcast(queue->not_empty);
return apr_thread_mutex_unlock(queue->one_big_mutex);
}
apr_status_t ap_queue_term(fd_queue_t * queue)
{
apr_status_t rv;
if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
return rv;
}
/* we must hold one_big_mutex when setting this... otherwise,
* we could end up setting it and waking everybody up just after a
* would-be popper checks it but right before they block
*/
queue->terminated = 1;
if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
return rv;
}
return ap_queue_interrupt_all(queue);
}

View File

@@ -0,0 +1,72 @@
/* Copyright 2001-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FDQUEUE_H
#define FDQUEUE_H
#include "httpd.h"
#include <stdlib.h>
#if APR_HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <apr_thread_mutex.h>
#include <apr_thread_cond.h>
#include <sys/types.h>
#if APR_HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include <apr_errno.h>
typedef struct fd_queue_info_t fd_queue_info_t;
apr_status_t ap_queue_info_create(fd_queue_info_t ** queue_info,
apr_pool_t * pool, int max_idlers);
apr_status_t ap_queue_info_set_idle(fd_queue_info_t * queue_info,
apr_pool_t * pool_to_recycle);
apr_status_t ap_queue_info_wait_for_idler(fd_queue_info_t * queue_info);
apr_status_t ap_queue_info_term(fd_queue_info_t * queue_info);
struct fd_queue_elem_t
{
apr_socket_t *sd;
apr_pool_t *p;
conn_state_t *cs;
};
typedef struct fd_queue_elem_t fd_queue_elem_t;
struct fd_queue_t
{
fd_queue_elem_t *data;
int nelts;
int bounds;
apr_thread_mutex_t *one_big_mutex;
apr_thread_cond_t *not_empty;
int terminated;
};
typedef struct fd_queue_t fd_queue_t;
void ap_pop_pool(apr_pool_t ** recycled_pool, fd_queue_info_t * queue_info);
void ap_push_pool(fd_queue_info_t * queue_info,
apr_pool_t * pool_to_recycle);
apr_status_t ap_queue_init(fd_queue_t * queue, int queue_capacity,
apr_pool_t * a);
apr_status_t ap_queue_push(fd_queue_t * queue, apr_socket_t * sd,
conn_state_t * cs, apr_pool_t * p);
apr_status_t ap_queue_pop(fd_queue_t * queue, apr_socket_t ** sd,
conn_state_t ** cs, apr_pool_t ** p);
apr_status_t ap_queue_interrupt_all(fd_queue_t * queue);
apr_status_t ap_queue_term(fd_queue_t * queue);
#endif /* FDQUEUE_H */

View File

@@ -0,0 +1,50 @@
/* Copyright 2001-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "scoreboard.h"
#include "unixd.h"
#ifndef APACHE_MPM_EVENT_H
#define APACHE_MPM_EVENT_H
#define EVENT_MPM
#define MPM_NAME "Event"
#define AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
#define AP_MPM_WANT_WAIT_OR_TIMEOUT
#define AP_MPM_WANT_PROCESS_CHILD_STATUS
#define AP_MPM_WANT_SET_PIDFILE
#define AP_MPM_WANT_SET_SCOREBOARD
#define AP_MPM_WANT_SET_LOCKFILE
#define AP_MPM_WANT_SET_MAX_REQUESTS
#define AP_MPM_WANT_SET_COREDUMPDIR
#define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
#define AP_MPM_WANT_SIGNAL_SERVER
#define AP_MPM_WANT_SET_MAX_MEM_FREE
#define AP_MPM_WANT_SET_STACKSIZE
#define AP_MPM_WANT_FATAL_SIGNAL_HANDLER
#define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK
#define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
#define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0)
#define MPM_ACCEPT_FUNC unixd_accept
extern int ap_threads_per_child;
extern int ap_max_daemons_limit;
extern server_rec *ap_server_conf;
extern char ap_coredump_dir[MAX_STRING_LEN];
#endif /* APACHE_MPM_EVENT_H */

View File

@@ -0,0 +1,68 @@
/* Copyright 2001-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APACHE_MPM_DEFAULT_H
#define APACHE_MPM_DEFAULT_H
/* Number of servers to spawn off by default --- also, if fewer than
* this free when the caretaker checks, it will spawn more.
*/
#ifndef DEFAULT_START_DAEMON
#define DEFAULT_START_DAEMON 3
#endif
/* Maximum number of *free* server processes --- more than this, and
* they will die off.
*/
#ifndef DEFAULT_MAX_FREE_DAEMON
#define DEFAULT_MAX_FREE_DAEMON 10
#endif
/* Minimum --- fewer than this, and more will be created */
#ifndef DEFAULT_MIN_FREE_DAEMON
#define DEFAULT_MIN_FREE_DAEMON 3
#endif
#ifndef DEFAULT_THREADS_PER_CHILD
#define DEFAULT_THREADS_PER_CHILD 25
#endif
/* File used for accept locking, when we use a file */
#ifndef DEFAULT_LOCKFILE
#define DEFAULT_LOCKFILE DEFAULT_REL_RUNTIMEDIR "/accept.lock"
#endif
/* Where the main/parent process's pid is logged */
#ifndef DEFAULT_PIDLOG
#define DEFAULT_PIDLOG DEFAULT_REL_RUNTIMEDIR "/httpd.pid"
#endif
/*
* Interval, in microseconds, between scoreboard maintenance.
*/
#ifndef SCOREBOARD_MAINTENANCE_INTERVAL
#define SCOREBOARD_MAINTENANCE_INTERVAL 1000000
#endif
/* Number of requests to try to handle in a single process. If <= 0,
* the children don't die off.
*/
#ifndef DEFAULT_MAX_REQUESTS_PER_CHILD
#define DEFAULT_MAX_REQUESTS_PER_CHILD 10000
#endif
#endif /* AP_MPM_DEFAULT_H */

View File

@@ -0,0 +1,108 @@
/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "pod.h"
#if APR_HAVE_UNISTD_H
#include <unistd.h>
#endif
AP_DECLARE(apr_status_t) ap_mpm_pod_open(apr_pool_t * p, ap_pod_t ** pod)
{
apr_status_t rv;
*pod = apr_palloc(p, sizeof(**pod));
rv = apr_file_pipe_create(&((*pod)->pod_in), &((*pod)->pod_out), p);
if (rv != APR_SUCCESS) {
return rv;
}
/*
apr_file_pipe_timeout_set((*pod)->pod_in, 0);
*/
(*pod)->p = p;
/* close these before exec. */
apr_file_inherit_unset((*pod)->pod_in);
apr_file_inherit_unset((*pod)->pod_out);
return APR_SUCCESS;
}
AP_DECLARE(int) ap_mpm_pod_check(ap_pod_t * pod)
{
char c;
apr_os_file_t fd;
int rc;
/* we need to surface EINTR so we'll have to grab the
* native file descriptor and do the OS read() ourselves
*/
apr_os_file_get(&fd, pod->pod_in);
rc = read(fd, &c, 1);
if (rc == 1) {
switch (c) {
case RESTART_CHAR:
return AP_RESTART;
case GRACEFUL_CHAR:
return AP_GRACEFUL;
}
}
return AP_NORESTART;
}
AP_DECLARE(apr_status_t) ap_mpm_pod_close(ap_pod_t * pod)
{
apr_status_t rv;
rv = apr_file_close(pod->pod_out);
if (rv != APR_SUCCESS) {
return rv;
}
rv = apr_file_close(pod->pod_in);
if (rv != APR_SUCCESS) {
return rv;
}
return rv;
}
static apr_status_t pod_signal_internal(ap_pod_t * pod, int graceful)
{
apr_status_t rv;
char char_of_death = graceful ? GRACEFUL_CHAR : RESTART_CHAR;
apr_size_t one = 1;
rv = apr_file_write(pod->pod_out, &char_of_death, &one);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf,
"write pipe_of_death");
}
return rv;
}
AP_DECLARE(apr_status_t) ap_mpm_pod_signal(ap_pod_t * pod, int graceful)
{
return pod_signal_internal(pod, graceful);
}
AP_DECLARE(void) ap_mpm_pod_killpg(ap_pod_t * pod, int num, int graceful)
{
int i;
apr_status_t rv = APR_SUCCESS;
for (i = 0; i < num && rv == APR_SUCCESS; i++) {
rv = pod_signal_internal(pod, graceful);
}
}

View File

@@ -0,0 +1,50 @@
/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "apr.h"
#include "apr_strings.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "http_main.h"
#include "mpm.h"
#include "mpm_common.h"
#include "ap_mpm.h"
#include "ap_listen.h"
#include "mpm_default.h"
#define RESTART_CHAR '$'
#define GRACEFUL_CHAR '!'
#define AP_RESTART 0
#define AP_GRACEFUL 1
typedef struct ap_pod_t ap_pod_t;
struct ap_pod_t
{
apr_file_t *pod_in;
apr_file_t *pod_out;
apr_pool_t *p;
};
AP_DECLARE(apr_status_t) ap_mpm_pod_open(apr_pool_t * p, ap_pod_t ** pod);
AP_DECLARE(int) ap_mpm_pod_check(ap_pod_t * pod);
AP_DECLARE(apr_status_t) ap_mpm_pod_close(ap_pod_t * pod);
AP_DECLARE(apr_status_t) ap_mpm_pod_signal(ap_pod_t * pod, int graceful);
AP_DECLARE(void) ap_mpm_pod_killpg(ap_pod_t * pod, int num, int graceful);