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

[improve][proxy] Remove unnecessary executor callback; use assert #19670

Conversation

michaeljmarshall
Copy link
Member

Motivation

The DirectProxyHandler and the ProxyConnection are run in the same event loop to prevent context switching. As such, we do not need to schedule an event onto an event loop that is in fact the same event loop. Further, scheduling on that event loop could have resulted in uncaught failures because the method was run without any error handling.

Additionally, we can use assert to verify that we are in the event loop. Netty makes extensive use of this paradigm, as described in this PR #19653. The primary benefit here is that we skip some unnecessary volatile reads when running the code in production.

Modifications

  • Replace checkState with assert in ProxyConnection class
  • Remove unnecessary event execution in callback when starting up the DirectProxyHandler.

Verifying this change

This change is covered by the assertions that are added.

Does this pull request potentially affect one of the following parts:

This is a minor improvement that should not break anything.

Documentation

  • doc-not-needed

Matching PR in forked repository

PR in forked repository: michaeljmarshall#33

@michaeljmarshall michaeljmarshall added type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages area/proxy labels Mar 1, 2023
@michaeljmarshall michaeljmarshall added this to the 3.0.0 milestone Mar 1, 2023
@michaeljmarshall michaeljmarshall self-assigned this Mar 1, 2023
@michaeljmarshall michaeljmarshall added the doc-not-needed Your PR changes do not impact docs label Mar 1, 2023
@@ -401,18 +400,21 @@ private void handleBrokerConnected(DirectProxyHandler directProxyHandler, Comman
}

private void connectToBroker(InetSocketAddress brokerAddress) {
checkState(ctx.executor().inEventLoop(), "This method should be called in the event loop");
assert ctx.executor().inEventLoop();
Copy link
Contributor

Choose a reason for hiding this comment

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

"assert" is not enabled in production
I am not sure that we enable Java assertion in tests

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. I had opened #19653, but @lhotari pointed out that it is already enabled by surefire.

@michaeljmarshall michaeljmarshall merged commit 164add6 into apache:master Mar 20, 2023
@michaeljmarshall michaeljmarshall deleted the assert-thread-proxy-connection branch April 3, 2023 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/proxy doc-not-needed Your PR changes do not impact docs ready-to-test type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants