From f887fc159fe6570d2d43ea8f154733f2618922f5 Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 16 Feb 2009 16:26:57 +0000 Subject: [PATCH] try to reduce the large number of unclosed incoming connections git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5615 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- .../anomic/http/JakartaCommonsHttpClient.java | 7 ++- source/de/anomic/server/serverCore.java | 43 +++++-------------- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/source/de/anomic/http/JakartaCommonsHttpClient.java b/source/de/anomic/http/JakartaCommonsHttpClient.java index 49b84b2c5..7d7651b98 100644 --- a/source/de/anomic/http/JakartaCommonsHttpClient.java +++ b/source/de/anomic/http/JakartaCommonsHttpClient.java @@ -93,9 +93,14 @@ public class JakartaCommonsHttpClient { * set options for connection manager */ // conManager.getParams().setDefaultMaxConnectionsPerHost(4); // default 2 + HostConfiguration localHostConfiguration = new HostConfiguration(); conManager.getParams().setMaxTotalConnections(200); // Proxy may need many connections conManager.getParams().setConnectionTimeout(60000); // set a default timeout - conManager.getParams().setDefaultMaxConnectionsPerHost(10); // prevent DoS by mistake + conManager.getParams().setDefaultMaxConnectionsPerHost(3); // prevent DoS by mistake + localHostConfiguration.setHost("localhost"); + conManager.getParams().setMaxConnectionsPerHost(localHostConfiguration, 10); + localHostConfiguration.setHost("127.0.0.1"); + conManager.getParams().setMaxConnectionsPerHost(localHostConfiguration, 10); // TODO should this be configurable? // accept self-signed or untrusted certificates diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.java index 69de2d513..ea5728d1a 100644 --- a/source/de/anomic/server/serverCore.java +++ b/source/de/anomic/server/serverCore.java @@ -373,13 +373,14 @@ public final class serverCore extends serverAbstractBusyThread implements server } // keep-alive: if set to true, the server frequently sends keep-alive packets to the client which the client must respond to // we set this to false to prevent that a missing ack from the client forces the server to close the connection - // controlSocket.setKeepAlive(false); + controlSocket.setKeepAlive(false); // disable Nagle's algorithm (waiting for more data until packet is full) // controlSocket.setTcpNoDelay(true); // set a non-zero linger, that means that a socket.close() blocks until all data is written // controlSocket.setSoLinger(false, this.timeout); + controlSocket.setSoLinger(true, this.timeout); // ensure that MTU-48 is not exceeded to prevent that routers cannot handle large data packets // read http://www.cisco.com/warp/public/105/38.shtml for explanation @@ -528,15 +529,12 @@ public final class serverCore extends serverAbstractBusyThread implements server } public void close() { - if (this.isAlive()) { - try { - // closing the socket to the client - if ((this.controlSocket != null)&&(this.controlSocket.isConnected())) { - this.controlSocket.close(); - serverCore.this.log.logInfo("Closing main socket of thread '" + this.getName() + "'"); - } - } catch (final Exception e) {} - } + // closing the socket to the client + if (this.controlSocket != null) try { + this.controlSocket.close(); + serverCore.this.log.logInfo("Closing main socket of thread '" + this.getName() + "'"); + this.controlSocket = null; + } catch (final Exception e) {} } public long getRequestStartTime() { @@ -551,12 +549,6 @@ public final class serverCore extends serverAbstractBusyThread implements server this.identity = id; } - /* - public void setPromiscuous() { - this.promiscuous = true; - } - */ - public void log(final boolean outgoing, final String request) { if (serverCore.this.log.isFine()) serverCore.this.log.logFine(this.userAddress.getHostAddress() + "/" + this.identity + " " + "[" + ((busySessions == null)? -1 : busySessions.size()) + ", " + this.commandCounter + @@ -660,29 +652,16 @@ public final class serverCore extends serverAbstractBusyThread implements server } - /* - * (non-Javadoc) - * - * @see java.lang.Object#finalize() - */ protected void finalize() { - if (busySessions != null && busySessions.contains(this)) - { + if (busySessions != null && busySessions.contains(this)) { busySessions.remove(this); if(log.isFinest()) log.logFinest("* removed session "+ this.controlSocket.getRemoteSocketAddress() + this.request); } + this.close(); } private void listen() { try { - - Object result; -// // send greeting -// Object result = commandObj.greeting(); -// if (result != null) { -// if ((result instanceof String) && (((String) result).length() > 0)) writeLine((String) result); -// } - // start dialog byte[] requestBytes = null; boolean terminate = false; @@ -757,7 +736,7 @@ public final class serverCore extends serverAbstractBusyThread implements server } } //long commandStart = System.currentTimeMillis(); - result = ((Method)commandMethod).invoke(this.commandObj, stringParameter); + Object result = ((Method)commandMethod).invoke(this.commandObj, stringParameter); //announceMoreExecTime(commandStart - System.currentTimeMillis()); // shall be negative! //log.logDebug("* session " + handle + " completed command '" + request + "'. time = " + (System.currentTimeMillis() - handle)); this.out.flush();