Forgot to attach the patch for the overload feature. It is attached now.
*** mod_jk.c.1.52       Sun Nov 14 15:00:20 2004
--- mod_jk.c.1.52.overload      Sun Nov 14 15:18:59 2004
***************
*** 38,43 ****
--- 38,46 ----
  #include "util_script.h"
  #include "util_date.h"
  #include "http_conf_globals.h"
+ #ifdef OVERLOAD
+ #include "scoreboard.h"
+ #endif /* OVERLOAD */
  
  /*
   * Jakarta (jk_) include files
***************
*** 63,68 ****
--- 66,75 ----
  #define JK_DURATION         ("jakarta.worker.duration")
  #define JK_MAGIC_TYPE       ("application/x-jakarta-servlet")
  #define NULL_FOR_EMPTY(x)   ((x && !strlen(x)) ? NULL : x)
+ #ifdef OVERLOAD
+ #define EMPTY_FOR_NULL(x)   ((x) ? x : "") 
+ #define NEITHER_NULL_NOR_EMPTY(x)   (x && x[0] != '\0')
+ #endif /* OVERLOAD */
  
  /*
   * If you are not using SSL, comment out the following line. It will make
***************
*** 134,139 ****
--- 141,170 ----
      int envvars_in_use;
      table *envvars;
  
+ #ifdef OVERLOAD
+     /*
+      * Configuration object for the mod_overload module. Parameters are
+      *
+      *   overload_uri             URI that triggers load check, e.g. starting
+      *                                 URI for a new application session
+      *   overload_uri_regexp      URI RegExp that triggers load check, e.g. 
starting
+      *                                 URI pattern for a new application 
session
+      *   overload_uri_match       String representation of overload_uri_match
+      *   overload_max_busy_slots  maximum number of busy children allowed
+      *                                 when doing load check
+      *   overload_error_page      URI of the error page shown (or redirected 
to),
+      *                                 if there are too many children busy 
during load check
+      *   overload_is_external     Flag to indicate, that overload redirect 
should
+      *                                 be done externally insted of an 
internal redirect
+      */
+     char *overload_uri;
+     char *overload_uri_match;
+     regex_t *overload_uri_regexp;
+     int  overload_max_busy_slots;
+     char *overload_error_page;
+     int  overload_is_external;
+ #endif /* OVERLOAD */
+ 
      server_rec *s;
  } jk_server_conf_t;
  
***************
*** 1404,1409 ****
--- 1435,1556 ----
      return NULL;
  }
  
+ #ifdef OVERLOAD
+ /* 
+  * JkOverloadURI directive Handling
+  *
+  * Take this config parameter only, if the string is not null and not empty 
+  */
+ static const char *set_overload_uri(cmd_parms *cmd, 
+                                          void *dummy, 
+                                          char *uri)
+ {
+     jk_server_conf_t *conf =
+         (jk_server_conf_t *)ap_get_module_config(cmd->server->module_config, 
+                                                  &jk_module);
+ 
+     if ( NEITHER_NULL_NOR_EMPTY(uri) ) {
+         conf->overload_uri = uri;
+     }
+ 
+     return NULL;
+ }
+ 
+ /* 
+  * JkOverloadURIMatch directive Handling
+  *
+  * Take this config parameter only, if the string is not null and not empty 
+  */
+ static const char *set_overload_uri_match(cmd_parms *cmd, 
+                                               void *dummy, 
+                                               char *uri_match)
+ {
+     jk_server_conf_t *conf =
+         (jk_server_conf_t *)ap_get_module_config(cmd->server->module_config, 
+                                                  &jk_module);
+ 
+     if ( NEITHER_NULL_NOR_EMPTY(uri_match) ) {
+         conf->overload_uri_regexp = ap_pregcomp(cmd->pool, uri_match, 
REG_EXTENDED);
+         if (conf->overload_uri_regexp == NULL) {
+             ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_DEBUG, cmd->server,
+                          "Overload configure: "
+                          "could not compile regexp %s",
+                          uri_match);
+             conf->overload_uri_match = NULL;
+             conf->overload_uri_regexp = NULL;
+         } else {
+             conf->overload_uri_match = uri_match;
+         }
+     }
+ 
+     return NULL;
+ }
+ 
+ /*
+  * JkOverloadMaxBusySlots Directive Handling
+  *
+  * Take this config parameter only, if the string is not null and not empty. 
+  * We just take atoi of the string, so the integer value is the initial 
integer 
+  * in the string 
+  */
+ static const char *set_overload_max_busy_slots(cmd_parms *cmd,  
+                                               void *dummy, 
+                                               char *max_busy_slots)
+ {
+     jk_server_conf_t *conf =
+         (jk_server_conf_t *)ap_get_module_config(cmd->server->module_config, 
+                                                  &jk_module);
+ 
+     if ( NEITHER_NULL_NOR_EMPTY(max_busy_slots) ) {
+         conf->overload_max_busy_slots = atoi(max_busy_slots);
+     }
+ 
+     return NULL;
+ }
+ 
+ /* 
+  * JkOverloadErrorPage Directive Handling
+  *
+  * Take this config parameter only, if the string is not null and not empty.
+  */
+ static const char *set_overload_error_page(cmd_parms *cmd, 
+                                                 void *dummy, 
+                                                 char *error_page)
+ {
+     jk_server_conf_t *conf =
+         (jk_server_conf_t *)ap_get_module_config(cmd->server->module_config, 
+                                                  &jk_module);
+ 
+     if ( NEITHER_NULL_NOR_EMPTY(error_page) ) {
+         conf->overload_error_page = error_page;
+         if (ap_is_url(error_page)) {
+             conf->overload_is_external = JK_TRUE;
+         }
+     }
+ 
+     return NULL;
+ }
+ 
+ /*
+  * JkOverloadIsExternal Directive Handling
+  *
+  * Flag to decide, if the redirect to JkOverloadErrorPage should be done
+  * internaly, or as an external redirect.
+  */
+ static const char *set_overload_is_external(cmd_parms *cmd,  
+                                            void *dummy, 
+                                            int is_external)
+ {
+     jk_server_conf_t *conf =
+         (jk_server_conf_t *)ap_get_module_config(cmd->server->module_config, 
+                                                  &jk_module);
+ 
+     conf->overload_is_external = is_external ? JK_TRUE : JK_FALSE;
+ 
+     return NULL;
+ }
+ #endif /* OVERLOAD */
+ 
  static const command_rec jk_cmds[] = {
      /*
       * JkWorkersFile specifies a full path to the location of the worker 
***************
*** 1504,1509 ****
--- 1651,1672 ----
      {"JkWorkerProperty", jk_set_worker_property, NULL, RSRC_CONF, RAW_ARGS,
       "Set worker.properties directive"},
  
+ #ifdef OVERLOAD 
+     /* 
+      * Configuration file commands for the overload check
+      */
+     {"JkOverloadURI", set_overload_uri, NULL, RSRC_CONF, TAKE1,
+      "URI that trigers a load check"},
+     {"JkOverloadURIMatch", set_overload_uri_match, NULL, RSRC_CONF, TAKE1,
+      "URI RegExp that trigers a load check"},
+     {"JkOverloadMaxBusySlots", set_overload_max_busy_slots, NULL, RSRC_CONF, 
TAKE1,
+      "Number of busy children above which load check triggers overload 
redirect"},
+     {"JkOverloadErrorPage", set_overload_error_page, NULL, RSRC_CONF, TAKE1,
+      "Error page URI for overload redirect during load check"},
+     {"JkOverloadIsExternal", set_overload_is_external, NULL, RSRC_CONF, FLAG,
+      "Overload redirect is done externally instead of internally"},
+ #endif /* OVERLOAD */
+ 
      {NULL}
  };
  
***************
*** 1552,1557 ****
--- 1715,1820 ----
              private_data.read_body_started = JK_FALSE;
              private_data.r = r;
  
+ #ifdef OVERLOAD
+ 
+             int found=0;
+             char *uri = conf->overload_uri;
+             regex_t *uri_regexp = conf->overload_uri_regexp;
+             char *uri_match = conf->overload_uri_match;
+             regmatch_t regm[AP_MAX_REG_MATCH];
+ 
+             if ( NEITHER_NULL_NOR_EMPTY(uri) && !strcmp(r->uri, 
conf->overload_uri) ) {
+                 found=1;
+             } else if ( uri_regexp && !ap_regexec(uri_regexp, r->uri, 
AP_MAX_REG_MATCH, regm, 0) ) {
+                 found=2;
+             }
+ 
+ #ifdef DEBUG   
+             ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_DEBUG, r->server,
+                          "Overload check: "
+                          "comparing '%s' to configured uri '%s' and to uri 
regexp '%s', "
+                          "result is: %d",
+                          r->uri, EMPTY_FOR_NULL(uri), 
EMPTY_FOR_NULL(uri_match), found);
+ #endif
+ 
+             if (  found ) {
+         
+                 int child_index, child_status;
+                 int ready_count = 0;
+                 int busy_count = 0;
+                 short_score score_record;
+         
+                 ap_sync_scoreboard_image();
+                
+                 for (child_index = 0; child_index < HARD_SERVER_LIMIT; 
++child_index) {
+         
+                     score_record = ap_scoreboard_image->servers[child_index];
+                     child_status = score_record.status;
+         
+                     if (child_status == SERVER_READY) {
+                         ready_count++;
+                     } else if (child_status != SERVER_DEAD) {
+                         busy_count++;
+                     }
+                 }
+ #ifdef DEBUG
+                ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_DEBUG, r->server,
+                             "Overload check: "
+                             "scoreboard says %d busy, %d ready (busy limit 
%d).",
+                             busy_count, ready_count, 
conf->overload_max_busy_slots);
+ #endif
+              
+                 if (busy_count>conf->overload_max_busy_slots) {
+                     char *error_page = conf->overload_error_page;
+                     int status = OK;
+                     if ( NEITHER_NULL_NOR_EMPTY(error_page) ) { 
+                         ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 
r->server,
+                                      "Overload warning: "
+                                      "Since %d > %d busy, %s redirecting '%s' 
to '%s'.",
+                                      busy_count, 
conf->overload_max_busy_slots, 
+                                      (conf->overload_is_external == JK_TRUE) 
? "externally" : "internally",
+                                      r->uri, error_page);
+ 
+                         if ( conf->overload_is_external == JK_TRUE ) {
+         
+                             /* redirect (compare e.g. mod_alias, mod_rewrite) 
*/
+ 
+                             status = HTTP_MOVED_TEMPORARILY;
+                             r->status = HTTP_OK; /* make Apache kernel happy 
*/
+ 
+                             if (error_page[0] != '/' && 
!ap_is_url(error_page)) {
+                                 status = HTTP_INTERNAL_SERVER_ERROR;
+                                 ap_log_error(APLOG_MARK, 
APLOG_NOERRNO|APLOG_ERR, r->server,
+                                               "Overload error: "
+                                               "Cannot redirect '%s' to '%s'; "
+                                               "target is not a valid 
absoluteURI or abs_path",
+                                               r->uri, error_page);
+                             } else {
+                                 ap_table_setn(r->headers_out, "Location", 
error_page);
+                             }
+ 
+                         } else {
+ 
+                             /* redirect (compare e.g. mod_cgi::cgi_handler) */
+ 
+                             if (r->method_number!=M_GET) {
+                                 r->method = ap_pstrdup(r->pool, "GET");
+                                 r->method_number = M_GET;
+                             }
+   
+                             ap_table_unset(r->headers_in, "Content-Length");
+ 
+                             ap_internal_redirect(error_page, r);
+ 
+                         }
+ 
+                         return status;
+ 
+                     }
+                 }
+             }
+ #endif /* OVERLOAD */
+ 
              jk_init_ws_service(&s);
  
              /* Update retries for this worker */
***************
*** 1688,1693 ****
--- 1951,1969 ----
  
      c->s = s;
  
+ #ifdef OVERLOAD
+     /*
+      * Default configuration parameters.
+      * The error_page is NULL and must be set in the config file. 
+      */
+     c->overload_uri = NULL;
+     c->overload_uri_regexp = NULL;
+     c->overload_uri_match = NULL;
+     c->overload_max_busy_slots = HARD_SERVER_LIMIT;
+     c->overload_error_page = NULL;
+     c->overload_is_external = JK_FALSE;
+ #endif /* OVERLOAD */
+ 
      return c;
  }
  
***************
*** 1726,1731 ****
--- 2002,2019 ----
  
      overrides->options = base->options;
  
+ #ifdef OVERLOAD
+     /* We mimic the existing code, here, and hope this is right. */
+ /*
+     overrides->overload_uri = base->overload_uri;
+     overrides->overload_uri_regexp = base->overload_uri_regexp;
+     overrides->overload_uri_match = base->overload_uri_match;
+     overrides->overload_max_busy_slots = base->overload_max_busy_slots;
+     overrides->overload_error_page = base->overload_error_page;
+     overrides->overload_is_external = base->overload_is_external;
+ */
+ #endif /* OVERLOAD */
+ 
      if (overrides->mountcopy) {
          copy_jk_map(p, overrides->s, base->uri_to_context,
                      overrides->uri_to_context);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to