You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by st...@apache.org on 2002/08/28 19:25:56 UTC

cvs commit: httpd-2.0/server/mpm/winnt mpm.h mpm_winnt.c

stoddard    2002/08/28 10:25:56

  Modified:    .        CHANGES
               server/mpm/winnt mpm.h mpm_winnt.c
  Log:
  Win32: Add ThreadLimit directive to the windows MPM
  
  Revision  Changes    Path
  1.902     +2 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.901
  retrieving revision 1.902
  diff -u -r1.901 -r1.902
  --- CHANGES	27 Aug 2002 19:22:45 -0000	1.901
  +++ CHANGES	28 Aug 2002 17:25:55 -0000	1.902
  @@ -1,4 +1,6 @@
   Changes with Apache 2.0.41
  +  *) Implement ThreadLimit directive in the Windows MPM.
  +     [Bill Stoddard]
   
     *) Remove CacheOn config directive since it is set but never checked.
        No sense wasting cycles on unused code. Besides, the only truly
  
  
  
  1.12      +1 -0      httpd-2.0/server/mpm/winnt/mpm.h
  
  Index: mpm.h
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/mpm/winnt/mpm.h,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- mpm.h	13 Mar 2002 20:48:04 -0000	1.11
  +++ mpm.h	28 Aug 2002 17:25:56 -0000	1.12
  @@ -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 */
  
  
  
  1.294     +76 -13    httpd-2.0/server/mpm/winnt/mpm_winnt.c
  
  Index: mpm_winnt.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/mpm/winnt/mpm_winnt.c,v
  retrieving revision 1.293
  retrieving revision 1.294
  diff -u -r1.293 -r1.294
  --- mpm_winnt.c	31 Jul 2002 06:13:18 -0000	1.293
  +++ mpm_winnt.c	28 Aug 2002 17:25:56 -0000	1.294
  @@ -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 @@
   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 @@
       }
   
       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 @@
       }
       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 @@
               *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 @@
   {
       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