tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jk/native2/common jk_worker_lb.c
Date Wed, 02 Oct 2002 15:36:23 GMT
mturk       2002/10/02 08:36:22

  Modified:    jk/native2/common jk_worker_lb.c
  Log:
  Introduced 3 new configuration parameters to the lb.
  1. attempts -- replaces harcoded MAX_ATTEMPTS
  2. recovery -- replaces hardcoded WAIT_BEFORE_RECOVER
  3. timeout -- this one is new.
  The timeout if set will force the lb to cycle through workers if all are in the
  error_state for the specified amount of seconds. This is usefull for
  situations when the TC is overloaded and refuses new connections.
  The lb will wait and after timeout will report 500 to the client.
  
  Revision  Changes    Path
  1.24      +36 -9     jakarta-tomcat-connectors/jk/native2/common/jk_worker_lb.c
  
  Index: jk_worker_lb.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_worker_lb.c,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- jk_worker_lb.c	8 Jul 2002 13:33:38 -0000	1.23
  +++ jk_worker_lb.c	2 Oct 2002 15:36:22 -0000	1.24
  @@ -77,15 +77,20 @@
   #define DEFAULT_LB_FACTOR           (1.0)
   
   /* Time to wait before retry... XXX make it configurable*/
  -#define WAIT_BEFORE_RECOVER (60) 
  +#define WAIT_BEFORE_RECOVER 60 
   
   #define MAX_ATTEMPTS 3
   
   #define NO_WORKER_MSG "The servlet container is temporary unavailable or being upgraded\n";
   
   typedef struct {
  -    struct jk_mutex *cs;
  -    int    initializing;
  +    struct  jk_mutex *cs;
  +    int     initializing;
  +    int     attempts;
  +    int     recovery;
  +    int     timeout;
  +    time_t  error_time;
  +
   } jk_worker_lb_private_t;
   
   /** Find the best worker. In process, check if timeout expired
  @@ -108,6 +113,7 @@
       int currentLevel=JK_LB_LEVELS - 1;
       char *session_route;
       time_t now = 0;
  +    jk_worker_lb_private_t *lb_priv = lb->worker_private;
   
       session_route = jk2_requtil_getSessionRoute(env, s);
          
  @@ -119,7 +125,7 @@
                   if(w->route != NULL &&
                      0 == strcmp(session_route, w->route)) {
                       if(attempt > 0 && w->in_error_state) {
  -                        /* We already tried to revive this worker. */
  +                        /* We already tried to revive this worker. */
                           break;
                       } else {
                           return w;
  @@ -181,7 +187,7 @@
                   /* Check if it's ready for recovery */
                   if( now==0 ) now = time(NULL);
                   
  -                if((now - w->error_time) > WAIT_BEFORE_RECOVER) {
  +                if((now - w->error_time) > lb_priv->recovery) {
                       env->l->jkLog(env, env->l, JK_LOG_ERROR,
                                     "lb.getWorker() reenable %s\n", w->mbean->name);
                       w->in_error_state = JK_FALSE;
  @@ -331,7 +337,18 @@
               rec=jk2_get_most_suitable_worker(env, lb, s, attempt);
   
               if (lb_priv->cs != NULL)
  -                lb_priv->cs->unLock(env, lb_priv->cs);
  +                lb_priv->cs->unLock(env, lb_priv->cs);
  +            if (!rec && lb_priv->timeout) {
  +                time_t now = time(NULL);
  +                if ((int)(now - lb_priv->error_time) < lb_priv->timeout) {
  +#ifdef HAS_APR
  +                    apr_thread_yield();
  +#endif
  +                    continue;
  +                }
  +            }
  +            else
  +                lb_priv->error_time = time(NULL);
           }
           else if (!rec){
               /* If we are initializing the service wait until
  @@ -340,7 +357,7 @@
               if (lb->cs != NULL) {
                   lb->cs->lock(env, lb->cs);
                   lb->cs->unLock(env, lb->cs);
  -            }
  +            }
               continue;
           }
           attempt++;
  @@ -370,6 +387,7 @@
               }
               
               s->afterRequest( env, s);
  +            lb_priv->error_time = time(NULL);
               return JK_ERR;
           }
   
  @@ -502,6 +520,7 @@
       jk_worker_t *lb=mbean->object;
       char *value=valueP;
       unsigned i = 0;
  +    jk_worker_lb_private_t *lb_priv = lb->worker_private;
       
       if( strcmp( name, "worker") == 0 ) {
           if( lb->lbWorkerMap->get( env, lb->lbWorkerMap, name) != NULL ) {
  @@ -523,7 +542,13 @@
           lb->noWorkerCode=atoi( value );
       } else if( strcmp( name, "hwBalanceErr") == 0 ) {
           lb->hwBalanceErr=atoi( value );
  -    }
  +    } else if( strcmp( name, "timeout") == 0 ) {
  +        lb_priv->timeout=atoi( value );
  +    } else if( strcmp( name, "recovery") == 0 ) {
  +        lb_priv->recovery=atoi( value );
  +    } else if( strcmp( name, "attempts") == 0 ) {
  +        lb_priv->attempts=atoi( value );
  +    }
       return JK_ERR;
   }
   
  @@ -594,7 +619,9 @@
       if( jkb != NULL ) {
           worker_private->cs=jkb->object;
           jkb->init(env, jkb );
  -    }
  +    }
  +    worker_private->attempts = MAX_ATTEMPTS;
  +    worker_private->recovery = WAIT_BEFORE_RECOVER;
       w->worker_private = worker_private;
       w->service        = jk2_lb_service;
       
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message