-
Notifications
You must be signed in to change notification settings - Fork 902
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
Use BlockingQueue.drainTo() in Journal thread #3544
Conversation
rerun the failure tests
|
queue.drainTo(localQueueEntries); | ||
} | ||
|
||
if (!localQueueEntries.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If new entries keep put into the queue
, the localQueueEntries
won't be empty, it won't go into line#1107 branch, and the flush won't be triggered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I got the scenario here. I think every time the loop goes back to the top on the while (true)
and we should always check first the localQueueEntries
before attempting the poll()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We should check it before poll
. But we shouldn't connect other logic with else if
.
When there is no entry put in, the localQueueEntries
will be empty. But if there have entries that continue to push, we will never go to other branches.
So the main problem is we never have a chance to go here
I have another question. I think this is only to replace the queue.take();
operation, so why not put them to the line 1100?
@merlimat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good points. I actually think we should do it both before the poll()
and the take()
.
@zymap @hangc0276 PTAL again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
Motivation
Use
BlockingQueue.drainTo()
in the Journal thread to minimize the contention between this thread and the threads passing entries to the journal.The drain method in the
ArrayBlockingQueue
method will use the mutex only once and take out all the items in one shot.The logic in the journal dequeuing is already quite complicated. This change aims at not changing the whole logic, rather doing the minimal intervention.