This is an automated email from the ASF dual-hosted git repository.
lucasbru pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new dfd996e51e0 KAFKA-18336: Improve jmh tests on ACL in
AuthorizerBenchmark and StandardAuthorizerUpdateBenchmark (#18293)
dfd996e51e0 is described below
commit dfd996e51e0d69a9872492ee63fce12a40882d59
Author: Evgeniy Kuvardin <[email protected]>
AuthorDate: Tue Jul 22 12:07:07 2025 +0300
KAFKA-18336: Improve jmh tests on ACL in AuthorizerBenchmark and
StandardAuthorizerUpdateBenchmark (#18293)
1. JMH test should return value against return void (compiler can
eliminate returned value and benchmark would be incorrect).
2. Also move constant variable from method to class, to prevent JIT to
unfold.
3. Increase warm up iterations
Reviewers: Lucas Brutschy <[email protected]>
---
.../org/apache/kafka/jmh/acl/AuthorizerBenchmark.java | 19 +++++++++++++------
.../jmh/acl/StandardAuthorizerUpdateBenchmark.java | 8 ++++----
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git
a/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/acl/AuthorizerBenchmark.java
b/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/acl/AuthorizerBenchmark.java
index 4ef4721c823..6d4536301f5 100644
---
a/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/acl/AuthorizerBenchmark.java
+++
b/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/acl/AuthorizerBenchmark.java
@@ -36,6 +36,7 @@ import org.apache.kafka.common.security.auth.SecurityProtocol;
import org.apache.kafka.metadata.authorizer.StandardAcl;
import org.apache.kafka.metadata.authorizer.StandardAuthorizer;
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;
@@ -87,6 +88,9 @@ 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;
@@ -94,6 +98,9 @@ public class AuthorizerBenchmark {
@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`
@@ -196,17 +203,17 @@ public class AuthorizerBenchmark {
}
@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);
}
}
diff --git
a/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/acl/StandardAuthorizerUpdateBenchmark.java
b/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/acl/StandardAuthorizerUpdateBenchmark.java
index a94a296c68b..96a5f62da39 100644
---
a/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/acl/StandardAuthorizerUpdateBenchmark.java
+++
b/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/acl/StandardAuthorizerUpdateBenchmark.java
@@ -54,8 +54,8 @@ import static
org.apache.kafka.common.acl.AclPermissionType.ALLOW;
@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 {
@@ -71,13 +71,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();
}