bookkeeper icon indicating copy to clipboard operation
bookkeeper copied to clipboard

[improve] [client] Group read/write response when jumping to the ordered executor

Open hangc0276 opened this issue 2 years ago • 1 comments

Motivation

When the PerChannelBookieClient receives read/write responses from the Bookie server, it processes those responses one by one with the following pipeline

  • Get the CompletionValue according to the CompletionKey
  • Jump to the ordered executor the run the callback

https://github.com/apache/bookkeeper/blob/cbd634dbe0c894474a934fab6d8711588ad94114/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java#L1353-L1374

If there are 1000 responses, we need to jump 1000 times into the ordered executor and cause 1000 times thread context switches.

Design

We can group those responses according to whether the Netty socket channel is empty. We initiate a Blocking Queue to buffer all the responses, and the default capacity is 1_000. There are two conditions that will trigger the response process.

  • The Blocking queue is full
  • The Netty socket channel is empty and the channelReadComplete is called.

If we buffered 1_000 responses in the queue, we will reduce 1_000 times thread context switch if those responses are hashed to the same thread to execute.

hangc0276 avatar Mar 27 '23 13:03 hangc0276

I see this is only for v2, it does not work for v3?

ytong01 avatar Nov 15 '23 10:11 ytong01