thetumbled opened a new pull request, #23582:
URL: https://github.com/apache/pulsar/pull/23582
### Motivation
**Delayed message feature** need to retain the message id and timestamp info
in the memory. Delayed message queue need to retain such info in broker side,
**Negative ack feature** need to retain such info in the consumer client side,
both of these two cases could lead to great memory consumption.
This PR aim to replace the `HashMap` with the inner map implementation
`ConcurrentLongLongPairHashMap` to reduce the memory consumption. Though
`HashMap` is faster than the inner map implementation
`ConcurrentLongLongPairHashMap` in some cases, but the most important issue in
this case is memory consumption instead of the speed.
Some test data list as follows:
```
public static void main(String[] args) throws IOException {
ConcurrentLongLongPairHashMap map1 =
ConcurrentLongLongPairHashMap.newBuilder()
.autoShrink(true)
.concurrencyLevel(16)
.build();
HashMap<MessageId, Long> map2 = new HashMap<>();
long numMessages = 5000000;
long ledgerId, entryId, partitionIndex, timestamp;
for (long i = 0; i < numMessages; i++) {
ledgerId = 10000+i;
entryId = i;
partitionIndex = 0;
timestamp = System.currentTimeMillis();
map1.put(ledgerId, entryId, partitionIndex, timestamp);
map2.put(new MessageIdImpl(ledgerId, entryId,
(int)partitionIndex), timestamp);
}
System.out.println("map1 size: " + map1.size());
System.out.println("map2 size: " + map2.size());
try {
Thread.sleep(10000000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
```
- 100w entry

HashMap:178Mb
ConcurrentLongLongPairHashMap:64Mb
- 500w entry

HashMap:566Mb
ConcurrentLongLongPairHashMap:256Mb
- 1000w entry

HashMap:1132MB
**Approximately each entry consume 1132MB/10000000=118byte.**
ConcurrentLongLongPairHashMap:512MB
**Approximately each entry consume 512MB/10000000=53byte.**
With this improvement, we can reduce 50% of the memory consumption!
### Modifications
Replace `HashMap` with `ConcurrentLongLongPairHashMap` in Negative Ack
Tracker.
### Verifying this change
- [ ] Make sure that the change passes the CI checks.
*(Please pick either of the following options)*
This change is already covered by existing tests, such as *(please describe
tests)*.
### Does this pull request potentially affect one of the following parts:
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
*If the box was checked, please highlight the changes*
- [ ] Dependencies (add or upgrade a dependency)
- [ ] The public API
- [ ] The schema
- [ ] The default values of configurations
- [ ] The threading model
- [ ] The binary protocol
- [ ] The REST endpoints
- [ ] The admin CLI options
- [ ] The metrics
- [ ] Anything that affects deployment
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc` <!-- Your PR contains doc changes. -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update
later -->
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->
### Matching PR in forked repository
PR in forked repository:
--
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]