From c40afa3aeaeffdecbb3363ed49b71ebf2b34a6db Mon Sep 17 00:00:00 2001 From: Jesse White Date: Sat, 2 May 2015 17:45:28 -0400 Subject: [PATCH] Introduce an optional delay, in order to try and group multiple samples in a single insert. --- .../opennms/netmgt/rrd/newts/NewtsPersistor.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/opennms-rrd/opennms-rrd-newts/src/main/java/org/opennms/netmgt/rrd/newts/NewtsPersistor.java b/opennms-rrd/opennms-rrd-newts/src/main/java/org/opennms/netmgt/rrd/newts/NewtsPersistor.java index 994b93a4ccba..00bd0e1f6b72 100644 --- a/opennms-rrd/opennms-rrd-newts/src/main/java/org/opennms/netmgt/rrd/newts/NewtsPersistor.java +++ b/opennms-rrd/opennms-rrd-newts/src/main/java/org/opennms/netmgt/rrd/newts/NewtsPersistor.java @@ -33,6 +33,10 @@ */ public class NewtsPersistor implements Runnable { + public static final boolean NO_DELAY = false; + + public static final long DELAY_IN_MS = 250; + public static final long MAX_CACHE_ENTRIES = 4096; private static final Logger LOG = LoggerFactory.getLogger(NewtsPersistor.class); @@ -78,6 +82,15 @@ public void run() { // Block and wait for an element samples.add(m_queue.take()); try { + if (!NO_DELAY) { + // We only have a single sample, if there are no other samples + // pending on the queue, then sleep for short delay before + // checking again and initiating the insert + if (m_queue.size() == 0) { + Thread.sleep(DELAY_IN_MS); + } + } + // Grab all of the remaining samples on the queue and flatten them m_queue.drainTo(samples); samples.stream().forEach(flattenedSamples::addAll);