From 50e1005b296cde1b6cd4beed0ea8cce25e08fe48 Mon Sep 17 00:00:00 2001 From: andrea Date: Mon, 2 Mar 2015 23:11:09 +0100 Subject: [PATCH] Added moquette.processor.benchmark sys property to enable/disable processor performance recording --- .../moquette/spi/impl/SimpleMessaging.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/broker/src/main/java/org/eclipse/moquette/spi/impl/SimpleMessaging.java b/broker/src/main/java/org/eclipse/moquette/spi/impl/SimpleMessaging.java index 9dd2cdb8..f639a58e 100644 --- a/broker/src/main/java/org/eclipse/moquette/spi/impl/SimpleMessaging.java +++ b/broker/src/main/java/org/eclipse/moquette/spi/impl/SimpleMessaging.java @@ -66,6 +66,7 @@ public class SimpleMessaging implements IMessaging, EventHandler { private final ProtocolProcessor m_processor = new ProtocolProcessor(); private final AnnotationSupport annotationSupport = new AnnotationSupport(); + private boolean benchmarkEnabled = false; CountDownLatch m_stopLatch; @@ -158,8 +159,10 @@ public class SimpleMessaging implements IMessaging, EventHandler { try { long startTime = System.nanoTime(); annotationSupport.dispatch(session, message); - long delay = System.nanoTime() - startTime; - histogram.recordValue(delay); + if (benchmarkEnabled) { + long delay = System.nanoTime() - startTime; + histogram.recordValue(delay); + } } catch (Throwable th) { LOG.error("Grave error processing the message {} for {}", message, session, th); } @@ -167,6 +170,8 @@ public class SimpleMessaging implements IMessaging, EventHandler { } private void processInit(Properties props) { + benchmarkEnabled = Boolean.parseBoolean(System.getProperty("moquette.processor.benchmark", "false")); + //TODO use a property to select the storage path MapDBPersistentStore mapStorage = new MapDBPersistentStore(); m_storageService = mapStorage; @@ -201,7 +206,9 @@ public class SimpleMessaging implements IMessaging, EventHandler { subscriptions = null; m_stopLatch.countDown(); - //log metrics - histogram.outputPercentileDistribution(System.out, 1000.0); + if (benchmarkEnabled) { + //log metrics + histogram.outputPercentileDistribution(System.out, 1000.0); + } } }