You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "BewareMyPower (via GitHub)" <gi...@apache.org> on 2024/07/22 13:20:57 UTC

[PR] [improve][broker] Reduce the pressure from the transaction buffer readers and writers in rolling restarts [pulsar]

BewareMyPower opened a new pull request, #23062:
URL: https://github.com/apache/pulsar/pull/23062

   ### Motivation
   
   During the rolling restarts, the namespace bundle ownerships will change. Assuming there is a producer created on a single topic, and the ownership was transferred to the new broker. Assuming the namespace bundle has N topics and the namespace is `tenant/ns`,
   1. All N topics in the same bundle of that topic will be loaded.
   2. For each topic, the managed ledger will be initialized, when the transaction coordinator is enabled, a `TopicTransactionBuffer` will be created. 2.1 A Pulsar producer will be created on `tenant/ns/__transaction_buffer_snapshot` concurrently. 2.2 A Pulsar reader will be created on `tenant/ns/__transaction_buffer_snapshot` concurrently.
   3. Once all N readers are created, the owner of the snapshot topic will start dispatching messages to N readers. Each dispatcher will read messages from BookKeeper concurrently and might fail with too many requests error because BK can only have `maxPendingReadRequestsPerThread` pending read requests (default: 10000).
   
   We have a `numTransactionReplayThreadPoolSize` config to limit the concurrency of transaction snapshot readers. However, it only limits the read loop. For example, if it's configured with 1, only 1 reader could read messages at the same time. However, N readers will be created concurrently. Each when one of these reader explicitly calls `readNext`, all N dispatchers at brokers side will dispatch messages to N readers.
   
   The behaviors above brings much CPU pressure on the owner broker, especially for a small cluster with only two brokers.
   
   ### Modifications
   
   - Synchronize the reader creation, read loop and the following process on its result.
   - Delay the snapshot producer creaton to when a message is written via `LazySnapshotWriter`.
   
   ### 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 -->
   - [x] `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: <!-- ENTER URL HERE -->
   
   <!--
   After opening this PR, the build in apache/pulsar will fail and instructions will
   be provided for opening a PR in the PR author's forked repository.
   
   apache/pulsar pull requests should be first tested in your own fork since the 
   apache/pulsar CI based on GitHub Actions has constrained resources and quota.
   GitHub Actions provides separate quota for pull requests that are executed in 
   a forked repository.
   
   The tests will be run in the forked repository until all PR review comments have
   been handled, the tests pass and the PR is approved by a reviewer.
   -->
   


-- 
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][broker] Reduce the CPU pressure from the transaction buffer in rolling restarts [pulsar]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #23062:
URL: https://github.com/apache/pulsar/pull/23062#issuecomment-2255793312

   ## [Codecov](https://app.codecov.io/gh/apache/pulsar/pull/23062?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `83.78378%` with `30 lines` in your changes missing coverage. Please review.
   > Project coverage is 73.47%. Comparing base [(`bbc6224`)](https://app.codecov.io/gh/apache/pulsar/commit/bbc62245c5ddba1de4b1e7cee4ab49334bc36277?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`acc95de`)](https://app.codecov.io/gh/apache/pulsar/commit/acc95dedac9aa81a87acf469fa87e17b4f2d2835?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 475 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/pulsar/pull/23062/graphs/tree.svg?width=650&height=150&src=pr&token=acYqCpsK9J&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/pulsar/pull/23062?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #23062      +/-   ##
   ============================================
   - Coverage     73.57%   73.47%   -0.11%     
   - Complexity    32624    33530     +906     
   ============================================
     Files          1877     1919      +42     
     Lines        139502   144086    +4584     
     Branches      15299    15741     +442     
   ============================================
   + Hits         102638   105860    +3222     
   - Misses        28908    30101    +1193     
   - Partials       7956     8125     +169     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/pulsar/pull/23062/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [inttests](https://app.codecov.io/gh/apache/pulsar/pull/23062/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `27.52% <36.75%> (+2.94%)` | :arrow_up: |
   | [systests](https://app.codecov.io/gh/apache/pulsar/pull/23062/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `24.72% <0.00%> (+0.40%)` | :arrow_up: |
   | [unittests](https://app.codecov.io/gh/apache/pulsar/pull/23062/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `72.54% <83.78%> (-0.31%)` | :arrow_down: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Files](https://app.codecov.io/gh/apache/pulsar/pull/23062?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...n/java/org/apache/pulsar/broker/PulsarService.java](https://app.codecov.io/gh/apache/pulsar/pull/23062?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fbroker%2FPulsarService.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9QdWxzYXJTZXJ2aWNlLmphdmE=) | `84.25% <100.00%> (+1.88%)` | :arrow_up: |
   | [...r/service/SystemTopicTxnBufferSnapshotService.java](https://app.codecov.io/gh/apache/pulsar/pull/23062?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fbroker%2Fservice%2FSystemTopicTxnBufferSnapshotService.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9zZXJ2aWNlL1N5c3RlbVRvcGljVHhuQnVmZmVyU25hcHNob3RTZXJ2aWNlLmphdmE=) | `80.55% <100.00%> (-2.47%)` | :arrow_down: |
   | [...rvice/TransactionBufferSnapshotServiceFactory.java](https://app.codecov.io/gh/apache/pulsar/pull/23062?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fbroker%2Fservice%2FTransactionBufferSnapshotServiceFactory.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9zZXJ2aWNlL1RyYW5zYWN0aW9uQnVmZmVyU25hcHNob3RTZXJ2aWNlRmFjdG9yeS5qYXZh) | `83.33% <100.00%> (ø)` | |
   | [...er/impl/SingleSnapshotAbortedTxnProcessorImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/23062?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fbroker%2Ftransaction%2Fbuffer%2Fimpl%2FSingleSnapshotAbortedTxnProcessorImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci90cmFuc2FjdGlvbi9idWZmZXIvaW1wbC9TaW5nbGVTbmFwc2hvdEFib3J0ZWRUeG5Qcm9jZXNzb3JJbXBsLmphdmE=) | `83.13% <100.00%> (-0.04%)` | :arrow_down: |
   | [...ransaction/buffer/impl/TopicTransactionBuffer.java](https://app.codecov.io/gh/apache/pulsar/pull/23062?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fbroker%2Ftransaction%2Fbuffer%2Fimpl%2FTopicTransactionBuffer.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci90cmFuc2FjdGlvbi9idWZmZXIvaW1wbC9Ub3BpY1RyYW5zYWN0aW9uQnVmZmVyLmphdmE=) | `87.63% <100.00%> (-0.12%)` | :arrow_down: |
   | [...main/java/org/apache/pulsar/utils/SimpleCache.java](https://app.codecov.io/gh/apache/pulsar/pull/23062?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Futils%2FSimpleCache.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL3V0aWxzL1NpbXBsZUNhY2hlLmphdmE=) | `100.00% <100.00%> (ø)` | |
   | [...lsar/broker/transaction/buffer/impl/TableView.java](https://app.codecov.io/gh/apache/pulsar/pull/23062?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fbroker%2Ftransaction%2Fbuffer%2Fimpl%2FTableView.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci90cmFuc2FjdGlvbi9idWZmZXIvaW1wbC9UYWJsZVZpZXcuamF2YQ==) | `74.07% <74.07%> (ø)` | |
   | [...r/impl/SnapshotSegmentAbortedTxnProcessorImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/23062?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fbroker%2Ftransaction%2Fbuffer%2Fimpl%2FSnapshotSegmentAbortedTxnProcessorImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci90cmFuc2FjdGlvbi9idWZmZXIvaW1wbC9TbmFwc2hvdFNlZ21lbnRBYm9ydGVkVHhuUHJvY2Vzc29ySW1wbC5qYXZh) | `81.96% <77.00%> (+3.44%)` | :arrow_up: |
   
   ... and [514 files with indirect coverage changes](https://app.codecov.io/gh/apache/pulsar/pull/23062/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   </details>


-- 
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][broker] Reduce the CPU pressure from the transaction buffer in rolling restarts [pulsar]

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on PR #23062:
URL: https://github.com/apache/pulsar/pull/23062#issuecomment-2244764499

   This improvement for the reader side can be verified by the following example.
   
   ```java
   public class LoadTopicTest extends ProducerConsumerBase {
   
       @BeforeClass
       @Override
       protected void setup() throws Exception {
           conf.setDefaultNumberOfNamespaceBundles(1);
           conf.setNumTransactionReplayThreadPoolSize(1);
           conf.setTransactionCoordinatorEnabled(true);
           super.isTcpLookup = true;
           super.internalSetup();
           super.producerBaseSetup();
       }
   
       @AfterClass
       @Override
       protected void cleanup() throws Exception {
           super.internalCleanup();
       }
   
       @Test
       public void test() throws Exception {
           final var topic = "test";
           admin.topics().createPartitionedTopic(topic, 5);
           @Cleanup final var producer = pulsarClient.newProducer().topic(topic + "-partition-0").create();
           Thread.sleep(1000);
       }
   }
   ```
   
   Save the outputs into `1.log` and run `grep -E "Subscribing on|Subscribed to|Closed consumer" 1.log | grep snapshot`, then you can see:
   
   ```
   2024-07-23T17:46:50,142 - INFO  - [pulsar-io-9-4:ServerCnx] - [[id: 0x0134c04e, L:/127.0.0.1:57954 - R:/127.0.0.1:57960] [SR:127.0.0.1, state:Connected]] Subscribing on topic persistent://public/default/__transaction_buffer_snapshot / reader-8d442bc96f. consumerId: 1
   2024-07-23T17:46:50,145 - INFO  - [pulsar-io-9-4:ServerCnx] - [[id: 0x0134c04e, L:/127.0.0.1:57954 - R:/127.0.0.1:57960] [SR:127.0.0.1, state:Connected]] Subscribing on topic persistent://public/default/__transaction_buffer_snapshot / reader-beb7e469f7. consumerId: 3
   2024-07-23T17:46:50,146 - INFO  - [pulsar-io-9-4:ServerCnx] - [[id: 0x0134c04e, L:/127.0.0.1:57954 - R:/127.0.0.1:57960] [SR:127.0.0.1, state:Connected]] Subscribing on topic persistent://public/default/__transaction_buffer_snapshot / reader-e9f0ce9149. consumerId: 2
   2024-07-23T17:46:50,149 - INFO  - [pulsar-io-9-4:ServerCnx] - [[id: 0x0134c04e, L:/127.0.0.1:57954 - R:/127.0.0.1:57960] [SR:127.0.0.1, state:Connected]] Subscribing on topic persistent://public/default/__transaction_buffer_snapshot / reader-d27782ccd4. consumerId: 5
   2024-07-23T17:46:50,150 - INFO  - [pulsar-io-9-4:ServerCnx] - [[id: 0x0134c04e, L:/127.0.0.1:57954 - R:/127.0.0.1:57960] [SR:127.0.0.1, state:Connected]] Subscribing on topic persistent://public/default/__transaction_buffer_snapshot / reader-ff5b692579. consumerId: 4
   2024-07-23T17:46:50,174 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot][reader-ff5b692579] Subscribed to topic on localhost/127.0.0.1:57954 -- consumer: 4
   2024-07-23T17:46:50,177 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot] [reader-ff5b692579] Closed consumer
   2024-07-23T17:46:50,186 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot][reader-d27782ccd4] Subscribed to topic on localhost/127.0.0.1:57954 -- consumer: 5
   2024-07-23T17:46:50,187 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot][reader-e9f0ce9149] Subscribed to topic on localhost/127.0.0.1:57954 -- consumer: 2
   2024-07-23T17:46:50,187 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot] [reader-d27782ccd4] Closed consumer
   2024-07-23T17:46:50,188 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot] [reader-e9f0ce9149] Closed consumer
   2024-07-23T17:46:50,188 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot][reader-beb7e469f7] Subscribed to topic on localhost/127.0.0.1:57954 -- consumer: 3
   2024-07-23T17:46:50,190 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot] [reader-beb7e469f7] Closed consumer
   2024-07-23T17:46:50,190 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot][reader-8d442bc96f] Subscribed to topic on localhost/127.0.0.1:57954 -- consumer: 1
   2024-07-23T17:46:50,191 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot] [reader-8d442bc96f] Closed consumer
   ```
   
   Even though the `numTransactionReplayThreadPoolSize` is 1, there are 5 pending readers from the "Subscribing on" logs.
   
   After this change, the logs become
   
   ```
   2024-07-23T17:49:48,902 - INFO  - [pulsar-io-9-1:ServerCnx] - [[id: 0x41f78fc2, L:/127.0.0.1:58007 - R:/127.0.0.1:58013] [SR:127.0.0.1, state:Connected]] Subscribing on topic persistent://public/default/__transaction_buffer_snapshot / reader-bef854f9d0. consumerId: 1
   2024-07-23T17:49:48,940 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot][reader-bef854f9d0] Subscribed to topic on localhost/127.0.0.1:58007 -- consumer: 1
   2024-07-23T17:49:48,943 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot] [reader-bef854f9d0] Closed consumer
   2024-07-23T17:49:48,947 - INFO  - [pulsar-io-9-1:ServerCnx] - [[id: 0x41f78fc2, L:/127.0.0.1:58007 - R:/127.0.0.1:58013] [SR:127.0.0.1, state:Connected]] Subscribing on topic persistent://public/default/__transaction_buffer_snapshot / reader-bb423c5246. consumerId: 2
   2024-07-23T17:49:48,954 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot][reader-bb423c5246] Subscribed to topic on localhost/127.0.0.1:58007 -- consumer: 2
   2024-07-23T17:49:48,956 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot] [reader-bb423c5246] Closed consumer
   2024-07-23T17:49:48,961 - INFO  - [pulsar-io-9-1:ServerCnx] - [[id: 0x41f78fc2, L:/127.0.0.1:58007 - R:/127.0.0.1:58013] [SR:127.0.0.1, state:Connected]] Subscribing on topic persistent://public/default/__transaction_buffer_snapshot / reader-11542281ee. consumerId: 3
   2024-07-23T17:49:48,964 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot][reader-11542281ee] Subscribed to topic on localhost/127.0.0.1:58007 -- consumer: 3
   2024-07-23T17:49:48,965 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot] [reader-11542281ee] Closed consumer
   2024-07-23T17:49:48,970 - INFO  - [pulsar-io-9-1:ServerCnx] - [[id: 0x41f78fc2, L:/127.0.0.1:58007 - R:/127.0.0.1:58013] [SR:127.0.0.1, state:Connected]] Subscribing on topic persistent://public/default/__transaction_buffer_snapshot / reader-4826069b23. consumerId: 4
   2024-07-23T17:49:48,974 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot][reader-4826069b23] Subscribed to topic on localhost/127.0.0.1:58007 -- consumer: 4
   2024-07-23T17:49:48,975 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot] [reader-4826069b23] Closed consumer
   2024-07-23T17:49:48,980 - INFO  - [pulsar-io-9-1:ServerCnx] - [[id: 0x41f78fc2, L:/127.0.0.1:58007 - R:/127.0.0.1:58013] [SR:127.0.0.1, state:Connected]] Subscribing on topic persistent://public/default/__transaction_buffer_snapshot / reader-5c857ecb26. consumerId: 5
   2024-07-23T17:49:48,984 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot][reader-5c857ecb26] Subscribed to topic on localhost/127.0.0.1:58007 -- consumer: 5
   2024-07-23T17:49:48,985 - INFO  - [pulsar-io-9-3:ConsumerImpl] - [persistent://public/default/__transaction_buffer_snapshot] [reader-5c857ecb26] Closed consumer
   ```


-- 
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][broker] Reduce the CPU pressure from the transaction buffer in rolling restarts [pulsar]

Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode commented on PR #23062:
URL: https://github.com/apache/pulsar/pull/23062#issuecomment-2249605010

   @liangyepianzhou @congbobo184 @gaoran10 Please take a look


-- 
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][broker] Reduce the CPU pressure from the transaction buffer in rolling restarts [pulsar]

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on PR #23062:
URL: https://github.com/apache/pulsar/pull/23062#issuecomment-2244798112

   Mark it as draft to avoid repeated creation of reader. It's better to maintain a long live reader.


-- 
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][broker] Reduce the CPU pressure from the transaction buffer in rolling restarts [pulsar]

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on PR #23062:
URL: https://github.com/apache/pulsar/pull/23062#issuecomment-2244239245

   Let me fix the failed tests first


-- 
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][broker] Reduce the CPU pressure from the transaction buffer in rolling restarts [pulsar]

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #23062:
URL: https://github.com/apache/pulsar/pull/23062#discussion_r1693945175


##########
pulsar-broker/src/main/java/org/apache/pulsar/utils/SimpleCache.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.pulsar.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+import lombok.RequiredArgsConstructor;
+
+@RequiredArgsConstructor
+public class SimpleCache<K, V> {

Review Comment:
   I changed the implementation now. The main difference from your example here is that I didn't add a `shutdown` method because the shutdown of the executor will cancel all pending scheduled tasks.



-- 
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][broker] Reduce the CPU pressure from the transaction buffer in rolling restarts [pulsar]

Posted by "Demogorgon314 (via GitHub)" <gi...@apache.org>.
Demogorgon314 commented on code in PR #23062:
URL: https://github.com/apache/pulsar/pull/23062#discussion_r1691447000


##########
pulsar-broker/src/main/java/org/apache/pulsar/utils/SimpleCache.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.pulsar.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+import lombok.RequiredArgsConstructor;
+
+@RequiredArgsConstructor
+public class SimpleCache<K, V> {

Review Comment:
   ```
   public class SimpleCache<K, V> {
       private class CacheEntry {
           V value;
           long lastAccessTime;
           Consumer<V> expireCallback;
   
           CacheEntry(V value, Consumer<V> expireCallback) {
               this.value = value;
               this.expireCallback = expireCallback;
               this.lastAccessTime = System.currentTimeMillis();
           }
       }
   
       private final HashMap<K, CacheEntry> cache = new HashMap<>();
       private final ScheduledFuture<?> scheduledFuture;
       private final long evictionDelay;
   
       public SimpleCache(ScheduledExecutorService scheduler, long evictionDelay) {
           this.evictionDelay = evictionDelay;
           this.scheduledFuture =
                   scheduler.scheduleAtFixedRate(this::evictionTask, 100, 100, TimeUnit.MILLISECONDS);
       }
   
       public synchronized V get(final K key, final Supplier<V> valueSupplier, final Consumer<V> expireCallback) {
           CacheEntry existingValue = cache.get(key);
           if (existingValue != null) {
               existingValue.lastAccessTime = System.currentTimeMillis();
               return existingValue.value;
           }
           final V value = valueSupplier.get();
           cache.put(key, new CacheEntry(value, expireCallback));
           return value;
       }
   
       private void evictionTask() {
           long now = System.currentTimeMillis();
           for (K key : cache.keySet()) {
               CacheEntry entry = cache.get(key);
               if (entry != null && (now - entry.lastAccessTime) > evictionDelay) {
                   CacheEntry remove = cache.remove(key);
                   if (remove != null) {
                       remove.expireCallback.accept(remove.value);
                   }
               }
           }
       }
   
       public void shutdown() {
           scheduledFuture.cancel(true);
       }
   }
   
   ```
   
   Maybe we can use a `scheduleAtFixedRate` to check the key expiry



-- 
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][broker] Reduce the CPU pressure from the transaction buffer in rolling restarts [pulsar]

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on PR #23062:
URL: https://github.com/apache/pulsar/pull/23062#issuecomment-2255843175

   Merge it first.


-- 
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][broker] Reduce the CPU pressure from the transaction buffer in rolling restarts [pulsar]

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower merged PR #23062:
URL: https://github.com/apache/pulsar/pull/23062


-- 
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