[feat][broker] Add config to count filtered entries towards rate limits
Motivation
Currently, when using entry filters, filtered out messages do not count against the rate limit. Therefore, a subscription that is completely filtered will never be throttled due to rate limiting. When the messages are delivered to the consumer for a filtered subscription, those messages will count against the rate limit, and in that case, the message filtering can be throttled because the check to delay readMoreEntries() happens before message filtering. Therefore, the rate limit will essentially be increased as a function of the percent of messages let through the filter (some quick math is that the new rate is likely dispatchRate * (1 / percentDelivered), where percent delivered is a percent as a decimal).
It's possible that some use cases prefer this behavior, but in my case, I think it'd be valuable to include these filtered messages in the dispatch throttling because these messages still cost the broker network, memory, and cpu. This PR adds a configuration to count filtered out messages towards dispatch rate limits for the broker, the topic, and the subscription.
Modifications
- Add configuration named
dispatchThrottlingForFilteredEntriesEnabled. Default it to false so we maintain the original behavior. When true, count filtered messages against rate limits. - Refactor the code to
acquirePermitsForDeliveredMessagesso that it is in theAbstractBaseDispatcher, which makes it available to the entry filtering logic.
Verifying this change
A new test is added as part of this PR.
Does this pull request potentially affect one of the following parts:
This PR introduces a new config while maintaining the current behavior.
Documentation
- [x]
doc-not-neededConfig docs are auto-generated.