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

Allow to send callbacks from journal thread #1258

Closed
wants to merge 1 commit into from

Conversation

merlimat
Copy link
Contributor

In BK 4.3 it was possible to configure 0 threads for the dispatching of journal callback threads.

There might be good reasons to not use a thread pool when dispatching the callback threads:

  • Avoiding one more context switch
  • Avoiding contention on the executor enqueuing
  • When using multiple journals, the journal thread is not a bottleneck anymore

We should allow the same convention (threads=0 means direct execution) that we have in other places.

@merlimat merlimat added this to the 4.7.0 milestone Mar 14, 2018
@merlimat merlimat self-assigned this Mar 14, 2018
this.cbThreadPool = Executors.newFixedThreadPool(conf.getNumJournalCallbackThreads(),
new DefaultThreadFactory("bookie-journal-callback"));
} else {
this.cbThreadPool = MoreExecutors.newDirectExecutorService();
Copy link
Contributor

Choose a reason for hiding this comment

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

this thread pool gets used on two different threads(JournalThread & ForceWriteThread). Are you sure this is safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be anyway either one case or the other.

I think though that it should be safe anyway. If you have a "direct" executor, it is like a dummy executor.

We could have threads t1 and t2 sharing the same instance. when t1 submits one task, it gets executed immediately in t1. t2 tasks will be executed in t2 thread.

Copy link
Contributor

Choose a reason for hiding this comment

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

Previously I think it wasn't possible. if getNumJournalCallbackThreads was 0, then we would throw an exception creating the executor. If 1, then callbacks would be serialized. That said, if you had getNumJournalCallbackThreads > 1, you have no guarantee where you run, they would have to be thread safe anyhow.

this.cbThreadPool = Executors.newFixedThreadPool(conf.getNumJournalCallbackThreads(),
new DaemonThreadFactory());
if (conf.getNumJournalCallbackThreads() > 0) {
this.cbThreadPool = Executors.newFixedThreadPool(conf.getNumJournalCallbackThreads(),
Copy link
Member

Choose a reason for hiding this comment

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

interesting.. I thought we used OrderedScheduler here as well.

I actually checked twitter's branch, it does use ordered scheduler. I believe cbThreadPool was first introduced by twitter sometime back.

https://github.com/twitter/bookkeeper/blob/master/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java#L577

Copy link
Member

Choose a reason for hiding this comment

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

the change looks good to me though. I just found this difference here.

@sijie
Copy link
Member

sijie commented Mar 14, 2018

retest this please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants