Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2024-03-04 Thread via GitHub


github-actions[bot] commented on PR #14597:
URL: https://github.com/apache/kafka/pull/14597#issuecomment-1977907333

   This PR is being marked as stale since it has not had any activity in 90 
days. If you would like to keep this PR alive, please ask a committer for 
review. If the PR has  merge conflicts, please update it with the latest from 
trunk (or appropriate release branch)  If this PR is no longer valid or 
desired, please feel free to close it. If no activity occurs in the next 30 
days, it will be automatically closed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on PR #14597:
URL: https://github.com/apache/kafka/pull/14597#issuecomment-1840520823

   > Thanks for the PR. There are a number of changes in this PR - which ones 
actually made a difference to the numbers? Some of them are a bit questionable.
   
   1. The main performance boost was from the `A.hashcode() != B.hashcode()` 
check. 
   2. Then the acl change to an array significantly improved the performance 
since it avoided boolean boxing/unboxing and the nested Seq iterator. 
   3. Then the Set change in the AclAuthorizer.scala which was called often in 
the inner loop.
   
   
   
   Then the performance became harder to gain and this results in a bit more 
questionable optimizations. Which actually came out of the benchmarks. 
   
   - enum comparison speed had a memory alignment issue and comparing by code 
was just faster in general.
   - improving the string compare performance for USER_TYPE by sharing the same 
reference. this might not have been that significant.
   
   I only committed changes which actually resulted in performance 
improvements. I tried to change the enum to a 'flag' type with the values `1, 
2, 8, 16, 32` but this didn't make any difference. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415344533


##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -409,9 +411,13 @@ class AclAuthorizer extends Authorizer with Logging {
 principal: String, host: String, op: 
AclOperation, permission: AclPermissionType,
 resourceType: ResourceType, patternType: 
PatternType): ArrayBuffer[Set[String]] = {
 val matched = ArrayBuffer[immutable.Set[String]]()
-for (p <- Set(principal, AclEntry.WildcardPrincipalString);
- h <- Set(host, AclEntry.WildcardHost);
- o <- Set(op, AclOperation.ALL)) {
+val ps = if (principal == AclEntry.WildcardPrincipalString) 
Array(AclEntry.WildcardPrincipalString) else Array(principal, 
AclEntry.WildcardPrincipalString)

Review Comment:
   creating and merging and iterating sets was significant slower then 
iterating arrays. The jvm was not able to optimize this away. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415317427


##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -61,18 +60,18 @@ object AclAuthorizer {
   val AllowEveryoneIfNoAclIsFoundProp = "allow.everyone.if.no.acl.found"
 
   case class VersionedAcls(acls: Set[AclEntry], zkVersion: Int) {
+// iterating a set is slow, add an array view on the set.
+lazy val aclsArray = acls.toArray

Review Comment:
   this also had a significant speed up since iterating seq is slow. But the 
acls are only updated a few times while the iteration through them is done 
often. 
   



##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -331,12 +330,15 @@ class AclAuthorizer extends Authorizer with Logging {
   }
 
   override def acls(filter: AclBindingFilter): lang.Iterable[AclBinding] = {
-val aclBindings = new util.ArrayList[AclBinding]()
-aclCache.forKeyValue { case (resource, versionedAcls) =>
-  versionedAcls.acls.foreach { acl =>
-val binding = new AclBinding(resource, acl.ace)
-if (filter.matches(binding))
-  aclBindings.add(binding)
+val aclBindings = new util.ArrayList[AclBinding](32)

Review Comment:
   the preinitialization of the size is indeed questionable. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415349250


##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -563,15 +570,20 @@ class AclAuthorizer extends Authorizer with Logging {
 host: String,
 permissionType: AclPermissionType,
 acls: AclSeqs): Boolean = {
-acls.find { acl =>
-  acl.permissionType == permissionType &&
-(acl.kafkaPrincipal == principal || acl.kafkaPrincipal == 
AclEntry.WildcardPrincipal) &&
-(operation == acl.operation || acl.operation == AclOperation.ALL) &&
-(acl.host == host || acl.host == AclEntry.WildcardHost)
-}.exists { acl =>
-  authorizerLogger.debug(s"operation = $operation on resource = $resource 
from host = $host is $permissionType based on acl = $acl")
-  true
-}
+
+acls.exists { acl =>

Review Comment:
   i think this change was a code improvement, but also avoided a few 
allocations.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415344533


##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -409,9 +411,13 @@ class AclAuthorizer extends Authorizer with Logging {
 principal: String, host: String, op: 
AclOperation, permission: AclPermissionType,
 resourceType: ResourceType, patternType: 
PatternType): ArrayBuffer[Set[String]] = {
 val matched = ArrayBuffer[immutable.Set[String]]()
-for (p <- Set(principal, AclEntry.WildcardPrincipalString);
- h <- Set(host, AclEntry.WildcardHost);
- o <- Set(op, AclOperation.ALL)) {
+val ps = if (principal == AclEntry.WildcardPrincipalString) 
Array(AclEntry.WildcardPrincipalString) else Array(principal, 
AclEntry.WildcardPrincipalString)

Review Comment:
   creating and merging and iterating sets was slower then iterating arrays. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415342634


##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -331,12 +330,15 @@ class AclAuthorizer extends Authorizer with Logging {
   }
 
   override def acls(filter: AclBindingFilter): lang.Iterable[AclBinding] = {
-val aclBindings = new util.ArrayList[AclBinding]()
-aclCache.forKeyValue { case (resource, versionedAcls) =>
-  versionedAcls.acls.foreach { acl =>
-val binding = new AclBinding(resource, acl.ace)
-if (filter.matches(binding))
-  aclBindings.add(binding)
+val aclBindings = new util.ArrayList[AclBinding](32)

Review Comment:
   the preinitialization of the size is maybe questionalbe.



##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -331,12 +330,15 @@ class AclAuthorizer extends Authorizer with Logging {
   }
 
   override def acls(filter: AclBindingFilter): lang.Iterable[AclBinding] = {
-val aclBindings = new util.ArrayList[AclBinding]()
-aclCache.forKeyValue { case (resource, versionedAcls) =>
-  versionedAcls.acls.foreach { acl =>
-val binding = new AclBinding(resource, acl.ace)
-if (filter.matches(binding))
-  aclBindings.add(binding)
+val aclBindings = new util.ArrayList[AclBinding](32)

Review Comment:
   the preinitialization of the size is questionable. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415341068


##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -61,18 +60,18 @@ object AclAuthorizer {
   val AllowEveryoneIfNoAclIsFoundProp = "allow.everyone.if.no.acl.found"
 
   case class VersionedAcls(acls: Set[AclEntry], zkVersion: Int) {
+// iterating a set is slow, add an array view on the set.
+lazy val aclsArray = acls.toArray
 def exists: Boolean = zkVersion != ZkVersion.UnknownVersion
   }
 
-  class AclSeqs(seqs: Seq[AclEntry]*) {
-def find(p: AclEntry => Boolean): Option[AclEntry] = {
-  // Lazily iterate through the inner `Seq` elements and stop as soon as 
we find a match
-  val it = seqs.iterator.flatMap(_.find(p))
-  if (it.hasNext) Some(it.next())
-  else None
-}
 
-def isEmpty: Boolean = !seqs.exists(_.nonEmpty)
+  class AclSeqs(val acls: Array[AclEntry]) {

Review Comment:
   having a single array avoids creating a boxed boolean for the isEmpty 
function.
   
   Also nested iteration had slow performance as wel. 



##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -61,18 +60,18 @@ object AclAuthorizer {
   val AllowEveryoneIfNoAclIsFoundProp = "allow.everyone.if.no.acl.found"
 
   case class VersionedAcls(acls: Set[AclEntry], zkVersion: Int) {
+// iterating a set is slow, add an array view on the set.
+lazy val aclsArray = acls.toArray
 def exists: Boolean = zkVersion != ZkVersion.UnknownVersion
   }
 
-  class AclSeqs(seqs: Seq[AclEntry]*) {
-def find(p: AclEntry => Boolean): Option[AclEntry] = {
-  // Lazily iterate through the inner `Seq` elements and stop as soon as 
we find a match
-  val it = seqs.iterator.flatMap(_.find(p))
-  if (it.hasNext) Some(it.next())
-  else None
-}
 
-def isEmpty: Boolean = !seqs.exists(_.nonEmpty)
+  class AclSeqs(val acls: Array[AclEntry]) {

Review Comment:
   having a single array avoids creating a boxed boolean for the isEmpty 
function.
   
   Also nested iteration had slow performance as wel in the find. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415341068


##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -61,18 +60,18 @@ object AclAuthorizer {
   val AllowEveryoneIfNoAclIsFoundProp = "allow.everyone.if.no.acl.found"
 
   case class VersionedAcls(acls: Set[AclEntry], zkVersion: Int) {
+// iterating a set is slow, add an array view on the set.
+lazy val aclsArray = acls.toArray
 def exists: Boolean = zkVersion != ZkVersion.UnknownVersion
   }
 
-  class AclSeqs(seqs: Seq[AclEntry]*) {
-def find(p: AclEntry => Boolean): Option[AclEntry] = {
-  // Lazily iterate through the inner `Seq` elements and stop as soon as 
we find a match
-  val it = seqs.iterator.flatMap(_.find(p))
-  if (it.hasNext) Some(it.next())
-  else None
-}
 
-def isEmpty: Boolean = !seqs.exists(_.nonEmpty)
+  class AclSeqs(val acls: Array[AclEntry]) {

Review Comment:
   having a single array avoids creating a boxed boolean for the isEmpty 
function.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415317427


##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -61,18 +60,18 @@ object AclAuthorizer {
   val AllowEveryoneIfNoAclIsFoundProp = "allow.everyone.if.no.acl.found"
 
   case class VersionedAcls(acls: Set[AclEntry], zkVersion: Int) {
+// iterating a set is slow, add an array view on the set.
+lazy val aclsArray = acls.toArray

Review Comment:
   this also had a significant speed up since iterating sets is slow. But the 
acls are only updated a few times while the iteration through them is done 
often. 
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415317427


##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -61,18 +60,18 @@ object AclAuthorizer {
   val AllowEveryoneIfNoAclIsFoundProp = "allow.everyone.if.no.acl.found"
 
   case class VersionedAcls(acls: Set[AclEntry], zkVersion: Int) {
+// iterating a set is slow, add an array view on the set.
+lazy val aclsArray = acls.toArray

Review Comment:
   this also had a significant speed up since iterating sets is slow.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415314693


##
clients/src/main/java/org/apache/kafka/common/security/auth/KafkaPrincipal.java:
##
@@ -53,7 +53,12 @@ public KafkaPrincipal(String principalType, String name) {
 }
 
 public KafkaPrincipal(String principalType, String name, boolean 
tokenAuthenticated) {
-this.principalType = requireNonNull(principalType, "Principal type 
cannot be null");
+//Sharing USER_TYPE reference.
+if (principalType.equals(USER_TYPE)) {

Review Comment:
   This improves the performance since the principal type is almost always a 
'USER_TYPE'  so you can make sure the same reference is used. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415317427


##
core/src/main/scala/kafka/security/authorizer/AclAuthorizer.scala:
##
@@ -61,18 +60,18 @@ object AclAuthorizer {
   val AllowEveryoneIfNoAclIsFoundProp = "allow.everyone.if.no.acl.found"
 
   case class VersionedAcls(acls: Set[AclEntry], zkVersion: Int) {
+// iterating a set is slow, add an array view on the set.
+lazy val aclsArray = acls.toArray

Review Comment:
   this also had a significant speed up. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415306650


##
clients/src/main/java/org/apache/kafka/common/security/auth/KafkaPrincipal.java:
##
@@ -68,9 +73,15 @@ public boolean equals(Object o) {
 if (this == o) return true;
 if (o == null) return false;
 if (getClass() != o.getClass()) return false;
-
 KafkaPrincipal that = (KafkaPrincipal) o;
-return principalType.equals(that.principalType) && 
name.equals(that.name);
+
+// hashes are cached, so this goes quicker than the string compare
+if (this.hashCode() != o.hashCode()) {

Review Comment:
   You  are correct that they can collide and this has been handeled. The check 
on hash is only used to detect if they are Not equal.
   When the hash is the same the code will do a value compare. 
   ```
   A.hashcode() != B.hashcode() == true => they are not the same 
   A.hashcode() != B.hashcode() == false => they are the same OR they collide
   
   //Hence the check after this to do the value compare:
   return name.equals(that.name) && principalType.equals(that.principalType);
   ```
   
   I think the biggest gain was in the has `if (this.hashCode() != 
o.hashCode()) {` for cases where there where a lot of rejects. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415314693


##
clients/src/main/java/org/apache/kafka/common/security/auth/KafkaPrincipal.java:
##
@@ -53,7 +53,12 @@ public KafkaPrincipal(String principalType, String name) {
 }
 
 public KafkaPrincipal(String principalType, String name, boolean 
tokenAuthenticated) {
-this.principalType = requireNonNull(principalType, "Principal type 
cannot be null");
+//Sharing USER_TYPE reference.
+if (principalType.equals(USER_TYPE)) {

Review Comment:
   This moved the equals check to the initialization of the object. instead of 
the check itself. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415312775


##
clients/src/main/java/org/apache/kafka/common/resource/ResourceType.java:
##
@@ -104,17 +104,18 @@ public static ResourceType fromCode(byte code) {
 return resourceType;
 }
 
-private final byte code;
+//making this int since profiling showed miss alignement.
+private final int code;

Review Comment:
   This improved the performance because the byte was not aligned in memory 
resulting in a slow memory access path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415306650


##
clients/src/main/java/org/apache/kafka/common/security/auth/KafkaPrincipal.java:
##
@@ -68,9 +73,15 @@ public boolean equals(Object o) {
 if (this == o) return true;
 if (o == null) return false;
 if (getClass() != o.getClass()) return false;
-
 KafkaPrincipal that = (KafkaPrincipal) o;
-return principalType.equals(that.principalType) && 
name.equals(that.name);
+
+// hashes are cached, so this goes quicker than the string compare
+if (this.hashCode() != o.hashCode()) {

Review Comment:
   You  are correct that they can collide and this has been handeled. The check 
on hash is only used to detect if they are Not equal.
   When the hash is the same the code will do a value compare. 
   ```
   A.hashcode() != B.hashcode() == true => they are not the same 
   A.hashcode() != B.hashcode() == false => they are the same OR they collide
   
   //Hence the check after this to do the value compare:
   return name.equals(that.name) && principalType.equals(that.principalType);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-12-05 Thread via GitHub


borisssmidtCET commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1415306650


##
clients/src/main/java/org/apache/kafka/common/security/auth/KafkaPrincipal.java:
##
@@ -68,9 +73,15 @@ public boolean equals(Object o) {
 if (this == o) return true;
 if (o == null) return false;
 if (getClass() != o.getClass()) return false;
-
 KafkaPrincipal that = (KafkaPrincipal) o;
-return principalType.equals(that.principalType) && 
name.equals(that.name);
+
+// hashes are cached, so this goes quicker than the string compare
+if (this.hashCode() != o.hashCode()) {

Review Comment:
   You  are correct that they can collide, but if the hashCode of 2 strings 
don't match then they are for sure not the same.
   I.e. 
   ```
   A.hashcode() != B.hashcode() == true => they are not the same 
   A.hashcode() != B.hashcode() == false => they are the same OR they collide
   
   //Hence the check after this to do the value compare:
   return name.equals(that.name) && principalType.equals(that.principalType);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-10-21 Thread via GitHub


ijuma commented on code in PR #14597:
URL: https://github.com/apache/kafka/pull/14597#discussion_r1367722984


##
clients/src/main/java/org/apache/kafka/common/security/auth/KafkaPrincipal.java:
##
@@ -68,9 +73,15 @@ public boolean equals(Object o) {
 if (this == o) return true;
 if (o == null) return false;
 if (getClass() != o.getClass()) return false;
-
 KafkaPrincipal that = (KafkaPrincipal) o;
-return principalType.equals(that.principalType) && 
name.equals(that.name);
+
+// hashes are cached, so this goes quicker than the string compare
+if (this.hashCode() != o.hashCode()) {

Review Comment:
   This is incorrect - hashCode can have collisions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-10-21 Thread via GitHub


ijuma commented on PR #14597:
URL: https://github.com/apache/kafka/pull/14597#issuecomment-1773777853

   Thanks for the PR. There are a number of changes in this PR - which ones 
actually made a difference to the numbers? Some of them are a bit questionable.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[PR] Improve benchmark settings to speed up benchmarking [kafka]

2023-10-20 Thread via GitHub


borisssmidtCET opened a new pull request, #14597:
URL: https://github.com/apache/kafka/pull/14597

   *More detailed description of your change,
   This PR makes the ACL Authorizer significantly faster.
   // before
   ```
   Benchmark(aclCount)  
(authorizerType)  (denyPercentage)  (resourceCount)  Mode  CntScore 
Error  Units
   AuthorizerBenchmark.testAclsIterator500   
ACL50 5000  avgt7  278.920 ±  28.651  ms/op
   AuthorizerBenchmark.testAuthorizeByResourceType 500   
ACL50 5000  avgt74.614 ±   1.076  ms/op
   AuthorizerBenchmark.testAuthorizer  500   
ACL50 5000  avgt70.185 ±   0.045  ms/op
   AuthorizerBenchmark.testUpdateCache 500   
ACL50 5000  avgt7  641.337 ± 123.786  ms/op
   
   ```
   // after
   ```
   Benchmark(aclCount)  
(authorizerType)  (denyPercentage)  (resourceCount)  Mode  CntScore
Error  Units
   AuthorizerBenchmark.testAclsIterator500   
ACL50 5000  avgt7  243.929 ± 32.787  ms/op
   AuthorizerBenchmark.testAuthorizeByResourceType 500   
ACL50 5000  avgt73.833 ±  0.375  ms/op
   AuthorizerBenchmark.testAuthorizer  500   
ACL50 5000  avgt70.033 ±  0.002  ms/op
   AuthorizerBenchmark.testUpdateCache 500   
ACL50 5000  avgt7  595.364 ± 25.375  ms/op
   JMH benchmarks done
   ```
   
   *Summary of testing strategy (including rationale)
   Since the code is equivalent the no extra tests should be added.
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org