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

Cleanup Listener Handling in AuthorizationService #75252

Merged

Conversation

original-brownbear
Copy link
Member

Two parts here from analyzing auth slowness in recent SDHs:

  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.
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Jul 12, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

authorizedIndicesSupplier.getAsync(
ActionListener.wrap(
authorizedIndices ->
resolvedIndicesListener.onResponse(
Copy link
Member Author

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;
Copy link
Contributor

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.

Suggested change
boolean addedListener = false;
boolean firstInvocation = false;

Comment on lines +377 to +389
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);
}
}
}
);
Copy link
Member

Choose a reason for hiding this comment

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

👍

@original-brownbear
Copy link
Member Author

Thanks Tim!

@original-brownbear original-brownbear merged commit 6912832 into elastic:master Jul 13, 2021
@original-brownbear original-brownbear deleted the simplify-async-supplier branch July 13, 2021 09:09
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Jul 13, 2021
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.
original-brownbear added a commit that referenced this pull request Jul 13, 2021
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.
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Jul 24, 2021
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.
original-brownbear added a commit that referenced this pull request Jul 29, 2021
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.
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Jul 29, 2021
…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.
original-brownbear added a commit that referenced this pull request Jul 29, 2021
…75833)

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.
ywangd pushed a commit to ywangd/elasticsearch that referenced this pull request Jul 30, 2021
…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.
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Apr 18, 2023
Same problem as in elastic#75252 addressed, also introduced some constants to reduce code size
in hot methods.
@original-brownbear original-brownbear restored the simplify-async-supplier branch April 18, 2023 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC Team:Security Meta label for security team v7.15.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants