diff options
author | Bill Stoddard <stoddard@apache.org> | 2002-08-28 19:25:56 +0200 |
---|---|---|
committer | Bill Stoddard <stoddard@apache.org> | 2002-08-28 19:25:56 +0200 |
commit | e26e5d617f80ba08ac1c2203ab2bf37615ff2229 (patch) | |
tree | dd7b09325963cf49c25c59db71df3cc173edbb00 /server | |
parent | Updated doco to conform to Pauls changes in mod_cache. (diff) | |
download | apache2-e26e5d617f80ba08ac1c2203ab2bf37615ff2229.tar.xz apache2-e26e5d617f80ba08ac1c2203ab2bf37615ff2229.zip |
Win32: Add ThreadLimit directive to the windows MPM
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96555 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'server')
-rw-r--r-- | server/mpm/winnt/mpm.h | 1 | ||||
-rw-r--r-- | server/mpm/winnt/mpm_winnt.c | 89 |
2 files changed, 77 insertions, 13 deletions
diff --git a/server/mpm/winnt/mpm.h b/server/mpm/winnt/mpm.h index 752af27a85..c83c4b62f0 100644 --- a/server/mpm/winnt/mpm.h +++ b/server/mpm/winnt/mpm.h @@ -74,6 +74,7 @@ #define AP_MPM_WANT_SET_SCOREBOARD extern int ap_threads_per_child; +extern int ap_thread_limit; extern server_rec *ap_server_conf; #endif /* APACHE_MPM_H */ diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 9e3e4e3b9a..df94fe2606 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -82,14 +82,21 @@ #include "apr_atomic.h" /* Limit on the threads per process. Clients will be locked out if more than - * this * HARD_SERVER_LIMIT are needed. + * this * server_limit are needed. * * We keep this for one reason it keeps the size of the scoreboard file small * enough that we can read the whole thing without worrying too much about * the overhead. */ -#ifndef HARD_THREAD_LIMIT -#define HARD_THREAD_LIMIT 1920 +#ifndef DEFAULT_THREAD_LIMIT +#define DEFAULT_THREAD_LIMIT 1920 +#endif + +/* Admin can't tune ThreadLimit beyond MAX_THREAD_LIMIT. We want + * some sort of compile-time limit to help catch typos. + */ +#ifndef MAX_THREAD_LIMIT +#define MAX_THREAD_LIMIT 15000 #endif /* Limit on the total --- clients will be locked out if more servers than @@ -126,6 +133,9 @@ static DWORD parent_pid; DWORD my_pid; int ap_threads_per_child = 0; +static int thread_limit = DEFAULT_THREAD_LIMIT; +static int first_thread_limit = 0; +static int changed_limit_at_restart; /* ap_my_generation are used by the scoreboard code */ ap_generation_t volatile ap_my_generation=0; @@ -179,16 +189,17 @@ static const char *set_threads_per_child (cmd_parms *cmd, void *dummy, char *arg } ap_threads_per_child = atoi(arg); - if (ap_threads_per_child > HARD_THREAD_LIMIT) { + if (ap_threads_per_child > thread_limit) { ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, - "WARNING: ThreadsPerChild of %d exceeds compile time" - " limit of %d threads,", ap_threads_per_child, - HARD_THREAD_LIMIT); + "WARNING: ThreadsPerChild of %d exceeds ThreadLimit " + "value of %d threads,", ap_threads_per_child, + thread_limit); ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, " lowering ThreadsPerChild to %d. To increase, please" - " see the HARD_THREAD_LIMIT define in %s.", - HARD_THREAD_LIMIT, AP_MPM_HARD_LIMITS_FILE); - ap_threads_per_child = HARD_THREAD_LIMIT; + " see the", thread_limit); + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, + " ThreadLimit directive."); + ap_threads_per_child = thread_limit; } else if (ap_threads_per_child < 1) { ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, @@ -197,11 +208,52 @@ static const char *set_threads_per_child (cmd_parms *cmd, void *dummy, char *arg } return NULL; } +static const char *set_thread_limit (cmd_parms *cmd, void *dummy, const char *arg) +{ + int tmp_thread_limit; + + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); + if (err != NULL) { + return err; + } + + tmp_thread_limit = atoi(arg); + /* you cannot change ThreadLimit across a restart; ignore + * any such attempts + */ + if (first_thread_limit && + tmp_thread_limit != thread_limit) { + /* how do we log a message? the error log is a bit bucket at this + * point; we'll just have to set a flag so that ap_mpm_run() + * logs a warning later + */ + changed_limit_at_restart = 1; + return NULL; + } + thread_limit = tmp_thread_limit; + + if (thread_limit > MAX_THREAD_LIMIT) { + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, + "WARNING: ThreadLimit of %d exceeds compile time limit " + "of %d threads,", thread_limit, MAX_THREAD_LIMIT); + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, + " lowering ThreadLimit to %d.", MAX_THREAD_LIMIT); + thread_limit = MAX_THREAD_LIMIT; + } + else if (thread_limit < 1) { + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, + "WARNING: Require ThreadLimit > 0, setting to 1"); + thread_limit = 1; + } + return NULL; +} static const command_rec winnt_cmds[] = { LISTEN_COMMANDS, -{ "ThreadsPerChild", set_threads_per_child, NULL, RSRC_CONF, TAKE1, - "Number of threads each child creates" }, +AP_INIT_TAKE1("ThreadsPerChild", set_threads_per_child, NULL, RSRC_CONF, + "Number of threads each child creates" ), +AP_INIT_TAKE1("ThreadLimit", set_thread_limit, NULL, RSRC_CONF, + "Maximum worker threads in a server for this run of Apache"), { NULL } }; @@ -1030,7 +1082,7 @@ AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result) *result = HARD_SERVER_LIMIT; return APR_SUCCESS; case AP_MPMQ_HARD_LIMIT_THREADS: - *result = HARD_THREAD_LIMIT; + *result = thread_limit; return APR_SUCCESS; case AP_MPMQ_MAX_THREADS: *result = ap_threads_per_child; @@ -1568,6 +1620,17 @@ AP_DECLARE(int) ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s ) { static int restart = 0; /* Default is "not a restart" */ + if (!restart) { + first_thread_limit = thread_limit; + } + + if (changed_limit_at_restart) { + ap_log_error(APLOG_MARK, APLOG_WARNING, APR_SUCCESS, ap_server_conf, + "WARNING: Attempt to change ThreadLimit ignored " + "during restart"); + changed_limit_at_restart = 0; + } + /* ### If non-graceful restarts are ever introduced - we need to rerun * the pre_mpm hook on subsequent non-graceful restarts. But Win32 * has only graceful style restarts - and we need this hook to act |