remm 2005/03/14 07:33:11 Modified: util/java/org/apache/tomcat/util/net PoolTcpEndpoint.java http11/src/java/org/apache/coyote/http11 Http11Processor.java Http11Protocol.java Log: - The "new" thread pool currently uses the endpoint to store its stuff. - Allocate a worker before accepting. If the pool is full, wait 100ms. This should allow taking advantage of the acceptCount. - Fix setting a reduced socket timeout. Revision Changes Path 1.44 +14 -8 jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/PoolTcpEndpoint.java Index: PoolTcpEndpoint.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/PoolTcpEndpoint.java,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- PoolTcpEndpoint.java 29 Jan 2005 19:30:44 -0000 1.43 +++ PoolTcpEndpoint.java 14 Mar 2005 15:33:10 -0000 1.44 @@ -626,21 +626,27 @@ // Ignore } } - - // Accept the next incoming connection from the server socket - Socket socket = acceptSocket(); - // Hand this socket off to an appropriate processor + // Allocate a new worker thread MasterSlaveWorkerThread workerThread = createWorkerThread(); if (workerThread == null) { try { - log.warn(sm.getString("endpoint.noProcessor")); - socket.close(); - } catch (IOException e) { - ; + // Wait a little for load to go down: as a result, + // no accept will be made until the concurrency is + // lower than the specified maxThreads, and current + // connections will wait for a little bit instead of + // failing right away. + Thread.sleep(100); + } catch (InterruptedException e) { + // Ignore } continue; } + + // Accept the next incoming connection from the server socket + Socket socket = acceptSocket(); + + // Hand this socket off to an appropriate processor workerThread.assign(socket); // The processor will recycle itself when it finishes 1.119 +36 -5 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java Index: Http11Processor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java,v retrieving revision 1.118 retrieving revision 1.119 diff -u -r1.118 -r1.119 --- Http11Processor.java 27 Feb 2005 18:18:02 -0000 1.118 +++ Http11Processor.java 14 Mar 2005 15:33:10 -0000 1.119 @@ -49,6 +49,7 @@ import org.apache.tomcat.util.buf.MessageBytes; import org.apache.tomcat.util.http.FastHttpDateFormat; import org.apache.tomcat.util.http.MimeHeaders; +import org.apache.tomcat.util.net.PoolTcpEndpoint; import org.apache.tomcat.util.net.SSLSupport; import org.apache.tomcat.util.threads.ThreadPool; import org.apache.tomcat.util.threads.ThreadWithAttributes; @@ -298,6 +299,12 @@ /** + * Associated endpoint. + */ + protected PoolTcpEndpoint endpoint; + + + /** * Allow a customized the server header for the tin-foil hat folks. */ protected String server = null; @@ -356,6 +363,12 @@ this.threadPool = threadPool; } + + public void setEndpoint(PoolTcpEndpoint endpoint) { + this.endpoint = endpoint; + } + + /** * Add user-agent for which gzip compression didn't works * The user agent String given will be exactly matched @@ -764,15 +777,33 @@ int keepAliveLeft = maxKeepAliveRequests; int soTimeout = socket.getSoTimeout(); + int oldSoTimeout = soTimeout; - float threadRatio = - (float) threadPool.getCurrentThreadsBusy() - / (float) threadPool.getMaxThreads(); - if ((threadRatio > 0.33) && (threadRatio <= 0.66)) { + int threadRatio = 0; + if (threadPool.getCurrentThreadsBusy() > 0) { + threadRatio = (threadPool.getCurrentThreadsBusy() * 100) + / threadPool.getMaxThreads(); + } else { + threadRatio = (endpoint.getCurrentThreadsBusy() * 100) + / endpoint.getMaxThreads(); + } + if ((threadRatio > 33) && (threadRatio <= 66)) { soTimeout = soTimeout / 2; - } else if (threadRatio > 0.66) { + } else if ((threadRatio > 66) && (threadRatio <= 90)) { soTimeout = soTimeout / 3; keepAliveLeft = 1; + } else if (threadRatio > 90) { + soTimeout = soTimeout / 20; + keepAliveLeft = 1; + } + + if (soTimeout != oldSoTimeout) { + try { + socket.setSoTimeout(soTimeout); + } catch (Throwable t) { + log.debug("Error setting timeout", t); + error = true; + } } boolean keptAlive = false; 1.63 +1 -0 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Protocol.java Index: Http11Protocol.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Protocol.java,v retrieving revision 1.62 retrieving revision 1.63 diff -u -r1.62 -r1.63 --- Http11Protocol.java 29 Jan 2005 19:29:54 -0000 1.62 +++ Http11Protocol.java 14 Mar 2005 15:33:10 -0000 1.63 @@ -684,6 +684,7 @@ new Http11Processor(proto.maxHttpHeaderSize); processor.setAdapter( proto.adapter ); processor.setThreadPool( proto.tp ); + processor.setEndpoint( proto.ep ); processor.setMaxKeepAliveRequests( proto.maxKeepAliveRequests ); processor.setTimeout( proto.timeout ); processor.setDisableUploadTimeout( proto.disableUploadTimeout );
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]