mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
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. git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6452 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
e77c906673
commit
1dc7ea986a
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user