From: fhanik Date: Tue, 24 Oct 2006 22:31:51 +0000 (+0000) Subject: Make the buffer pool configurable, still need to make it configurable based on size X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ea81327f4efe20bd9f39249b28024b8de43421ce;p=tomcat7.0 Make the buffer pool configurable, still need to make it configurable based on size git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@467513 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index e9da70fe8..168c5ca49 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -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 nioChannels = new ConcurrentLinkedQueue() { - 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); diff --git a/java/org/apache/tomcat/util/net/SocketProperties.java b/java/org/apache/tomcat/util/net/SocketProperties.java index d693e3b2b..86c1e2bf7 100644 --- a/java/org/apache/tomcat/util/net/SocketProperties.java +++ b/java/org/apache/tomcat/util/net/SocketProperties.java @@ -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