From dev-return-55157-apmail-httpd-dev-archive=httpd.apache.org@httpd.apache.org Thu Oct 26 01:10:06 2006 Return-Path: Delivered-To: apmail-httpd-dev-archive@www.apache.org Received: (qmail 29373 invoked from network); 26 Oct 2006 07:20:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Oct 2006 07:20:41 -0000 Received: (qmail 14586 invoked by uid 500); 24 Oct 2006 19:37:28 -0000 Delivered-To: apmail-httpd-dev-archive@httpd.apache.org Received: (qmail 14527 invoked by uid 500); 24 Oct 2006 19:37:28 -0000 Mailing-List: contact dev-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list dev@httpd.apache.org Received: (qmail 14516 invoked by uid 99); 24 Oct 2006 19:37:28 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Oct 2006 12:37:28 -0700 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=DNS_FROM_RFC_POST X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [64.236.25.90] (HELO cnnimail33.turner.com) (64.236.25.90) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Oct 2006 12:37:14 -0700 Received: from turner.com (10.165.244.17) by cnnimail33.turner.com with ESMTP; 24 Oct 2006 15:36:56 -0400 Received: from [10.188.50.168] (TTS-Unixpcp064421pcs.turner.com [10.188.50.168]) by web.turner.com (Postfix) with ESMTP id 954FAC003B for ; Tue, 24 Oct 2006 15:36:54 -0400 (EDT) Message-ID: <453E6B54.9050702@turner.com> Date: Tue, 24 Oct 2006 15:36:52 -0400 From: Brian Akins User-Agent: Thunderbird 1.5.0.7 (Macintosh/20060909) MIME-Version: 1.0 To: dev@httpd.apache.org Subject: [PATCH] add MaxKeepAliveConns to event mpm Content-Type: multipart/mixed; boundary="------------010307050009040902080001" X-Virus-Checked: Checked by ClamAV on apache.org This is a multi-part message in MIME format. --------------010307050009040902080001 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Allows you to limit number of keepalive connections per child. Patched against 2.2.3 as trunk just seems broken right now. Did some light testing, seems to work. -- Brian Akins Chief Operations Engineer Turner Digital Media Technologies --------------010307050009040902080001 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="event-ma-ka.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="event-ma-ka.diff" --- event.c.orig 2006-10-24 14:32:54.000000000 -0400 +++ event.c 2006-10-24 15:00:04.000000000 -0400 @@ -161,6 +161,8 @@ static fd_queue_info_t *worker_queue_info; static int mpm_state = AP_MPMQ_STARTING; static int sick_child_detected; +static int max_keepalives = 0; /*default is unlimited*/ +static int curr_keepalives = 0; apr_thread_mutex_t *timeout_mutex; APR_RING_HEAD(timeout_head_t, conn_state_t); @@ -658,18 +660,31 @@ */ cs->expiration_time = ap_server_conf->keep_alive_timeout + time_now; apr_thread_mutex_lock(timeout_mutex); - APR_RING_INSERT_TAIL(&timeout_head, cs, conn_state_t, timeout_list); - - pt->status = 0; - /* Add work to pollset. These are always read events */ - rc = apr_pollset_add(event_pollset, &cs->pfd); - - apr_thread_mutex_unlock(timeout_mutex); - - if (rc != APR_SUCCESS) { - ap_log_error(APLOG_MARK, APLOG_ERR, rc, ap_server_conf, - "process_socket: apr_pollset_add failure"); - AP_DEBUG_ASSERT(rc == APR_SUCCESS); + + /* ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf, */ +/* "curr_keepalives = %d", curr_keepalives); */ + + if(max_keepalives && (AP_CONN_KEEPALIVE == cs->c->keepalive) &&(curr_keepalives >= max_keepalives)) { + apr_thread_mutex_unlock(timeout_mutex); + ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf, + "Maximum keepalive connections reached"); + } + else { + curr_keepalives++; + + APR_RING_INSERT_TAIL(&timeout_head, cs, conn_state_t, timeout_list); + + pt->status = 0; + /* Add work to pollset. These are always read events */ + rc = apr_pollset_add(event_pollset, &cs->pfd); + + apr_thread_mutex_unlock(timeout_mutex); + + if (rc != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_ERR, rc, ap_server_conf, + "process_socket: apr_pollset_add failure"); + AP_DEBUG_ASSERT(rc == APR_SUCCESS); + } } } return 0; @@ -928,6 +943,7 @@ apr_thread_mutex_lock(timeout_mutex); APR_RING_REMOVE(cs, timeout_list); + curr_keepalives--; apr_thread_mutex_unlock(timeout_mutex); rc = push2worker(out_pfd, event_pollset); @@ -2256,6 +2272,18 @@ return NULL; } +static const char *set_max_keepalives(cmd_parms * cmd, void *dummy, + const char *arg) +{ + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); + if (err != NULL) { + return err; + } + + max_keepalives = atoi(arg); + return NULL; +} + static const char *set_max_clients(cmd_parms * cmd, void *dummy, const char *arg) { @@ -2436,7 +2464,9 @@ AP_INIT_TAKE1("MaxClients", set_max_clients, NULL, RSRC_CONF, "Maximum number of threads alive at the same time"), AP_INIT_TAKE1("ThreadsPerChild", set_threads_per_child, NULL, RSRC_CONF, - "Number of threads each child creates"), + "Number of threads each child creates"), + AP_INIT_TAKE1("MaxKeepAliveConns", set_max_keepalives, NULL, RSRC_CONF, + "Maximum number of keepalive connections per child"), AP_INIT_TAKE1("ThreadLimit", set_thread_limit, NULL, RSRC_CONF, "Maximum number of worker threads per child process for this " "run of Apache - Upper limit for ThreadsPerChild"), --------------010307050009040902080001--