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

Pass BookieRequestHandler instead of Channel to the request processors #3835

Merged
merged 6 commits into from
Mar 5, 2023

Conversation

merlimat
Copy link
Contributor

@merlimat merlimat commented Mar 2, 2023

Motivation

This is just a preparatory refactoring change. The final goal is to streamline the send-response path from Journal to the client connections.

We're now passing the Netty Channel object as context for the requests, though that prevents us from adding more state and logic when tracking back to the original connection.

Instead, we can pass BookieRequestHandler where we can potentially add new fields.

@merlimat merlimat added this to the 4.16.0 milestone Mar 2, 2023
Copy link
Contributor

@hangc0276 hangc0276 left a comment

Choose a reason for hiding this comment

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

Nice job!

@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2023

Codecov Report

Merging #3835 (98d681c) into master (b4112df) will increase coverage by 0.06%.
The diff coverage is 84.81%.

@@             Coverage Diff              @@
##             master    #3835      +/-   ##
============================================
+ Coverage     68.21%   68.28%   +0.06%     
+ Complexity     6761     6755       -6     
============================================
  Files           473      473              
  Lines         40950    40967      +17     
  Branches       5240     5243       +3     
============================================
+ Hits          27935    27974      +39     
+ Misses        10762    10731      -31     
- Partials       2253     2262       +9     
Flag Coverage Δ
bookie 39.84% <58.22%> (+0.01%) ⬆️
client 44.17% <75.94%> (-0.03%) ⬇️
remaining 29.66% <34.17%> (+0.14%) ⬆️
replication 41.33% <65.82%> (+0.03%) ⬆️
tls 20.99% <50.63%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...g/apache/bookkeeper/proto/PacketProcessorBase.java 50.49% <45.45%> (-4.72%) ⬇️
...rg/apache/bookkeeper/proto/ReadEntryProcessor.java 51.45% <66.66%> (+0.47%) ⬆️
.../apache/bookkeeper/proto/ReadEntryProcessorV3.java 64.82% <80.00%> (+0.24%) ⬆️
...pache/bookkeeper/proto/BookieRequestProcessor.java 74.46% <90.90%> (+0.27%) ⬆️
.../apache/bookkeeper/proto/BookieRequestHandler.java 76.00% <100.00%> (+2.08%) ⬆️
...pache/bookkeeper/proto/ForceLedgerProcessorV3.java 49.09% <100.00%> (ø)
...che/bookkeeper/proto/GetBookieInfoProcessorV3.java 77.77% <100.00%> (ø)
...per/proto/GetListOfEntriesOfLedgerProcessorV3.java 76.74% <100.00%> (ø)
...bookkeeper/proto/LongPollReadEntryProcessorV3.java 56.38% <100.00%> (ø)
...apache/bookkeeper/proto/PacketProcessorBaseV3.java 81.13% <100.00%> (+0.36%) ⬆️
... and 36 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@merlimat merlimat merged commit dfde3d6 into apache:master Mar 5, 2023
hangc0276 pushed a commit that referenced this pull request Mar 7, 2023
### Motivation

Note: this is stacked on top of #3830 & #3835

This change improves the way the AddRequests responses are send to client. 

The current flow is: 
 * The journal-force-thread issues the fsync on the journal file
 * We iterate over all the entries that were just synced and for each of them:
     1. Trigger channel.writeAndFlus()
     2. This will jump on the connection IO thread (Netty will use a `write()` to `eventfd` to post the task and wake the epoll)
     3. Write the object in the connection and trigger the serialization logic
     4. Grab a `ByteBuf` from the pool and write ~20 bytes with the response
     5. Write and flush the buffer on the channel
     6. With the flush consolidator we try to group multiple buffer into a single `writev()` syscall, though each call will have a long list of buffer, making the memcpy inefficient.
     7. Release all the buffers and return them to the pool

All these steps are quite expensive when the bookie is receiving a lot of small requests. 

This PR changes the flow into: 

1. journal fsync
2. go through each request and prepare the response into a per-connection `ByteBuf` which is not written on the channel as of yet
3. after preparing all the responses, we flush them at once: Trigger an event on all the connections that will write the accumulated buffers.

The advantages are: 
 1. 1 ByteBuf allocated per connection instead of 1 per request
    1. Less allocations and stress of buffer pool
    2. More efficient socket write() operations
 3. 1 task per connection posted on the Netty IO threads, instead of 1 per request.
Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024
apache#3835)

* Pass BookieRequestHandler instead of Channel to the request processors

* Fixed checkstyle

* Fixed ForceLedgerProcessorV3Test

* Fixed TestBookieRequestProcessor

* Fixed line length
Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024
### Motivation

Note: this is stacked on top of apache#3830 & apache#3835

This change improves the way the AddRequests responses are send to client. 

The current flow is: 
 * The journal-force-thread issues the fsync on the journal file
 * We iterate over all the entries that were just synced and for each of them:
     1. Trigger channel.writeAndFlus()
     2. This will jump on the connection IO thread (Netty will use a `write()` to `eventfd` to post the task and wake the epoll)
     3. Write the object in the connection and trigger the serialization logic
     4. Grab a `ByteBuf` from the pool and write ~20 bytes with the response
     5. Write and flush the buffer on the channel
     6. With the flush consolidator we try to group multiple buffer into a single `writev()` syscall, though each call will have a long list of buffer, making the memcpy inefficient.
     7. Release all the buffers and return them to the pool

All these steps are quite expensive when the bookie is receiving a lot of small requests. 

This PR changes the flow into: 

1. journal fsync
2. go through each request and prepare the response into a per-connection `ByteBuf` which is not written on the channel as of yet
3. after preparing all the responses, we flush them at once: Trigger an event on all the connections that will write the accumulated buffers.

The advantages are: 
 1. 1 ByteBuf allocated per connection instead of 1 per request
    1. Less allocations and stress of buffer pool
    2. More efficient socket write() operations
 3. 1 task per connection posted on the Netty IO threads, instead of 1 per request.
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