-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Cleanup Listener Handling in AuthorizationService #75252
Cleanup Listener Handling in AuthorizationService #75252
Conversation
Two parts here: 1. Don't synchonize on the async supplier. Even though these aren't actually async yet it seeems, the synchronization wouldn't work anyway if they were. If this were to be called concurrently the current approach would cause blocking needlessly though. Either way, synchonizing ever call and all the downstream calls is just unnecessarily hard on the JIT here. 2. The async look over the interceptors was needlessly slow with all the synchronization etc. in the `StepListener`. Also it made the stacktraces on transport thread extremely deep and complicated. Simplified and made this faster by using a normal listener/iterator without any synchronization.
Pinging @elastic/es-security (Team:Security) |
authorizedIndicesSupplier.getAsync( | ||
ActionListener.wrap( | ||
authorizedIndices -> | ||
resolvedIndicesListener.onResponse( |
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.
inlined this to make the stack-trace one less deep and generally make the logic easier to follow, no need to have a method to resolve a listener when the method is blocking and one line anyway :)
listener.onResponse(value); | ||
public void getAsync(ActionListener<V> listener) { | ||
if (valueFuture == null) { | ||
boolean addedListener = false; |
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.
Nit: addedListener
doesn't seem to quite fit the usage here.
boolean addedListener = false; | |
boolean firstInvocation = false; |
final Iterator<RequestInterceptor> requestInterceptorIterator = requestInterceptors.iterator(); | ||
requestInterceptorIterator.next().intercept(requestInfo, authorizationEngine, authorizationInfo, | ||
new ActionListener.Delegating<>(listener) { | ||
@Override | ||
public void onResponse(Void unused) { | ||
if (requestInterceptorIterator.hasNext()) { | ||
requestInterceptorIterator.next().intercept(requestInfo, authorizationEngine, authorizationInfo, this); | ||
} else { | ||
listener.onResponse(null); | ||
} | ||
} | ||
} | ||
); |
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.
👍
Thanks Tim! |
Two parts here: 1. Don't synchonize on the async supplier. Even though these aren't actually async yet it seeems, the synchronization wouldn't work anyway if they were. If this were to be called concurrently the current approach would cause blocking needlessly though. Either way, synchonizing ever call and all the downstream calls is just unnecessarily hard on the JIT here. 2. The async look over the interceptors was needlessly slow with all the synchronization etc. in the `StepListener`. Also it made the stacktraces on transport thread extremely deep and complicated. Simplified and made this faster by using a normal listener/iterator without any synchronization.
Two parts here: 1. Don't synchonize on the async supplier. Even though these aren't actually async yet it seeems, the synchronization wouldn't work anyway if they were. If this were to be called concurrently the current approach would cause blocking needlessly though. Either way, synchonizing ever call and all the downstream calls is just unnecessarily hard on the JIT here. 2. The async look over the interceptors was needlessly slow with all the synchronization etc. in the `StepListener`. Also it made the stacktraces on transport thread extremely deep and complicated. Simplified and made this faster by using a normal listener/iterator without any synchronization.
Same as elastic#75252 pretty much just continuing to make this logic a little simpler for easier profiling and (very) maybe performance through saving some allocations/indirection.
Same as #75252 pretty much just continuing to make this logic a little simpler for easier profiling and (very) maybe performance through saving some allocations/indirection.
…5662) Same as elastic#75252 pretty much just continuing to make this logic a little simpler for easier profiling and (very) maybe performance through saving some allocations/indirection.
…5662) Same as elastic#75252 pretty much just continuing to make this logic a little simpler for easier profiling and (very) maybe performance through saving some allocations/indirection.
Same problem as in elastic#75252 addressed, also introduced some constants to reduce code size in hot methods.
Two parts here from analyzing auth slowness in recent SDHs:
actually async yet it seeems, the synchronization wouldn't work anyway
if they were. If this were to be called concurrently the current approach would cause
blocking needlessly though. Either way, synchonizing ever call and all the downstream calls
is just unnecessarily hard on the JIT here.
in the
StepListener
. Also it made the stacktraces on transport thread extremely deep and complicated.Simplified and made this faster by using a normal listener/iterator without any synchronization.