You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "Abyss-lord (via GitHub)" <gi...@apache.org> on 2025/06/30 09:43:57 UTC
[PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Abyss-lord opened a new pull request, #7501:
URL: https://github.com/apache/gravitino/pull/7501
### What changes were proposed in this pull request?
Add JMH Tests for EntityCache, the result as follows:
```text
Benchmark (totalCnt) Mode Cnt Score Error Units
EntityCacheClearBenchmark.benchmarkClear 10 thrpt 10 536704.823 ± 36351.106 ops/s
EntityCacheClearBenchmark.benchmarkClear 100 thrpt 10 89391.338 ± 4692.738 ops/s
EntityCacheClearBenchmark.benchmarkClear 1000 thrpt 10 8406.573 ± 738.173 ops/s
EntityCacheContainsBenchmark.benchmarkContains 10 thrpt 10 19008727.286 ± 1172892.696 ops/s
EntityCacheContainsBenchmark.benchmarkContains 100 thrpt 10 19129605.626 ± 928728.148 ops/s
EntityCacheContainsBenchmark.benchmarkContains 1000 thrpt 10 17954917.808 ± 916939.288 ops/s
EntityCacheContainsBenchmark.benchmarkContainsWithRelation 10 thrpt 10 9454829.072 ± 403482.020 ops/s
EntityCacheContainsBenchmark.benchmarkContainsWithRelation 100 thrpt 10 5910924.166 ± 234228.471 ops/s
EntityCacheContainsBenchmark.benchmarkContainsWithRelation 1000 thrpt 10 1021172.939 ± 188152.980 ops/s
EntityCacheGetBenchmark.benchmarkGet 10 thrpt 10 17646662.661 ± 1850512.796 ops/s
EntityCacheGetBenchmark.benchmarkGet 100 thrpt 10 17906401.139 ± 905521.957 ops/s
EntityCacheGetBenchmark.benchmarkGet 1000 thrpt 10 17882451.612 ± 1013749.411 ops/s
EntityCacheGetBenchmark.benchmarkGetWithRelations 10 thrpt 10 7949607.041 ± 323537.818 ops/s
EntityCacheGetBenchmark.benchmarkGetWithRelations 100 thrpt 10 4939219.694 ± 54283.320 ops/s
EntityCacheGetBenchmark.benchmarkGetWithRelations 1000 thrpt 10 1060788.506 ± 22922.363 ops/s
EntityCacheInvalidateBenchmark.benchmarkInvalidate 10 thrpt 10 184227.751 ± 6303.043 ops/s
EntityCacheInvalidateBenchmark.benchmarkInvalidate 100 thrpt 10 19663.536 ± 684.142 ops/s
EntityCacheInvalidateBenchmark.benchmarkInvalidate 1000 thrpt 10 1651.429 ± 213.587 ops/s
EntityCachePutBenchmark.benchmarkPut 10 thrpt 10 222207.294 ± 10992.713 ops/s
EntityCachePutBenchmark.benchmarkPut 100 thrpt 10 20128.455 ± 434.551 ops/s
EntityCachePutBenchmark.benchmarkPut 1000 thrpt 10 1902.510 ± 75.715 ops/s
EntityCachePutBenchmark.benchmarkPutWithRelation 10 thrpt 10 335683.335 ± 34641.231 ops/s
EntityCachePutBenchmark.benchmarkPutWithRelation 100 thrpt 10 26415.590 ± 1511.666 ops/s
EntityCachePutBenchmark.benchmarkPutWithRelation 1000 thrpt 10 2345.904 ± 89.693 ops/s
EntityCacheSizeBenchmark.entityCacheSize 10 thrpt 10 9416189.995 ± 1018247.698 ops/s
EntityCacheSizeBenchmark.entityCacheSize 100 thrpt 10 944383.407 ± 35235.930 ops/s
EntityCacheSizeBenchmark.entityCacheSize 1000 thrpt 10 79938.016 ± 2466.431 ops/s
EntityCacheClearBenchmark.benchmarkClear 10 avgt 10 ≈ 10⁻⁵ s/op
EntityCacheClearBenchmark.benchmarkClear 100 avgt 10 ≈ 10⁻⁴ s/op
EntityCacheClearBenchmark.benchmarkClear 1000 avgt 10 ≈ 10⁻³ s/op
EntityCacheContainsBenchmark.benchmarkContains 10 avgt 10 ≈ 10⁻⁷ s/op
EntityCacheContainsBenchmark.benchmarkContains 100 avgt 10 ≈ 10⁻⁷ s/op
EntityCacheContainsBenchmark.benchmarkContains 1000 avgt 10 ≈ 10⁻⁷ s/op
EntityCacheContainsBenchmark.benchmarkContainsWithRelation 10 avgt 10 ≈ 10⁻⁶ s/op
EntityCacheContainsBenchmark.benchmarkContainsWithRelation 100 avgt 10 ≈ 10⁻⁶ s/op
EntityCacheContainsBenchmark.benchmarkContainsWithRelation 1000 avgt 10 ≈ 10⁻⁵ s/op
EntityCacheGetBenchmark.benchmarkGet 10 avgt 10 ≈ 10⁻⁷ s/op
EntityCacheGetBenchmark.benchmarkGet 100 avgt 10 ≈ 10⁻⁷ s/op
EntityCacheGetBenchmark.benchmarkGet 1000 avgt 10 ≈ 10⁻⁷ s/op
EntityCacheGetBenchmark.benchmarkGetWithRelations 10 avgt 10 ≈ 10⁻⁶ s/op
EntityCacheGetBenchmark.benchmarkGetWithRelations 100 avgt 10 ≈ 10⁻⁶ s/op
EntityCacheGetBenchmark.benchmarkGetWithRelations 1000 avgt 10 ≈ 10⁻⁵ s/op
EntityCacheInvalidateBenchmark.benchmarkInvalidate 10 avgt 10 ≈ 10⁻⁵ s/op
EntityCacheInvalidateBenchmark.benchmarkInvalidate 100 avgt 10 ≈ 10⁻⁴ s/op
EntityCacheInvalidateBenchmark.benchmarkInvalidate 1000 avgt 10 0.002 ± 0.001 s/op
EntityCachePutBenchmark.benchmarkPut 10 avgt 10 ≈ 10⁻⁵ s/op
EntityCachePutBenchmark.benchmarkPut 100 avgt 10 ≈ 10⁻⁴ s/op
EntityCachePutBenchmark.benchmarkPut 1000 avgt 10 0.002 ± 0.001 s/op
EntityCachePutBenchmark.benchmarkPutWithRelation 10 avgt 10 ≈ 10⁻⁵ s/op
EntityCachePutBenchmark.benchmarkPutWithRelation 100 avgt 10 ≈ 10⁻⁴ s/op
EntityCachePutBenchmark.benchmarkPutWithRelation 1000 avgt 10 0.002 ± 0.001 s/op
EntityCacheSizeBenchmark.entityCacheSize 10 avgt 10 ≈ 10⁻⁶ s/op
EntityCacheSizeBenchmark.entityCacheSize 100 avgt 10 ≈ 10⁻⁵ s/op
EntityCacheSizeBenchmark.entityCacheSize 1000 avgt 10 ≈ 10⁻⁴ s/op
```
### Why are the changes needed?
Fix: #7472
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
local test, `./gradlew :core:jmh`
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#discussion_r2177050226
##########
core/src/jmh/README.md:
##########
Review Comment:
I think we didn't need this document.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on code in PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#discussion_r2177649490
##########
core/src/jmh/README.md:
##########
Review Comment:
Fix
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on code in PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#discussion_r2181446103
##########
core/build.gradle.kts:
##########
@@ -93,3 +99,13 @@ jcstress {
mode = "default"
jvmArgsPrepend = "-Djdk.stdout.sync=true"
}
+
+jmh {
+ jmhVersion = "1.37"
+ warmupIterations = 5
+ iterations = 10
+ fork = 1
+ threads = 4
+ resultFormat = "csv"
+ resultsFile = file("$buildDir/reports/jmh/results.csv")
Review Comment:
Fix.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on code in PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#discussion_r2188892459
##########
core/src/jmh/java/org/apache/gravitino/cache/EntityCachePutBenchmark.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.gravitino.cache;
+
+import java.util.List;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.SupportsRelationOperations;
+import org.apache.gravitino.meta.ModelEntity;
+import org.apache.gravitino.meta.RoleEntity;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Setup;
+
+/**
+ * EntityCachePutBenchmark benchmarks the performance of {@link EntityCache#put} operations for both
+ * standard entities and relation-based entity groups.
+ *
+ * <p>Each benchmark invocation starts with a cleared cache to ensure that measurements reflect
+ * fresh insertions without side effects from previous state.
+ *
+ * <p>This benchmark covers two insertion scenarios:
+ *
+ * <ul>
+ * <li>{@code benchmarkPut}: Inserts a batch of {@link ModelEntity} instances into the cache.
+ * <li>{@code benchmarkPutWithRelation}: Inserts relation mappings between {@link RoleEntity} and
+ * related entities (e.g., users), using a relation type as part of the cache key.
+ * </ul>
+ *
+ * @param <E> the type of related entity, extending {@link Entity} and implementing {@link
+ * HasIdentifier}
+ * @see org.apache.gravitino.cache.EntityCache
+ * @see org.openjdk.jmh.annotations.Benchmark
+ */
+public class EntityCachePutBenchmark<E extends Entity & HasIdentifier>
+ extends AbstractEntityBenchmark {
+ @Setup(Level.Invocation)
Review Comment:
Fix
##########
core/src/jmh/java/org/apache/gravitino/cache/EntityCachePutBenchmark.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.gravitino.cache;
+
+import java.util.List;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.SupportsRelationOperations;
+import org.apache.gravitino.meta.ModelEntity;
+import org.apache.gravitino.meta.RoleEntity;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Setup;
+
+/**
+ * EntityCachePutBenchmark benchmarks the performance of {@link EntityCache#put} operations for both
+ * standard entities and relation-based entity groups.
+ *
+ * <p>Each benchmark invocation starts with a cleared cache to ensure that measurements reflect
+ * fresh insertions without side effects from previous state.
+ *
+ * <p>This benchmark covers two insertion scenarios:
+ *
+ * <ul>
+ * <li>{@code benchmarkPut}: Inserts a batch of {@link ModelEntity} instances into the cache.
+ * <li>{@code benchmarkPutWithRelation}: Inserts relation mappings between {@link RoleEntity} and
+ * related entities (e.g., users), using a relation type as part of the cache key.
+ * </ul>
+ *
+ * @param <E> the type of related entity, extending {@link Entity} and implementing {@link
+ * HasIdentifier}
+ * @see org.apache.gravitino.cache.EntityCache
+ * @see org.openjdk.jmh.annotations.Benchmark
+ */
+public class EntityCachePutBenchmark<E extends Entity & HasIdentifier>
+ extends AbstractEntityBenchmark {
+ @Setup(Level.Invocation)
Review Comment:
Fix
##########
core/src/jmh/java/org/apache/gravitino/cache/EntityCacheClearBenchmark.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.gravitino.cache;
+
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.meta.ModelEntity;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Setup;
+
+/**
+ * EntityCacheClearBenchmark benchmarks the performance of the {@link EntityCache#clear()} operation
+ * under varying cache sizes.
+ *
+ * <p>This benchmark repeatedly clears the cache to evaluate the efficiency and overhead of the
+ * cache invalidation mechanism, especially under different entity volumes (e.g., 10, 100, 1000).
+ *
+ * <p>Before each invocation, the cache is pre-populated with a predefined list of entities to
+ * ensure the {@code clear()} method operates on a non-empty cache.
+ *
+ * @param <E> the entity type being tested, must extend {@link Entity} and implement {@link
+ * HasIdentifier}
+ * @see org.apache.gravitino.cache.EntityCache
+ * @see org.openjdk.jmh.annotations.Benchmark
+ */
+public class EntityCacheClearBenchmark<E extends Entity & HasIdentifier>
Review Comment:
Fix
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#discussion_r2188870560
##########
core/src/jmh/java/org/apache/gravitino/cache/EntityCachePutBenchmark.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.gravitino.cache;
+
+import java.util.List;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.SupportsRelationOperations;
+import org.apache.gravitino.meta.ModelEntity;
+import org.apache.gravitino.meta.RoleEntity;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Setup;
+
+/**
+ * EntityCachePutBenchmark benchmarks the performance of {@link EntityCache#put} operations for both
+ * standard entities and relation-based entity groups.
+ *
+ * <p>Each benchmark invocation starts with a cleared cache to ensure that measurements reflect
+ * fresh insertions without side effects from previous state.
+ *
+ * <p>This benchmark covers two insertion scenarios:
+ *
+ * <ul>
+ * <li>{@code benchmarkPut}: Inserts a batch of {@link ModelEntity} instances into the cache.
+ * <li>{@code benchmarkPutWithRelation}: Inserts relation mappings between {@link RoleEntity} and
+ * related entities (e.g., users), using a relation type as part of the cache key.
+ * </ul>
+ *
+ * @param <E> the type of related entity, extending {@link Entity} and implementing {@link
+ * HasIdentifier}
+ * @see org.apache.gravitino.cache.EntityCache
+ * @see org.openjdk.jmh.annotations.Benchmark
+ */
+public class EntityCachePutBenchmark<E extends Entity & HasIdentifier>
+ extends AbstractEntityBenchmark {
+ @Setup(Level.Invocation)
Review Comment:
Can you add an empty line above?
##########
core/src/jmh/java/org/apache/gravitino/cache/EntityCachePutBenchmark.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.gravitino.cache;
+
+import java.util.List;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.SupportsRelationOperations;
+import org.apache.gravitino.meta.ModelEntity;
+import org.apache.gravitino.meta.RoleEntity;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Setup;
+
+/**
+ * EntityCachePutBenchmark benchmarks the performance of {@link EntityCache#put} operations for both
+ * standard entities and relation-based entity groups.
+ *
+ * <p>Each benchmark invocation starts with a cleared cache to ensure that measurements reflect
+ * fresh insertions without side effects from previous state.
+ *
+ * <p>This benchmark covers two insertion scenarios:
+ *
+ * <ul>
+ * <li>{@code benchmarkPut}: Inserts a batch of {@link ModelEntity} instances into the cache.
+ * <li>{@code benchmarkPutWithRelation}: Inserts relation mappings between {@link RoleEntity} and
+ * related entities (e.g., users), using a relation type as part of the cache key.
+ * </ul>
+ *
+ * @param <E> the type of related entity, extending {@link Entity} and implementing {@link
+ * HasIdentifier}
+ * @see org.apache.gravitino.cache.EntityCache
+ * @see org.openjdk.jmh.annotations.Benchmark
+ */
+public class EntityCachePutBenchmark<E extends Entity & HasIdentifier>
+ extends AbstractEntityBenchmark {
+ @Setup(Level.Invocation)
Review Comment:
Can you add an empty line above?
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#issuecomment-3021433577
Hi @jerryshao , could you please review this PR when you have time? I’d really appreciate your feedback.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#discussion_r2182696290
##########
gradle/libs.versions.toml:
##########
@@ -121,6 +121,8 @@ aliyun-credentials = "0.3.12"
openlineage = "1.29.0"
concurrent-trees = "2.6.0"
jcstress = "0.8.15"
+jmh-plugin = "0.7.3"
+jmh = "1.37"
Review Comment:
Where is the value used?
##########
core/src/jmh/java/org/apache/gravitino/cache/BenchmarkHelper.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.gravitino.cache;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Maps;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.meta.ModelEntity;
+import org.apache.gravitino.meta.RoleEntity;
+import org.apache.gravitino.utils.TestUtil;
+
+public class BenchmarkHelper {
+ public static final int RELATION_CNT = 5;
+ private static final Random random = new Random();
+
+ private BenchmarkHelper() {
+ // Utility class, no constructor needed
+ }
+
+ /**
+ * Generates a map of entities with their relations.
+ *
+ * @param entityCnt the count of entities to generate.
+ * @return a map of entities with their relations.
+ * @param <E> the type of the entity.
+ */
+ public static <E extends Entity & HasIdentifier> Map<RoleEntity, List<E>> getRelationEntities(
+ int entityCnt) {
+ Map<RoleEntity, List<E>> entitiesWithRelations = Maps.newHashMap();
+ for (int i = 0; i < entityCnt; i++) {
+ RoleEntity testRoleEntity = TestUtil.getTestRoleEntity();
+ int userCnt = random.nextInt(RELATION_CNT);
+ List<E> userList = BaseEntityCache.convertEntities(getUserList(testRoleEntity, userCnt));
+ entitiesWithRelations.put(testRoleEntity, userList);
+ }
+
+ return entitiesWithRelations;
+ }
+
+ /**
+ * Generates a list of entities with the specified count.
+ *
+ * @param entityCnt the count of entities to generate.
+ * @return a list of model entities.
+ */
+ public static List<ModelEntity> getEntities(int entityCnt) {
+ List<ModelEntity> entities = new ArrayList<>(entityCnt);
+ for (int i = 0; i < entityCnt; i++) {
+ entities.add(TestUtil.getTestModelEntity());
+ }
+
+ return entities;
+ }
+
+ /**
+ * Returns a randomly selected key from the given map.
+ *
+ * @param map the input map from which to select a random key
+ * @param <K> the type of keys in the map
+ * @param <V> the type of values in the map
+ * @return a randomly selected key from the map, or {@code null} if the map is null or empty
+ */
+ public static <K, V> K getRandomKey(Map<K, V> map) {
+ if (map == null || map.isEmpty()) {
+ return null;
+ }
+
+ List<K> keys = new ArrayList<>(map.keySet());
+ Random random = new Random();
Review Comment:
You can reuse the `random` defined in L36
##########
core/src/jmh/java/org/apache/gravitino/cache/AbstractEntityBenchmark.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.gravitino.cache;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.SupportsRelationOperations;
+import org.apache.gravitino.meta.ModelEntity;
+import org.apache.gravitino.meta.RoleEntity;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Level;
+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;
+
+/**
+ * AbstractEntityBenchmark is a JMH-based benchmark base class designed to evaluate the performance
+ * of the {@link EntityCache} implementation in Gravitino.
+ *
+ * <p>This class sets up a controlled environment where a configurable number of entities and their
+ * associated relations are preloaded into the cache before each iteration. It supports benchmarking
+ * cache operations such as put, get, and relation-based access under varying data volumes.
+ *
+ * <p>Features:
+ *
+ * <ul>
+ * <li>Supports benchmarking with different entity counts (e.g., 10, 100, 1000)
+ * <li>Measures both throughput and average execution time using JMH modes
+ * <li>Preloads both simple entities and relation entities (e.g., user-role mappings)
+ * </ul>
+ *
+ * <p>Subclasses should implement benchmark methods to evaluate specific cache operations.
+ *
+ * @param <E> the type of entity under test, must implement {@link Entity} and {@link HasIdentifier}
+ * @see org.apache.gravitino.cache.CaffeineEntityCache
+ * @see org.openjdk.jmh.annotations.Benchmark
+ * @see org.apache.gravitino.cache.BenchmarkHelper
+ */
+@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
+@OutputTimeUnit(TimeUnit.SECONDS)
+@State(Scope.Thread)
+public abstract class AbstractEntityBenchmark<E extends Entity & HasIdentifier> {
+ @Param({"10", "100", "1000"})
Review Comment:
The size seems to be quite small. Is this the total number of entities stored in `entityStore`?
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#issuecomment-3026169542
It is better we can add the end to end API test after cache is enabled, then we will know how cache improves, and identify the hotpath again to improve the performance, that will be much more useful compared to test the performance of cache alone.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on code in PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#discussion_r2184106511
##########
core/src/jmh/java/org/apache/gravitino/cache/BenchmarkHelper.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.gravitino.cache;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Maps;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.meta.ModelEntity;
+import org.apache.gravitino.meta.RoleEntity;
+import org.apache.gravitino.utils.TestUtil;
+
+public class BenchmarkHelper {
+ public static final int RELATION_CNT = 5;
+ private static final Random random = new Random();
+
+ private BenchmarkHelper() {
+ // Utility class, no constructor needed
+ }
+
+ /**
+ * Generates a map of entities with their relations.
+ *
+ * @param entityCnt the count of entities to generate.
+ * @return a map of entities with their relations.
+ * @param <E> the type of the entity.
+ */
+ public static <E extends Entity & HasIdentifier> Map<RoleEntity, List<E>> getRelationEntities(
+ int entityCnt) {
+ Map<RoleEntity, List<E>> entitiesWithRelations = Maps.newHashMap();
+ for (int i = 0; i < entityCnt; i++) {
+ RoleEntity testRoleEntity = TestUtil.getTestRoleEntity();
+ int userCnt = random.nextInt(RELATION_CNT);
+ List<E> userList = BaseEntityCache.convertEntities(getUserList(testRoleEntity, userCnt));
+ entitiesWithRelations.put(testRoleEntity, userList);
+ }
+
+ return entitiesWithRelations;
+ }
+
+ /**
+ * Generates a list of entities with the specified count.
+ *
+ * @param entityCnt the count of entities to generate.
+ * @return a list of model entities.
+ */
+ public static List<ModelEntity> getEntities(int entityCnt) {
+ List<ModelEntity> entities = new ArrayList<>(entityCnt);
+ for (int i = 0; i < entityCnt; i++) {
+ entities.add(TestUtil.getTestModelEntity());
+ }
+
+ return entities;
+ }
+
+ /**
+ * Returns a randomly selected key from the given map.
+ *
+ * @param map the input map from which to select a random key
+ * @param <K> the type of keys in the map
+ * @param <V> the type of values in the map
+ * @return a randomly selected key from the map, or {@code null} if the map is null or empty
+ */
+ public static <K, V> K getRandomKey(Map<K, V> map) {
+ if (map == null || map.isEmpty()) {
+ return null;
+ }
+
+ List<K> keys = new ArrayList<>(map.keySet());
+ Random random = new Random();
Review Comment:
Fix.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#discussion_r2177076934
##########
core/build.gradle.kts:
##########
@@ -93,3 +99,13 @@ jcstress {
mode = "default"
jvmArgsPrepend = "-Djdk.stdout.sync=true"
}
+
+jmh {
+ jmhVersion = "1.37"
+ warmupIterations = 5
+ iterations = 10
+ fork = 1
+ threads = 4
+ resultFormat = "csv"
+ resultsFile = file("$buildDir/reports/jmh/results.csv")
Review Comment:
Maybe we need define version `1.37` in the https://github.com/apache/gravitino/blob/main/settings.gradle.kts ?
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#discussion_r2184119099
##########
gradle/libs.versions.toml:
##########
@@ -121,6 +121,8 @@ aliyun-credentials = "0.3.12"
openlineage = "1.29.0"
concurrent-trees = "2.6.0"
jcstress = "0.8.15"
+jmh-plugin = "0.7.3"
+jmh = "1.37"
Review Comment:
I see.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#issuecomment-3034171291
@xunliu
I have no further comments, and most of them are JMH test codes.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao merged PR #7501:
URL: https://github.com/apache/gravitino/pull/7501
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on code in PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#discussion_r2184107000
##########
core/src/jmh/java/org/apache/gravitino/cache/AbstractEntityBenchmark.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.gravitino.cache;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.SupportsRelationOperations;
+import org.apache.gravitino.meta.ModelEntity;
+import org.apache.gravitino.meta.RoleEntity;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Level;
+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;
+
+/**
+ * AbstractEntityBenchmark is a JMH-based benchmark base class designed to evaluate the performance
+ * of the {@link EntityCache} implementation in Gravitino.
+ *
+ * <p>This class sets up a controlled environment where a configurable number of entities and their
+ * associated relations are preloaded into the cache before each iteration. It supports benchmarking
+ * cache operations such as put, get, and relation-based access under varying data volumes.
+ *
+ * <p>Features:
+ *
+ * <ul>
+ * <li>Supports benchmarking with different entity counts (e.g., 10, 100, 1000)
+ * <li>Measures both throughput and average execution time using JMH modes
+ * <li>Preloads both simple entities and relation entities (e.g., user-role mappings)
+ * </ul>
+ *
+ * <p>Subclasses should implement benchmark methods to evaluate specific cache operations.
+ *
+ * @param <E> the type of entity under test, must implement {@link Entity} and {@link HasIdentifier}
+ * @see org.apache.gravitino.cache.CaffeineEntityCache
+ * @see org.openjdk.jmh.annotations.Benchmark
+ * @see org.apache.gravitino.cache.BenchmarkHelper
+ */
+@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
+@OutputTimeUnit(TimeUnit.SECONDS)
+@State(Scope.Thread)
+public abstract class AbstractEntityBenchmark<E extends Entity & HasIdentifier> {
+ @Param({"10", "100", "1000"})
Review Comment:
Thanks for the comment!
Yes, the current entity count is relatively small because I ran the test on my local machine for about 2.5 hours. The main goal of this test is to explore the relationship between entity count and cache performance, aiming to analyze the Big-O.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on code in PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#discussion_r2184108646
##########
gradle/libs.versions.toml:
##########
@@ -121,6 +121,8 @@ aliyun-credentials = "0.3.12"
openlineage = "1.29.0"
concurrent-trees = "2.6.0"
jcstress = "0.8.15"
+jmh-plugin = "0.7.3"
+jmh = "1.37"
Review Comment:
jmh plugin:
https://github.com/apache/gravitino/blob/89ec22cc65506e5a64cad9e107037c2229bdc5f0/core/build.gradle.kts#L26
jmh:
https://github.com/apache/gravitino/blob/89ec22cc65506e5a64cad9e107037c2229bdc5f0/core/build.gradle.kts#L104
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "Abyss-lord (via GitHub)" <gi...@apache.org>.
Abyss-lord commented on PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#issuecomment-3026575630
> It is better we can add the end to end API test after cache is enabled, then we will know how cache improves, and identify the hotpath again to improve the performance, that will be much more useful compared to test the performance of cache alone.
Got it, I Will submit a new PR with E2E tests to validate caching performance #7546 .
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7472] feat(core): Add JMH Tests for EntityCache [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7501:
URL: https://github.com/apache/gravitino/pull/7501#discussion_r2188866948
##########
core/src/jmh/java/org/apache/gravitino/cache/EntityCacheClearBenchmark.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.gravitino.cache;
+
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.meta.ModelEntity;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Setup;
+
+/**
+ * EntityCacheClearBenchmark benchmarks the performance of the {@link EntityCache#clear()} operation
+ * under varying cache sizes.
+ *
+ * <p>This benchmark repeatedly clears the cache to evaluate the efficiency and overhead of the
+ * cache invalidation mechanism, especially under different entity volumes (e.g., 10, 100, 1000).
+ *
+ * <p>Before each invocation, the cache is pre-populated with a predefined list of entities to
+ * ensure the {@code clear()} method operates on a non-empty cache.
+ *
+ * @param <E> the entity type being tested, must extend {@link Entity} and implement {@link
+ * HasIdentifier}
+ * @see org.apache.gravitino.cache.EntityCache
+ * @see org.openjdk.jmh.annotations.Benchmark
+ */
+public class EntityCacheClearBenchmark<E extends Entity & HasIdentifier>
Review Comment:
Can you please rename this class name to `ClearEntityCacheBenchmark`, `ContainsEntityCacheBenchmark`, etc?
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org