Shawyeok opened a new issue, #15445: URL: https://github.com/apache/pulsar/issues/15445
**Describe the bug** When use `Key_Shared`, if one consumer consume slowly and others are normal, `MessageRedeliveryController#messagesToRedeliver` will keep growing and could be very large. `MessageRedeliveryController#getMessagesToReplayNow` will be very expensive cause `messagesToRedeliver.items()` is a O(n) operation in both time and space complexity. https://github.com/apache/pulsar/blob/2b2e0c50183c71e954f5c6e8bfcd7e36130279a5/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/MessageRedeliveryController.java#L109-L122 In this situation, one thread cpu usage could be 100%, this could effects the publish latency of other topics on the same broker instance. **To Reproduce** Steps to reproduce the behavior: 1. start a standalone cluster 2. start a producer ```shell $ bin/pulsar-perf produce -mk random persistent://public/default/test ``` 4. start a consumer that consume very slowly and a normal consumer ```shell $ bin/pulsar-perf consume -st Key_Shared persistent://public/default/test $ bin/pulsar-perf consume -st Key_Shared -r 0.1 persistent://public/default/test ``` **Screenshots** CPU flame graph  **Additional context** - pulsar: `2.8.1` -- 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]
