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
[UNDERTOW-1758] make state field atomic in HttpServerExchange #1560
base: 2.2.x
Are you sure you want to change the base?
[UNDERTOW-1758] make state field atomic in HttpServerExchange #1560
Conversation
@@ -165,7 +166,7 @@ public final class HttpServerExchange extends AbstractAttachable { | |||
|
|||
// mutable state | |||
|
|||
private int state = 200; | |||
private AtomicInteger state = new AtomicInteger(200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@burov4j Thanks for your PR!
I would like to follow the same pattern we have in XNIO. Could you instead make the field volatile and add an atomic field updater, like in this class: https://github.com/xnio/xnio/blob/3.x/api/src/main/java/org/xnio/Connection.java ?
This will have a better memory footprint than the currently proposed solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -480,9 +483,9 @@ public HttpServerExchange setRequestURI(final String requestURI) { | |||
public HttpServerExchange setRequestURI(final String requestURI, boolean containsHost) { | |||
this.requestURI = requestURI; | |||
if (containsHost) { | |||
this.state |= FLAG_URI_CONTAINS_HOST; | |||
stateUpdater.accumulateAndGet(this, FLAG_URI_CONTAINS_HOST, (state, flag) -> state | flag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps these lambdas could be extracted to static reusable instances -- sometimes lambdas like this in hot paths aren't elided as quickly as one might wish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a premature optimization?
https://issues.redhat.com/browse/UNDERTOW-1758