forked from apache/kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kafka 9626: Improve ACLAuthorizer.acls() performance
This PR avoids creation of unnecessary sets in AclAuthorizer.acls() method implementation. Perf results: **Old** ``` Benchmark (aclCount) (resourceCount) Mode Cnt Score Error Units AclAuthorizerBenchmark.testAclsIterator 5 5000 avgt 15 5.821 ? 0.309 ms/op AclAuthorizerBenchmark.testAclsIterator 5 10000 avgt 15 15.303 ? 0.107 ms/op AclAuthorizerBenchmark.testAclsIterator 5 50000 avgt 15 74.976 ? 0.543 ms/op AclAuthorizerBenchmark.testAclsIterator 10 5000 avgt 15 15.366 ? 0.184 ms/op AclAuthorizerBenchmark.testAclsIterator 10 10000 avgt 15 29.899 ? 0.129 ms/op AclAuthorizerBenchmark.testAclsIterator 10 50000 avgt 15 167.301 ? 1.723 ms/op AclAuthorizerBenchmark.testAclsIterator 15 5000 avgt 15 21.980 ? 0.114 ms/op AclAuthorizerBenchmark.testAclsIterator 15 10000 avgt 15 44.385 ? 0.255 ms/op AclAuthorizerBenchmark.testAclsIterator 15 50000 avgt 15 241.919 ? 3.955 ms/op ``` **New** ``` Benchmark (aclCount) (resourceCount) Mode Cnt Score Error Units AclAuthorizerBenchmark.testAclsIterator 5 5000 avgt 15 0.666 ? 0.004 ms/op AclAuthorizerBenchmark.testAclsIterator 5 10000 avgt 15 1.427 ? 0.015 ms/op AclAuthorizerBenchmark.testAclsIterator 5 50000 avgt 15 21.410 ? 0.225 ms/op AclAuthorizerBenchmark.testAclsIterator 10 5000 avgt 15 1.230 ? 0.018 ms/op AclAuthorizerBenchmark.testAclsIterator 10 10000 avgt 15 4.303 ? 0.744 ms/op AclAuthorizerBenchmark.testAclsIterator 10 50000 avgt 15 36.724 ? 0.409 ms/op AclAuthorizerBenchmark.testAclsIterator 15 5000 avgt 15 2.433 ? 0.379 ms/op AclAuthorizerBenchmark.testAclsIterator 15 10000 avgt 15 9.818 ? 0.214 ms/op AclAuthorizerBenchmark.testAclsIterator 15 50000 avgt 15 52.886 ? 0.525 ms/op ``` Author: Manikumar Reddy <[email protected]> Author: Lucas Bradstreet <[email protected]> Reviewers: Ismael Juma <[email protected]>, Rajini Sivaram <[email protected]>, Lucas Bradstreet <[email protected]> Closes apache#8199 from omkreddy/KAFKA-9626
- Loading branch information
Showing
4 changed files
with
138 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
jmh-benchmarks/src/main/java/org/apache/kafka/jmh/acl/AclAuthorizerBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.kafka.jmh.acl; | ||
|
||
import kafka.security.authorizer.AclAuthorizer; | ||
import kafka.security.authorizer.AclAuthorizer.VersionedAcls; | ||
import kafka.security.authorizer.AclEntry; | ||
import org.apache.kafka.common.acl.AccessControlEntry; | ||
import org.apache.kafka.common.acl.AclBindingFilter; | ||
import org.apache.kafka.common.acl.AclOperation; | ||
import org.apache.kafka.common.acl.AclPermissionType; | ||
import org.apache.kafka.common.resource.PatternType; | ||
import org.apache.kafka.common.resource.ResourcePattern; | ||
import org.apache.kafka.common.resource.ResourceType; | ||
import org.apache.kafka.common.security.auth.KafkaPrincipal; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.TearDown; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import scala.collection.JavaConverters; | ||
import scala.collection.immutable.TreeMap; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@State(Scope.Benchmark) | ||
@Fork(value = 1) | ||
@Warmup(iterations = 5) | ||
@Measurement(iterations = 15) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
|
||
public class AclAuthorizerBenchmark { | ||
@Param({"5000", "10000", "50000"}) | ||
private int resourceCount; | ||
//no. of. rules per resource | ||
@Param({"5", "10", "15"}) | ||
private int aclCount; | ||
|
||
private AclAuthorizer aclAuthorizer = new AclAuthorizer(); | ||
private KafkaPrincipal principal = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, "test-user"); | ||
|
||
@Setup(Level.Trial) | ||
public void setup() throws Exception { | ||
setFieldValue(aclAuthorizer, AclAuthorizer.class.getDeclaredField("aclCache").getName(), | ||
prepareAclCache()); | ||
} | ||
|
||
private void setFieldValue(Object obj, String fieldName, Object value) throws Exception { | ||
Field field = obj.getClass().getDeclaredField(fieldName); | ||
field.setAccessible(true); | ||
field.set(obj, value); | ||
} | ||
|
||
private TreeMap<ResourcePattern, VersionedAcls> prepareAclCache() { | ||
Map<ResourcePattern, Set<AclEntry>> aclEntries = new HashMap<>(); | ||
for (int resourceId = 0; resourceId < resourceCount; resourceId++) { | ||
|
||
ResourcePattern resource = new ResourcePattern( | ||
(resourceId % 10 == 0) ? ResourceType.GROUP : ResourceType.TOPIC, | ||
"resource-" + resourceId, | ||
(resourceId % 5 == 0) ? PatternType.PREFIXED : PatternType.LITERAL); | ||
|
||
Set<AclEntry> entries = aclEntries.computeIfAbsent(resource, k -> new HashSet<>()); | ||
|
||
for (int aclId = 0; aclId < aclCount; aclId++) { | ||
AccessControlEntry ace = new AccessControlEntry(principal.toString() + aclId, | ||
"*", AclOperation.READ, AclPermissionType.ALLOW); | ||
entries.add(new AclEntry(ace)); | ||
} | ||
} | ||
|
||
TreeMap<ResourcePattern, VersionedAcls> aclCache = new TreeMap<>(new AclAuthorizer.ResourceOrdering()); | ||
for (Map.Entry<ResourcePattern, Set<AclEntry>> entry : aclEntries.entrySet()) { | ||
aclCache = aclCache.updated(entry.getKey(), | ||
new VersionedAcls(JavaConverters.asScalaSetConverter(entry.getValue()).asScala().toSet(), 1)); | ||
} | ||
|
||
return aclCache; | ||
} | ||
|
||
@TearDown(Level.Trial) | ||
public void tearDown() { | ||
aclAuthorizer.close(); | ||
} | ||
|
||
@Benchmark | ||
public void testAclsIterator() { | ||
aclAuthorizer.acls(AclBindingFilter.ANY); | ||
} | ||
} |