Author: rjung
Date: Fri Oct  3 12:37:13 2008
New Revision: 701507

URL: http://svn.apache.org/viewvc?rev=701507&view=rev
Log:
Add retry_wait for AJP13 workers.
If a request fails, sleep a configurable time
before each following retry.
Remember: this has nothing to do with the lb retries.

Modified:
    tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c
    tomcat/connectors/trunk/jk/native/common/jk_ajp_common.h
    tomcat/connectors/trunk/jk/native/common/jk_util.c
    tomcat/connectors/trunk/jk/native/common/jk_util.h

Modified: tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c?rev=701507&r1=701506&r2=701507&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c Fri Oct  3 
12:37:13 2008
@@ -2097,7 +2097,8 @@
     ajp_worker_t *aw;
     int log_error;
     int rc = JK_UNSET;
-    char *msg;
+    char *msg = "";
+    int retry_wait;
 
     JK_TRACE_ENTER(l);
 
@@ -2200,8 +2201,22 @@
         aw->s->state = JK_AJP_STATE_PROBE;
     if (aw->s->busy > aw->s->max_busy)
         aw->s->max_busy = aw->s->busy;
+    retry_wait = p->worker->retry_wait;
     for (i = 0; i < aw->retries; i++) {
         /*
+         * ajp_send_request() already locally handles
+         * reconnecting and broken connection detection.
+         * So if we already failed in it, wait a bit before
+         * retrying the same backend.
+         */
+        if (i > 0 && retry_wait >= 0) {
+            if (JK_IS_DEBUG_LEVEL(l))
+                jk_log(l, JK_LOG_DEBUG,
+                       "retry %d, sleeping for %d ms before retrying",
+                       i, retry_wait);
+            jk_sleep(retry_wait);
+        }
+        /*
          * We're using op->request which hold initial request
          * if Tomcat is stopped or restarted, we will pass op->request
          * to next valid tomcat.
@@ -2303,9 +2318,6 @@
                 *is_error = JK_HTTP_SERVER_BUSY;
                 msg = "because of response status";
                 rc = err;
-                if (i >= JK_RETRIES) {
-                    jk_sleep(JK_SLEEP_DEF);
-                }
             }
             /* This should only be the cases err == JK_FALSE */
             else {
@@ -2317,10 +2329,6 @@
                 *is_error = JK_HTTP_BAD_GATEWAY;
                 msg = "";
                 rc = JK_FALSE;
-                /* Check for custom retries */
-                if (i >= JK_RETRIES) {
-                    jk_sleep(JK_SLEEP_DEF);
-                }
             }
         }
         else {
@@ -2549,6 +2557,10 @@
         p->socket_buf =
             jk_get_worker_socket_buffer(props, p->name, p->max_packet_size);
 
+        p->retry_wait =
+            jk_get_worker_retry_wait(props, p->name,
+                                     JK_SLEEP_DEF);
+
         p->http_status_fail_num = jk_get_worker_fail_on_status(props, p->name,
                                      &p->http_status_fail[0],
                                      JK_MAX_HTTP_STATUS_FAILS);
@@ -2613,6 +2625,10 @@
             jk_log(l, JK_LOG_DEBUG,
                    "max packet size:  %d",
                     p->max_packet_size);
+
+            jk_log(l, JK_LOG_DEBUG,
+                   "retry wait time:  %d",
+                    p->retry_wait);
         }
         /*
          *  Need to initialize secret here since we could return from inside

Modified: tomcat/connectors/trunk/jk/native/common/jk_ajp_common.h
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_ajp_common.h?rev=701507&r1=701506&r2=701507&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_ajp_common.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_ajp_common.h Fri Oct  3 
12:37:13 2008
@@ -318,12 +318,12 @@
     int connect_timeout;      /* connect cping/cpong delay in ms (0 means 
disabled)  */
     int reply_timeout;        /* reply timeout delay in ms (0 means disabled) 
*/
     int prepost_timeout;      /* before sending a request cping/cpong timeout 
delay in ms (0 means disabled) */
-    int conn_ping_interval;   /* interval for sending cping packets on
+    int conn_ping_interval;   /* interval for sending keepalive cping packets 
on
                                * unused connection */
     int ping_timeout;         /* generic cping/cpong timeout. Used for 
keepalive packets or
                                * as default for boolean valued connect and 
prepost timeouts.
                                */
-    unsigned int ping_mode;   /* Ping mode flags */
+    unsigned int ping_mode;   /* Ping mode flags (which types of cpings should 
be used) */
     /*
      * Recovery options
      */
@@ -337,6 +337,8 @@
 
     unsigned int max_packet_size;  /*  Maximum AJP Packet size */
 
+    int retry_wait;                /*  Number of milliseconds to sleep before 
doing a retry */
+
     /* 
      * HTTP status that will cause failover (0 means disabled)
      */

Modified: tomcat/connectors/trunk/jk/native/common/jk_util.c
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_util.c?rev=701507&r1=701506&r2=701507&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_util.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_util.c Fri Oct  3 12:37:13 2008
@@ -86,6 +86,7 @@
 #define ACTIVATION_OF_WORKER        ("activation")
 #define WORKER_RECOVER_TIME         ("recover_time")
 #define MAX_REPLY_TIMEOUTS_OF_WORKER ("max_reply_timeouts")
+#define RETRY_WAIT_OF_WORKER        ("retry_wait")
 #define WORKER_MAX_PACKET_SIZE      ("max_packet_size")
 #define STYLE_SHEET_OF_WORKER       ("css")
 #define NAMESPACE_OF_WORKER         ("ns")
@@ -201,6 +202,7 @@
     ACTIVATION_OF_WORKER,
     WORKER_RECOVER_TIME,
     MAX_REPLY_TIMEOUTS_OF_WORKER,
+    RETRY_WAIT_OF_WORKER,
     WORKER_MAX_PACKET_SIZE,
     STYLE_SHEET_OF_WORKER,
     READ_ONLY_OF_WORKER,
@@ -293,6 +295,7 @@
     ACTIVATION_OF_WORKER,
     WORKER_RECOVER_TIME,
     MAX_REPLY_TIMEOUTS_OF_WORKER,
+    RETRY_WAIT_OF_WORKER,
     WORKER_MAX_PACKET_SIZE,
     STYLE_SHEET_OF_WORKER,
     NAMESPACE_OF_WORKER,
@@ -362,8 +365,8 @@
     Sleep(ms);
 #else
     struct timeval tv;
-    tv.tv_usec = ms * 1000;
-    tv.tv_sec = 0;
+    tv.tv_usec = (ms % 1000) * 1000;
+    tv.tv_sec = ms / 1000;
     select(0, NULL, NULL, NULL, &tv);
 #endif
 }
@@ -967,6 +970,19 @@
     return jk_map_get_int(m, buf, def);
 }
 
+int jk_get_worker_retry_wait(jk_map_t *m, const char *wname, int def)
+{
+    char buf[1024];
+
+    if (!m || !wname) {
+        return -1;
+    }
+
+    MAKE_WORKER_PARAM(RETRY_WAIT_OF_WORKER);
+
+    return jk_map_get_int(m, buf, def);
+}
+
 int jk_get_worker_socket_buffer(jk_map_t *m, const char *wname, int def)
 {
     char buf[1024];

Modified: tomcat/connectors/trunk/jk/native/common/jk_util.h
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_util.h?rev=701507&r1=701506&r2=701507&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_util.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_util.h Fri Oct  3 12:37:13 2008
@@ -98,6 +98,8 @@
 
 int jk_get_worker_max_reply_timeouts(jk_map_t *m, const char *wname, int def);
 
+int jk_get_worker_retry_wait(jk_map_t *m, const char *wname, int def);
+
 const char *jk_get_worker_route(jk_map_t *m, const char *wname, const char 
*def);
 
 const char *jk_get_worker_domain(jk_map_t *m, const char *wname, const char 
*def);



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to