add response time and contention traces to logfile
This commit is contained in:
parent
94ea88fe17
commit
56b4263107
1 changed files with 28 additions and 17 deletions
|
@ -61,7 +61,7 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
||||||
|
|
||||||
private static DateFormat tsFormat = new SimpleDateFormat( "dd.MM.yy HH:mm", new Locale( "en", "US" ) );
|
private static DateFormat tsFormat = new SimpleDateFormat( "dd.MM.yy HH:mm", new Locale( "en", "US" ) );
|
||||||
|
|
||||||
private static String formattedTimestamp()
|
private static String formattedTimeStamp( long t )
|
||||||
{
|
{
|
||||||
synchronized( tsFormat )
|
synchronized( tsFormat )
|
||||||
{
|
{
|
||||||
|
@ -73,13 +73,17 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
||||||
{
|
{
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
BufferedWriter bw = null;
|
BufferedWriter bw = null;
|
||||||
|
|
||||||
|
// first line
|
||||||
|
String getline = null;
|
||||||
|
String sessionInfo = null;
|
||||||
|
String sIp = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
br = new BufferedReader( new InputStreamReader( clientSocket.getInputStream() , "UTF-8") );
|
br = new BufferedReader( new InputStreamReader( clientSocket.getInputStream() , "UTF-8") );
|
||||||
bw = new BufferedWriter( new OutputStreamWriter( clientSocket.getOutputStream(), "UTF-8" ) );
|
bw = new BufferedWriter( new OutputStreamWriter( clientSocket.getOutputStream(), "UTF-8" ) );
|
||||||
|
|
||||||
// first line
|
|
||||||
String getline = null;
|
|
||||||
String agent = null;
|
String agent = null;
|
||||||
String encodings = null;
|
String encodings = null;
|
||||||
String xff = null; // X-Forwarded-For
|
String xff = null; // X-Forwarded-For
|
||||||
|
@ -118,6 +122,17 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InetAddress ip = clientSocket.getInetAddress();
|
||||||
|
sIp = xff == null ? (ip==null ? "null" : ip.toString() ) : xff;
|
||||||
|
boolean newSession = IpAccessMonitor.touchIpAccess( sIp );
|
||||||
|
sessionInfo = " new";
|
||||||
|
if ( !newSession )
|
||||||
|
{
|
||||||
|
int sessionCount = IpAccessMonitor.getSessionCount();
|
||||||
|
sessionInfo = " " + Math.min( sessionCount, 999 );
|
||||||
|
sessionInfo = sessionInfo.substring( sessionInfo.length() - 4 );
|
||||||
|
}
|
||||||
|
|
||||||
String excludedAgents = System.getProperty( "excludedAgents" );
|
String excludedAgents = System.getProperty( "excludedAgents" );
|
||||||
if ( agent != null && excludedAgents != null )
|
if ( agent != null && excludedAgents != null )
|
||||||
{
|
{
|
||||||
|
@ -149,19 +164,6 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
InetAddress ip = clientSocket.getInetAddress();
|
|
||||||
String sIp = xff == null ? (ip==null ? "null" : ip.toString() ) : xff;
|
|
||||||
boolean newSession = IpAccessMonitor.touchIpAccess( sIp );
|
|
||||||
String sessionInfo = " new";
|
|
||||||
if ( !newSession )
|
|
||||||
{
|
|
||||||
int sessionCount = IpAccessMonitor.getSessionCount();
|
|
||||||
sessionInfo = " " + Math.min( sessionCount, 999 );
|
|
||||||
sessionInfo = sessionInfo.substring( sessionInfo.length() - 4 );
|
|
||||||
}
|
|
||||||
System.out.println( formattedTimestamp() + sessionInfo + " ip=" + sIp + " -> " + getline );
|
|
||||||
|
|
||||||
String url = getline.split(" ")[1];
|
String url = getline.split(" ")[1];
|
||||||
HashMap<String,String> params = getUrlParams(url);
|
HashMap<String,String> params = getUrlParams(url);
|
||||||
|
|
||||||
|
@ -296,9 +298,13 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
||||||
{
|
{
|
||||||
threadPoolSync.notifyAll();
|
threadPoolSync.notifyAll();
|
||||||
}
|
}
|
||||||
|
long t = System.currentTimeMillis();
|
||||||
|
long ms = t - starttime;
|
||||||
|
System.out.println( formattedTimeStamp(t) + sessionInfo + " ip=" + sIp + " ms=" + ms + " -> " + getline );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception
|
public static void main(String[] args) throws Exception
|
||||||
{
|
{
|
||||||
System.out.println("BRouter 1.6.1 / 01032020");
|
System.out.println("BRouter 1.6.1 / 01032020");
|
||||||
|
@ -371,13 +377,18 @@ public class RouteServer extends Thread implements Comparable<RouteServer>
|
||||||
{
|
{
|
||||||
threadPoolSync.wait( maxWaitTime );
|
threadPoolSync.wait( maxWaitTime );
|
||||||
}
|
}
|
||||||
|
long t = System.currentTimeMillis();
|
||||||
|
System.out.println( formattedTimeStamp(t) + " contention! ms waited " + (t - server.starttime) );
|
||||||
}
|
}
|
||||||
cleanupThreadQueue( threadQueue );
|
cleanupThreadQueue( threadQueue );
|
||||||
if ( threadQueue.size() >= maxthreads )
|
if ( threadQueue.size() >= maxthreads )
|
||||||
{
|
{
|
||||||
if ( debug ) System.out.println( "stopping oldest thread..." );
|
if ( debug ) System.out.println( "stopping oldest thread..." );
|
||||||
// no way... stop the oldest thread
|
// no way... stop the oldest thread
|
||||||
threadQueue.poll().stopRouter();
|
RouteServer oldest = threadQueue.poll();
|
||||||
|
oldest.stopRouter();
|
||||||
|
long t = System.currentTimeMillis();
|
||||||
|
System.out.println( formattedTimeStamp(t) + " contention! ms killed " + (t - oldest.starttime) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue