Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

added a dynamic keep-alive time-out for http server sessions: if there are many concurrent server sessions, the timout is decreased. This should avoid a situation where the clean-up thread is too late to stop running http sessions that should be terminated before the maximum number of server sessions is reached.

orbiter1dc7ea986ab8
diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.java
index d29697f41..951674c4c 100644
--- a/source/de/anomic/server/serverCore.java
+++ b/source/de/anomic/server/serverCore.java
@@ -99,6 +99,7 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
static int sessionCounter = 0;
// static variables
+ private static final long keepAliveTimeout = 60000; // time that a connection is kept alive if requested with a keepAlive statement
public static final Boolean TERMINATE_CONNECTION = Boolean.FALSE;
public static final Boolean RESUME_CONNECTION = Boolean.TRUE;
@@ -677,7 +678,13 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
String reqCmd;
String reqProtocol = "HTTP";
final Object[] stringParameter = new String[1];
- while ((this.in != null) && ((requestBytes = readLine()) != null)) {
+ long listenStart = System.currentTimeMillis();
+ long situationDependentKeepAliveTimeout = keepAliveTimeout;
+ while (this.in != null &&
+ this.controlSocket != null &&
+ this.controlSocket.isConnected() &&
+ (this.commandCounter == 0 || System.currentTimeMillis() - listenStart < situationDependentKeepAliveTimeout) &&
+ (requestBytes = readLine()) != null) {
this.setName("Session_" + this.userAddress.getHostAddress() +
":" + this.controlSocket.getPort() +
"#" + this.commandCounter);
@@ -765,10 +772,12 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
}
if (terminate) break;
+
} catch (final InvocationTargetException e) {
log.logSevere("command execution, target exception " + e.getMessage() + " for client " + this.userAddress.getHostAddress(), e);
- // we extract a target exception and let the thread survive
+ // we extract a target exception
writeLine(this.commandObj.error(e.getTargetException()));
+ break;
} catch (final NoSuchMethodException e) {
log.logSevere("command execution, method exception " + e.getMessage() + " for client " + this.userAddress.getHostAddress(), e);
if (!this.userAddress.isSiteLocalAddress()) {
@@ -779,17 +788,23 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
break;
} catch (final IllegalAccessException e) {
log.logSevere("command execution, illegal access exception " + e.getMessage() + " for client " + this.userAddress.getHostAddress(), e);
- // wrong parameters: this an only be an internal problem
+ // wrong parameters: this can only be an internal problem
writeLine(this.commandObj.error(e));
+ break;
} catch (final java.lang.ClassCastException e) {
log.logSevere("command execution, cast exception " + e.getMessage() + " for client " + this.userAddress.getHostAddress(), e);
// ??
writeLine(this.commandObj.error(e));
+ break;
} catch (final Exception e) {
log.logSevere("command execution, generic exception " + e.getMessage() + " for client " + this.userAddress.getHostAddress(), e);
// whatever happens: the thread has to survive!
writeLine("UNKNOWN REASON:" + this.commandObj.error(e));
+ break;
}
+ // check if we should still keep this alive:
+ // the more connections are alive, the shorter the keep alive timeout
+ situationDependentKeepAliveTimeout = keepAliveTimeout / Math.max(1, sessionThreadGroup.activeCount() - 20);
} // end of while
} catch (final IOException e) {
log.logSevere("command execution, IO exception " + e.getMessage() + " for client " + this.userAddress.getHostAddress(), e);