Introduce keepAliveTimeout to be able to separate
authormturk <mturk@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 29 Sep 2006 08:23:37 +0000 (08:23 +0000)
committermturk <mturk@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 29 Sep 2006 08:23:37 +0000 (08:23 +0000)
the Keep-Alive and Socket timeout.
The patch enables to have infinite socket timeouts
while still having correct keep alive.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@451157 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/connector/Constants.java
java/org/apache/catalina/connector/mbeans-descriptors.xml
java/org/apache/coyote/ajp/AjpAprProtocol.java
java/org/apache/coyote/ajp/Constants.java
java/org/apache/coyote/http11/Constants.java
java/org/apache/coyote/http11/Http11AprProcessor.java
java/org/apache/coyote/http11/Http11AprProtocol.java
java/org/apache/coyote/http11/Http11Processor.java
java/org/apache/coyote/http11/Http11Protocol.java
java/org/apache/tomcat/util/net/AprEndpoint.java

index 7f49bb9..24ddffe 100644 (file)
@@ -34,6 +34,7 @@ public final class Constants {
     public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
     public static final int DEFAULT_CONNECTION_UPLOAD_TIMEOUT = 300000;
     public static final int DEFAULT_SERVER_SOCKET_TIMEOUT = 0;
+    public static final int DEFAULT_KEEPALIVE_TIMEOUT = 15000;
 
     public static final int PROCESSOR_IDLE = 0;
     public static final int PROCESSOR_ACTIVE = 1;
index 5651d53..58ba947 100644 (file)
           description="Maximum number of Keep-Alive requests to honor per connection"
                  type="int"/>
 
+    <attribute   name="keepAliveTimeout"
+          description="The number of seconds Tomcat will wait for a subsequent request before closing the connection"
+                 type="int"/>
+
     <attribute   name="maxPostSize"
           description="Maximum size in bytes of a POST which will be handled by the servlet API provided features"
                  type="int"/>
index 9a3f038..73206cd 100644 (file)
@@ -417,6 +417,15 @@ public class AjpAprProtocol
         setAttribute("soTimeout", "" + i);
     }
 
+    public int getKeepAliveTimeout() {
+        return ep.getKeepAliveTimeout();
+    }
+
+
+    public void setKeepAliveTimeout( int i ) {
+        ep.setKeepAliveTimeout(i);
+        setAttribute("keepAliveTimeout", "" + i);
+    }
     
     public void setRequiredSecret(String requiredSecret) {
         this.requiredSecret = requiredSecret;
index 077ee37..368d563 100644 (file)
@@ -38,6 +38,7 @@ public final class Constants {
     public static final int DEFAULT_CONNECTION_LINGER = -1;
     public static final int DEFAULT_CONNECTION_TIMEOUT = -1;
     public static final int DEFAULT_CONNECTION_UPLOAD_TIMEOUT = 300000;
+    public static final int DEFAULT_KEEPALIVE_TIMEOUT = 15000;    
     public static final int DEFAULT_SERVER_SOCKET_TIMEOUT = 0;
     public static final boolean DEFAULT_TCP_NO_DELAY = true;
 
index 46dde83..5f3a2fb 100644 (file)
@@ -39,6 +39,7 @@ public final class Constants {
     public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
     public static final int DEFAULT_CONNECTION_UPLOAD_TIMEOUT = 300000;
     public static final int DEFAULT_SERVER_SOCKET_TIMEOUT = 0;
+    public static final int DEFAULT_KEEPALIVE_TIMEOUT = 15000;
     public static final boolean DEFAULT_TCP_NO_DELAY = true;
     
     
index 3b3daf4..9744899 100644 (file)
@@ -208,6 +208,11 @@ public class Http11AprProcessor implements ActionHook {
      */
     protected int maxKeepAliveRequests = -1;
 
+    /**
+     * The number of seconds Tomcat will wait for a subsequent request
+     * before closing the connection.
+     */
+    protected int keepAliveTimeout = 15000;
 
     /**
      * SSL enabled ?
@@ -643,6 +648,20 @@ public class Http11AprProcessor implements ActionHook {
         return maxKeepAliveRequests;
     }
 
+    /**
+     * Set the Keep-Alive timeout.
+     */
+    public void setKeepAliveTimeout(int timeout) {
+        keepAliveTimeout = timeout;
+    }
+
+
+    /**
+     * Return the number Keep-Alive timeout.
+     */
+    public int getKeepAliveTimeout() {
+        return keepAliveTimeout;
+    }
 
     /**
      * Set the maximum size of a POST which will be buffered in SSL mode.
index fd27184..f58275a 100644 (file)
@@ -201,6 +201,7 @@ public class Http11AprProtocol implements ProtocolHandler, MBeanRegistration
     private int socketBuffer = 9000;
     private Adapter adapter;
     private Http11ConnectionHandler cHandler;
+    private int keepAliveTimeout = 15000; // 15 seconds as in Apache HTTPD server
 
     /**
      * Compression value.
@@ -463,6 +464,14 @@ public class Http11AprProtocol implements ProtocolHandler, MBeanRegistration
     }
 
     /**
+     * The number of seconds Tomcat will wait for a subsequent request
+     * before closing the connection. The default is the same as for
+     * Apache HTTP Server (15 000 milliseconds).
+     */
+    public int getKeepAliveTimeout() { return keepAliveTimeout; }
+    public void setKeepAliveTimeout(int timeout) { keepAliveTimeout = timeout; }
+
+    /**
      * Return the Keep-Alive policy for the connection.
      */
     public boolean getKeepAlive() {
index 58c8230..b6f3a75 100644 (file)
@@ -185,6 +185,12 @@ public class Http11Processor implements ActionHook {
      */
     protected int maxKeepAliveRequests = -1;
 
+    /**
+     * The number of seconds Tomcat will wait for a subsequent request
+     * before closing the connection.
+     */
+    protected int keepAliveTimeout = 15000;
+
 
     /**
      * SSL information.
@@ -620,6 +626,21 @@ public class Http11Processor implements ActionHook {
         return maxKeepAliveRequests;
     }
 
+    /**
+     * Set the Keep-Alive timeout.
+     */
+    public void setKeepAliveTimeout(int timeout) {
+        keepAliveTimeout = timeout;
+    }
+
+
+    /**
+     * Return the number Keep-Alive timeout.
+     */
+    public int getKeepAliveTimeout() {
+        return keepAliveTimeout;
+    }
+
 
     /**
      * Set the maximum size of a POST which will be buffered in SSL mode.
@@ -778,8 +799,13 @@ public class Http11Processor implements ActionHook {
 
             // Parsing the request header
             try {
-                if( !disableUploadTimeout && keptAlive && soTimeout > 0 ) {
-                    socket.setSoTimeout(soTimeout);
+                if (!disableUploadTimeout && keptAlive) {
+                    if (keepAliveTimeout > 0) {
+                        socket.setSoTimeout(keepAliveTimeout);
+                    }
+                    else if (soTimeout > 0) {
+                        socket.setSoTimeout(soTimeout);                        
+                    }
                 }
                 inputBuffer.parseRequestLine();
                 request.setStartTime(System.currentTimeMillis());
index a1a92ab..8a37d6a 100644 (file)
@@ -70,6 +70,7 @@ public class Http11Protocol
     public Http11Protocol() {
         setSoLinger(Constants.DEFAULT_CONNECTION_LINGER);
         setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT);
+        setKeepAliveTimeout(Constants.DEFAULT_KEEPALIVE_TIMEOUT);
         //setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT);
         setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);
     }
@@ -281,6 +282,16 @@ public class Http11Protocol
     public int getMaxKeepAliveRequests() { return maxKeepAliveRequests; }
     public void setMaxKeepAliveRequests(int mkar) { maxKeepAliveRequests = mkar; }
 
+    // HTTP
+    /**
+     * The number of seconds Tomcat will wait for a subsequent request
+     * before closing the connection. The default is the same as for
+     * Apache HTTP Server (15 000 milliseconds).
+     */
+    protected int keepAliveTimeout = 15000;
+    public int getKeepAliveTimeout() { return keepAliveTimeout; }
+    public void setKeepAliveTimeout(int timeout) { keepAliveTimeout = timeout; }
+
 
     // HTTP
     /**
@@ -580,6 +591,7 @@ public class Http11Protocol
                         new Http11Processor(protocol.maxHttpHeaderSize, protocol.endpoint);
                     processor.setAdapter(protocol.adapter);
                     processor.setMaxKeepAliveRequests(protocol.maxKeepAliveRequests);
+                    processor.setKeepAliveTimeout(protocol.keepAliveTimeout);
                     processor.setTimeout(protocol.timeout);
                     processor.setDisableUploadTimeout(protocol.disableUploadTimeout);
                     processor.setCompression(protocol.compression);
index 617f9a0..2ec532f 100644 (file)
@@ -255,6 +255,13 @@ public class AprEndpoint {
     public int getSoTimeout() { return soTimeout; }
     public void setSoTimeout(int soTimeout) { this.soTimeout = soTimeout; }
 
+    /**
+     * Keep-Alive timeout.
+     */
+    protected int keepAliveTimeout = 15000;
+    public int getKeepAliveTimeout() { return keepAliveTimeout; }
+    public void setKeepAliveTimeout(int timeout) { keepAliveTimeout = timeout; }
+
 
     /**
      * Timeout on first request read before going to the poller, in ms.
@@ -1148,11 +1155,11 @@ public class AprEndpoint {
         protected void init() {
             pool = Pool.create(serverSockPool);
             int size = pollerSize / pollerThreadCount;
-            int timeout = soTimeout;
+            int timeout = keepAliveTimeout;
             if (comet) {
                 // FIXME: Find an appropriate timeout value, for now, "longer than usual"
                 // semms appropriate
-                timeout = soTimeout * 50;
+                timeout = keepAliveTimeout * 50;
             }
             serverPollset = allocatePoller(size, pool, timeout);
             if (serverPollset == 0 && size > 1024) {
@@ -1566,14 +1573,14 @@ public class AprEndpoint {
         protected void init() {
             pool = Pool.create(serverSockPool);
             int size = sendfileSize / sendfileThreadCount;
-            sendfilePollset = allocatePoller(size, pool, soTimeout);
+            sendfilePollset = allocatePoller(size, pool, keepAliveTimeout);
             if (sendfilePollset == 0 && size > 1024) {
                 size = 1024;
-                sendfilePollset = allocatePoller(size, pool, soTimeout);
+                sendfilePollset = allocatePoller(size, pool, keepAliveTimeout);
             }
             if (sendfilePollset == 0) {
                 size = 62;
-                sendfilePollset = allocatePoller(size, pool, soTimeout);
+                sendfilePollset = allocatePoller(size, pool, keepAliveTimeout);
             }
             desc = new long[size * 2];
             sendfileData = new HashMap<Long, SendfileData>(size);