BewareMyPower commented on code in PR #23052:
URL: https://github.com/apache/pulsar/pull/23052#discussion_r1683747381
##########
pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicName.java:
##########
@@ -54,13 +49,13 @@ public class TopicName implements ServiceUnitId {
private final int partitionIndex;
- private static final LoadingCache<String, TopicName> cache =
CacheBuilder.newBuilder().maximumSize(100000)
- .expireAfterAccess(30, TimeUnit.MINUTES).build(new
CacheLoader<String, TopicName>() {
- @Override
- public TopicName load(String name) throws Exception {
- return new TopicName(name);
- }
- });
+ private static final ConcurrentHashMap<String, TopicName> cache = new
ConcurrentHashMap<>();
+
+ public static void clearIfReachedMaxCapacity(int maxCapacity) {
+ if (cache.size() > maxCapacity) {
+ cache.clear();
Review Comment:
Actually I've implemented my own `TopicName` locally. It does not use any
cache, here are the test results.
```
Benchmark Mode Cnt Score
Error Units
TopicNameGetBenchmark.testCustomApi thrpt 5 5218006.242 ±
110486.719 ops/s
TopicNameGetBenchmark.testLoadingCache2Get thrpt 5 6695534.090 ±
780412.049 ops/s
TopicNameGetBenchmark.testLoadingCache3Get thrpt 5 70196060.116 ±
1651256.265 ops/s
TopicNameGetBenchmark.testLoadingCacheGet thrpt 5 6437317.067 ±
600935.408 ops/s
TopicNameGetBenchmark.testPulsarApi thrpt 5 5958092.755 ±
150135.549 ops/s
```
- `testCustomApi`: Parse the topic string every time without any cache
- `testPulsarApi`: Parse the topic string only for the 1st time and read
from the loading cache in the following tests
As you can see, reading from the loading cache does not perform
significantly better.
<img width="1698" alt="image"
src="https://github.com/user-attachments/assets/7fdf5cac-8032-4b56-9d39-133a2e6c871c">
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]