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

KAFKA-18336: Improve jmh tests on ACL in AuthorizerBenchmark and StandardAuthorizerUpdateBenchmark #18293

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.kafka.security.authorizer.AclEntry;
import org.apache.kafka.server.authorizer.Action;

import org.apache.kafka.server.authorizer.AuthorizationResult;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand Down Expand Up @@ -89,13 +90,19 @@ public class AuthorizerBenchmark {
private List<Action> actions = new ArrayList<>();
private RequestContext authorizeContext;
private RequestContext authorizeByResourceTypeContext;
private AclBindingFilter filter;
private AclOperation op;
private ResourceType resourceType;

Random rand = new Random(System.currentTimeMillis());
double eps = 1e-9;

@Setup(Level.Trial)
public void setup() throws Exception {
authorizer = new StandardAuthorizer();
filter = AclBindingFilter.ANY;
op = AclOperation.READ;
resourceType = ResourceType.TOPIC;
prepareAclCache();
// By adding `-95` to the resource name prefix, we cause the `TreeMap.from/to` call to return
// most map entries. In such cases, we rely on the filtering based on `String.startsWith`
Expand Down Expand Up @@ -204,17 +211,17 @@ public void tearDown() throws IOException {
}

@Benchmark
public void testAclsIterator() {
authorizer.acls(AclBindingFilter.ANY);
public Iterable<AclBinding> testAclsIterator() {
return authorizer.acls(filter);
}

@Benchmark
public void testAuthorizer() {
authorizer.authorize(authorizeContext, actions);
public List<AuthorizationResult> testAuthorizer() {
return authorizer.authorize(authorizeContext, actions);
}

@Benchmark
public void testAuthorizeByResourceType() {
authorizer.authorizeByResourceType(authorizeByResourceTypeContext, AclOperation.READ, ResourceType.TOPIC);
public AuthorizationResult testAuthorizeByResourceType() {
return authorizer.authorizeByResourceType(authorizeByResourceTypeContext, op, resourceType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@

@State(Scope.Benchmark)
@Fork(value = 1)
@Warmup(iterations = 0)
@Measurement(iterations = 4)
@Warmup(iterations = 7, timeUnit = TimeUnit.SECONDS, time = 2)
@Measurement(iterations = 10, timeUnit = TimeUnit.SECONDS, time = 2)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class StandardAuthorizerUpdateBenchmark {
Expand All @@ -72,13 +72,13 @@ public class StandardAuthorizerUpdateBenchmark {
private int aclCount;
int index = 0;

@Setup(Level.Trial)
@Setup(Level.Iteration)
public void setup() throws Exception {
authorizer = new StandardAuthorizer();
addAcls(aclCount);
}

@TearDown(Level.Trial)
@TearDown(Level.Iteration)
public void tearDown() throws IOException {
authorizer.close();
}
Expand Down
Loading