Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(chore): refactor batch event processor to use blocking queue poll and take so as not to spin too much. #343

Merged
merged 7 commits into from
Oct 23, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ public void run() {
if (System.currentTimeMillis() > deadline) {
logger.debug("Deadline exceeded flushing current batch.");
flush();
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