Skip to content
Prev Previous commit
Next Next commit
use flush interval for event queue polling
  • Loading branch information
thomaszurkan-optimizely committed Oct 21, 2019
commit 1b919a38d3c675d4ae45a61f0541c99c1fbb2a49
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,11 @@ public void run() {
deadline = System.currentTimeMillis() + flushInterval;
}

Object item = eventQueue.poll(50, TimeUnit.MILLISECONDS);
Object item = eventQueue.poll(flushInterval, TimeUnit.MILLISECONDS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this another configuration option. If we set to flushInterval then the messages are only guaranteed to be dispatched every (2 * flushInterval) milliseconds. I'd like to better understand the CPU and battery utilization with a change like this.

if (item == null) {
logger.debug("Empty item, sleeping for 50ms.");
Thread.sleep(50);
logger.debug("Empty item after waiting flush interval. Flushing.");
flush();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flush() is not necessary since it will be captured on the next while iteration. in general I'd like to keep the number of places we're calling flush() and setting the deadline to a minimum. (Ideally one place)

deadline = System.currentTimeMillis() + flushInterval;
continue;
}

Expand Down