Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
try to reduce the large number of unclosed incoming connections
orbiterf887fc159fe6
diff --git a/source/de/anomic/http/JakartaCommonsHttpClient.java b/source/de/anomic/http/JakartaCommonsHttpClient.javaindex 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 connectionsconManager.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 certificatesdiff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.javaindex 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 serverthis.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 dialogbyte[] 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();