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

Pin order executor in LedgerHandle #3738

Merged
merged 2 commits into from
Jul 13, 2023

Conversation

AnonHxy
Copy link
Contributor

@AnonHxy AnonHxy commented Jan 16, 2023

Descriptions of the changes in this PR:

Motivation

Pin the order executor in LedgerHandle to save the choose thread overhead. For details reason:

We could call executeOrdered() frequently, e.g., when in asyncReadEntries. And we would compute the thread index from ledgerId every time when call executeOrdered(). So pin the order executor will save the thread index compution time.

Changes

  • Choose the order executor in LedgerHandle constructor method and save it as a final field
  • Override getMainWorkerPool() in MockBookKeeper to fix UT NPE exception when call this.executor = clientCtx.getMainWorkerPool().chooseThread(ledgerId);

@AnonHxy
Copy link
Contributor Author

AnonHxy commented Jan 16, 2023

rerun failure checks

@AnonHxy
Copy link
Contributor Author

AnonHxy commented Jan 16, 2023

PTAL @StevenLuMT @eolivelli

@hangc0276
Copy link
Contributor

@AnonHxy Would you please provide more context about the reason to pin the executor? thanks.

@AnonHxy
Copy link
Contributor Author

AnonHxy commented Jan 17, 2023

@AnonHxy Would you please provide more context about the reason to pin the executor? thanks.

Sure. It was inspired by this PR apache/pulsar#18078. and I have provided more detail reasons in the descriptions of this PR @hangc0276

@AnonHxy
Copy link
Contributor Author

AnonHxy commented Jan 21, 2023

PTAL @hangc0276 @eolivelli , thanks

Copy link
Member

@StevenLuMT StevenLuMT left a comment

Choose a reason for hiding this comment

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

when the execution mode changes, the performance change significantly ? ledgerID will block reading. Is it expected?

@AnonHxy
Copy link
Contributor Author

AnonHxy commented Jan 28, 2023

when the execution mode changes, the performance change significantly ? ledgerID will block reading. Is it expected?

I think this patch will not change the executeion mode. It just make the execute thread as a final field, which is a obvious improvement. But I am not sure how much can be improved. @StevenLuMT

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.

Overall LGTM. This change saves the cost of choosing threads in executeOrdered, and I wonder if choosing threads costs a lot of CPU resources and whether this change can improve the performance or not.

@AnonHxy
Copy link
Contributor Author

AnonHxy commented Jan 29, 2023

Overall LGTM. This change saves the cost of choosing threads in executeOrdered, and I wonder if choosing threads costs a lot of CPU resources and whether this change can improve the performance or not.

I tested it using one bookie client to add entry async like following. It looks that it was not a significant improvement from the result.

 for (int i = 0; i < Integer.MAX_VALUE; ++i) {
                handle.asyncAddEntry("Some entry data".getBytes(), new AsyncCallback.AddCallback() {
                    @Override
                    public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {

                    }
                }, null);
 }

@hangc0276
Copy link
Contributor

hangc0276 commented Jan 31, 2023

Overall LGTM. This change saves the cost of choosing threads in executeOrdered, and I wonder if choosing threads costs a lot of CPU resources and whether this change can improve the performance or not.

I tested it using one bookie client to add entry async like following. It looks that it was not a significant improvement from the result.

 for (int i = 0; i < Integer.MAX_VALUE; ++i) {
                handle.asyncAddEntry("Some entry data".getBytes(), new AsyncCallback.AddCallback() {
                    @Override
                    public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {

                    }
                }, null);
 }

@AnonHxy If there is no significant performance improvement, I think we can hold on this change.

@hangc0276
Copy link
Contributor

@AnonHxy Do you have any updates?

@AnonHxy
Copy link
Contributor Author

AnonHxy commented May 4, 2023

I think we can hold on this change.

OK. But I think this change is a positive optimization anyway, while the proform result is not obvious ... @hangc0276

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.

LGTM

Copy link
Member

@StevenLuMT StevenLuMT left a comment

Choose a reason for hiding this comment

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

Good catch,LGTM

@AnonHxy
Copy link
Contributor Author

AnonHxy commented Jul 13, 2023

@eolivelli @dlg99 @merlimat PTAL, thanks:)

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

@eolivelli eolivelli merged commit d85e990 into apache:master Jul 13, 2023
Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants