You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "gy-deng (via GitHub)" <gi...@apache.org> on 2025/07/31 10:50:15 UTC
[PR] [improve] modify the negativeACK structure to reduce memory overhead [pulsar-client-cpp]
gy-deng opened a new pull request, #497:
URL: https://github.com/apache/pulsar-client-cpp/pull/497
<!--
### Contribution Checklist
- PR title format should be *[type][component] summary*. For details, see *[Guideline - Pulsar PR Naming Convention](https://docs.google.com/document/d/1d8Pw6ZbWk-_pCKdOmdvx9rnhPiyuxwq60_TrD68d7BA/edit#heading=h.trs9rsex3xom)*.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message
- Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
-->
<!-- Either this PR fixes an issue, -->
<!-- or this PR is one task of an issue -->
### Motivation
<!-- Explain here the context, and why you're making that change. What is the problem you're trying to solve. -->
The main content of this PR is to implement the Pulsar Java community's [PIP-393](https://github.com/apache/pulsar/pull/23601) proposal in the CPP client.
Negative acknowledgement handling in now Pulsar CPP client exhibits inefficiencies related to memory usage, timing precision, and batch-level contention.
This effort aims to bring parity with the refinements implemented in the Java client, notably around memory usage and redelivery coordination.
### Modifications
<!-- Describe the modifications you've done. -->
Refactor the `NegativeAcksTracker` to solve the above problems.
Updated outdated images in CI:
1. Updated windows-2019 to 2022, as windows-2019 was deprecated on June 30, 2025 (ref: https://github.com/actions/runner-images/issues/12045).
2. Updated debian 10 in the Dockerfile to debian 11, as it no longer works with GitHub images (ref: https://github.com/actions/runner-images/issues/12627).
### Verifying this change
- [x] Make sure that the change passes the CI checks.
This change added tests and can be verified as follows:
- *Functional testing of negative acks is covered by existing tests (e.g., `testNegativeAcks`)*
- *Extended integration test for evaluating redelivery precision across varying negative acknowledgement bit-widths (i.e., `testNegativeAckPrecisionBitCnt`.*
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc-required`
- [x] `doc-not-needed`
- [ ] `doc`
- [ ] `doc-complete`
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] modify the negativeACK structure to reduce memory overhead [pulsar-client-cpp]
Posted by "gy-deng (via GitHub)" <gi...@apache.org>.
gy-deng commented on PR #497:
URL: https://github.com/apache/pulsar-client-cpp/pull/497#issuecomment-3140118498
> Could you fix the `.github/workflows/codeql-analysis.yml`?
Of course, I'll deal with this.
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] modify the negativeACK structure to reduce memory overhead [pulsar-client-cpp]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #497:
URL: https://github.com/apache/pulsar-client-cpp/pull/497#discussion_r2245244308
##########
tests/BasicEndToEndTest.cc:
##########
@@ -3249,6 +3249,60 @@ TEST(BasicEndToEndTest, testNegativeAcksWithPartitions) {
testNegativeAcks(topicName, true);
}
+int64_t getCurrentTimeMs() {
Review Comment:
You can use `TimeUtils::currentTimeMillis()` from `lib/TimeUtils.h`.
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] modify the negativeACK structure to reduce memory overhead [pulsar-client-cpp]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on PR #497:
URL: https://github.com/apache/pulsar-client-cpp/pull/497#issuecomment-3140092074
Could you fix the `.github/workflows/codeql-analysis.yml`?
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] modify the negativeACK structure to reduce memory overhead [pulsar-client-cpp]
Posted by "gy-deng (via GitHub)" <gi...@apache.org>.
gy-deng commented on code in PR #497:
URL: https://github.com/apache/pulsar-client-cpp/pull/497#discussion_r2275194431
##########
lib/NegativeAcksTracker.cc:
##########
@@ -75,13 +81,22 @@ void NegativeAcksTracker::handleTimer(const ASIO_ERROR &ec) {
auto now = Clock::now();
+ // The map is sorted by time, so we can exit immediately when we traverse to a time that does not match
for (auto it = nackedMessages_.begin(); it != nackedMessages_.end();) {
- if (it->second < now) {
- messagesToRedeliver.insert(it->first);
- it = nackedMessages_.erase(it);
- } else {
- ++it;
+ if (it->first > now) {
+ // We are done with all the messages that need to be redelivered
+ break;
}
+
+ auto ledgerMap = it->second;
+ for (auto ledgerIt = ledgerMap.begin(); ledgerIt != ledgerMap.end(); ++ledgerIt) {
+ auto entrySet = ledgerIt->second;
Review Comment:
Thanks for pointing that out.
I'll create a new PR to fix it
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] modify the negativeACK structure to reduce memory overhead [pulsar-client-cpp]
Posted by "arhoads (via GitHub)" <gi...@apache.org>.
arhoads commented on code in PR #497:
URL: https://github.com/apache/pulsar-client-cpp/pull/497#discussion_r2274220029
##########
lib/NegativeAcksTracker.cc:
##########
@@ -75,13 +81,22 @@ void NegativeAcksTracker::handleTimer(const ASIO_ERROR &ec) {
auto now = Clock::now();
+ // The map is sorted by time, so we can exit immediately when we traverse to a time that does not match
for (auto it = nackedMessages_.begin(); it != nackedMessages_.end();) {
- if (it->second < now) {
- messagesToRedeliver.insert(it->first);
- it = nackedMessages_.erase(it);
- } else {
- ++it;
+ if (it->first > now) {
+ // We are done with all the messages that need to be redelivered
+ break;
}
+
+ auto ledgerMap = it->second;
+ for (auto ledgerIt = ledgerMap.begin(); ledgerIt != ledgerMap.end(); ++ledgerIt) {
+ auto entrySet = ledgerIt->second;
Review Comment:
This makes a copy. Is this intended to be a reference instead - `auto& entrySet = ledgerIt->second;`?
This line also makes a copy `auto ledgerMap = it->second;`
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] modify the negativeACK structure to reduce memory overhead [pulsar-client-cpp]
Posted by "arhoads (via GitHub)" <gi...@apache.org>.
arhoads commented on code in PR #497:
URL: https://github.com/apache/pulsar-client-cpp/pull/497#discussion_r2274220029
##########
lib/NegativeAcksTracker.cc:
##########
@@ -75,13 +81,22 @@ void NegativeAcksTracker::handleTimer(const ASIO_ERROR &ec) {
auto now = Clock::now();
+ // The map is sorted by time, so we can exit immediately when we traverse to a time that does not match
for (auto it = nackedMessages_.begin(); it != nackedMessages_.end();) {
- if (it->second < now) {
- messagesToRedeliver.insert(it->first);
- it = nackedMessages_.erase(it);
- } else {
- ++it;
+ if (it->first > now) {
+ // We are done with all the messages that need to be redelivered
+ break;
}
+
+ auto ledgerMap = it->second;
+ for (auto ledgerIt = ledgerMap.begin(); ledgerIt != ledgerMap.end(); ++ledgerIt) {
+ auto entrySet = ledgerIt->second;
Review Comment:
This makes a copy. Is this intended to be a reference instead - `auto& entrySet = ledgerIt->second;`?
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] modify the negativeACK structure to reduce memory overhead [pulsar-client-cpp]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower merged PR #497:
URL: https://github.com/apache/pulsar-client-cpp/pull/497
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org