Skip to content

Commit

Permalink
Introduce an optional delay, in order to try and group multiple sampl…
Browse files Browse the repository at this point in the history
…es in a single insert.
  • Loading branch information
Jesse White committed May 2, 2015
1 parent d481c29 commit c40afa3
Showing 1 changed file with 13 additions and 0 deletions.
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c40afa3

Please sign in to comment.