Make the buffer pool configurable, still need to make it configurable based on size
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 24 Oct 2006 22:31:51 +0000 (22:31 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 24 Oct 2006 22:31:51 +0000 (22:31 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@467513 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/net/NioEndpoint.java
java/org/apache/tomcat/util/net/SocketProperties.java

index e9da70f..168c5ca 100644 (file)
@@ -46,6 +46,7 @@ import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.net.SecureNioChannel.ApplicationBufferHandler;
 import org.apache.tomcat.util.res.StringManager;
+import org.apache.tomcat.util.net.NioEndpoint.KeyAttachment;
 
 /**
  * NIO tailored thread pool, providing the following services:
@@ -149,11 +150,21 @@ public class NioEndpoint {
 
 
     protected ConcurrentLinkedQueue<NioChannel> nioChannels = new ConcurrentLinkedQueue<NioChannel>() {
-        public boolean offer(NioChannel o) {
+        public boolean offer(NioChannel socket) {
+            Poller pol = socket.getPoller();
+            Selector sel = pol!=null?pol.getSelector():null;
+            SelectionKey key = sel!=null?socket.getIOChannel().keyFor(sel):null;
+            KeyAttachment att = key!=null?(KeyAttachment)key.attachment():null;
+            if ( att!=null ) att.reset();
+            if ( key!=null ) key.cancel();
             //avoid over growing our cache or add after we have stopped
-            if ( running && (!paused) && (size() < curThreads) ) return super.offer(o);
+            if ( running && (!paused) && (size() < socketProperties.getDirectBufferPool()) ) return super.offer(socket);
             else return false;
         }
+        
+        public NioChannel poll() {
+            return super.poll();
+        }
     };
 
     
@@ -1199,6 +1210,16 @@ public class NioEndpoint {
         public KeyAttachment(Poller poller) {
             this.poller = poller;
         }
+        public void reset() {
+            //mutex = new Object();
+            wakeUp = false;
+            lastAccess = System.currentTimeMillis();
+            currentAccess = false;
+            comet = false;
+            timeout = -1;
+            error = false;
+            channel = null;
+        }
         public Poller getPoller() { return poller;}
         public void setPoller(Poller poller){this.poller = poller;}
         public long getLastAccess() { return lastAccess; }
@@ -1364,7 +1385,6 @@ public class NioEndpoint {
                             if ((status != null) && (handler.event(socket, status) == Handler.SocketState.CLOSED)) {
                                 // Close socket and pool
                                 try {
-                                    
                                     try {socket.close();}catch (Exception ignore){}
                                     if ( socket.isOpen() ) socket.close(true);
                                     nioChannels.offer(socket);
@@ -1374,7 +1394,6 @@ public class NioEndpoint {
                             } else if ((status == null) && (handler.process(socket) == Handler.SocketState.CLOSED)) {
                                 // Close socket and pool
                                 try {
-                                    
                                     try {socket.close();}catch (Exception ignore){}
                                     if ( socket.isOpen() ) socket.close(true);
                                     nioChannels.offer(socket);
index d693e3b..86c1e2b 100644 (file)
@@ -7,6 +7,8 @@ public class SocketProperties {
     protected boolean directBuffer = true;
     protected int rxBufSize = 25188;
     protected int txBufSize = 43800;
+    protected int directBufferPool = 500;
+    
     protected boolean tcpNoDelay = false;
     protected boolean soKeepAlive = false;
     protected boolean ooBInline = true;
@@ -18,7 +20,7 @@ public class SocketProperties {
     protected int performanceConnectionTime = 1;
     protected int performanceLatency = 0;
     protected int performanceBandwidth = 1;
-    private Socket properties;
+    
 
     public void setProperties(Socket socket) throws SocketException{
         socket.setReceiveBufferSize(rxBufSize);
@@ -53,10 +55,6 @@ public class SocketProperties {
         return performanceLatency;
     }
 
-    public Socket getProperties() {
-        return properties;
-    }
-
     public int getRxBufSize() {
         return rxBufSize;
     }
@@ -93,6 +91,10 @@ public class SocketProperties {
         return txBufSize;
     }
 
+    public int getDirectBufferPool() {
+        return directBufferPool;
+    }
+
     public void setPerformanceConnectionTime(int performanceConnectionTime) {
         this.performanceConnectionTime = performanceConnectionTime;
     }
@@ -149,4 +151,8 @@ public class SocketProperties {
         this.soLingerOn = soLingerOn;
     }
 
+    public void setDirectBufferPool(int directBufferPool) {
+        this.directBufferPool = directBufferPool;
+    }
+
 }
\ No newline at end of file