Added measuer of latency to server side

This commit is contained in:
andrea
2015-02-24 23:38:05 +01:00
parent fb39e64417
commit 3ea9e3f6e0
2 changed files with 18 additions and 2 deletions
+8 -1
View File
@@ -114,6 +114,13 @@
<version>2.0.0-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>org.hdrhistogram</groupId>
<artifactId>HdrHistogram</artifactId>
<version>2.1.4</version>
</dependency>
<!-- Test dependencies -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
@@ -126,7 +133,7 @@
<artifactId>robot.junit</artifactId> <artifactId>robot.junit</artifactId>
<version>0.0.0.12</version> <version>0.0.0.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- needs extra dependencies: objenesis & hamcrest --> <!-- needs extra dependencies: objenesis & hamcrest -->
<dependency> <dependency>
@@ -36,6 +36,7 @@ import org.eclipse.moquette.server.IAuthenticator;
import org.eclipse.moquette.server.ServerChannel; import org.eclipse.moquette.server.ServerChannel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.HdrHistogram.Histogram;
/** /**
* *
@@ -68,6 +69,8 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
CountDownLatch m_stopLatch; CountDownLatch m_stopLatch;
Histogram histogram = new Histogram(5);
private SimpleMessaging() { private SimpleMessaging() {
} }
@@ -153,7 +156,10 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
ServerChannel session = ((ProtocolEvent) evt).getSession(); ServerChannel session = ((ProtocolEvent) evt).getSession();
AbstractMessage message = ((ProtocolEvent) evt).getMessage(); AbstractMessage message = ((ProtocolEvent) evt).getMessage();
try { try {
long startTime = System.nanoTime();
annotationSupport.dispatch(session, message); annotationSupport.dispatch(session, message);
long delay = System.nanoTime() - startTime;
histogram.recordValue(delay);
} catch (Throwable th) { } catch (Throwable th) {
LOG.error("Grave error processing the message {} for {}", message, session, th); LOG.error("Grave error processing the message {} for {}", message, session, th);
} }
@@ -194,5 +200,8 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
subscriptions = null; subscriptions = null;
m_stopLatch.countDown(); m_stopLatch.countDown();
//log metrics
histogram.outputPercentileDistribution(System.out, 1000.0);
} }
} }