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
+9 -2
View File
@@ -113,7 +113,14 @@
<!--version>1.1.0-SNAPSHOT</version-->
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.hdrhistogram</groupId>
<artifactId>HdrHistogram</artifactId>
<version>2.1.4</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -126,7 +133,7 @@
<artifactId>robot.junit</artifactId>
<version>0.0.0.12</version>
<scope>test</scope>
</dependency>
</dependency>
<!-- needs extra dependencies: objenesis & hamcrest -->
<dependency>
@@ -36,6 +36,7 @@ import org.eclipse.moquette.server.IAuthenticator;
import org.eclipse.moquette.server.ServerChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.HdrHistogram.Histogram;
/**
*
@@ -67,6 +68,8 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
private final AnnotationSupport annotationSupport = new AnnotationSupport();
CountDownLatch m_stopLatch;
Histogram histogram = new Histogram(5);
private SimpleMessaging() {
}
@@ -153,7 +156,10 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
ServerChannel session = ((ProtocolEvent) evt).getSession();
AbstractMessage message = ((ProtocolEvent) evt).getMessage();
try {
long startTime = System.nanoTime();
annotationSupport.dispatch(session, message);
long delay = System.nanoTime() - startTime;
histogram.recordValue(delay);
} catch (Throwable 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;
m_stopLatch.countDown();
//log metrics
histogram.outputPercentileDistribution(System.out, 1000.0);
}
}