Skip to content

Conversation

@poorbarcode
Copy link
Contributor

@poorbarcode poorbarcode commented Nov 20, 2022

Motivation

The Dispatch rate limiter serves two purposes:

  1. Limit your consumption speed
  2. When there are many backlogs, bk can be protected to avoid excessive I/O

But the current design has the following problems:

available permits indicates how many messages the client needs, and then uses the rate limiter to determine how many entries to read. If batch production is not enabled, it is working. When batch production is enabled, the rate limiter counts the number of entries as the number of messages, resulting in excessive entries to be read.

In PR #6719, preciseDispatcherFlowControl was added to optimize the above problem: If enabled preciseDispatcherFlowControl, we call availablePermits / avgMessagesPerEntry to calculate how many entries to read, but this did not solve the problem because that:

  • When you compute avgMessagesPerEntry, randomly take a consumer from the subscription, and get attribute stat.avgMessagesPerEntry, it is possible to null the property. We should look for the consumer that meets condition stat.avgMessagesPerEntry != null.
  • The rate limiter still counts the number of entries as the number of messages.

Modifications

  • First, calculate how many messages to read by rate limiter, and then calculate how many entries to read by avgMessagesPerEntry
  • When calculating the "avgMessagesPerEntry," look up the attribute avgMessagesPerEntry from the consumers under subscription, if all consumers avgMessagesPerEntry is zero, look up under the topic.
  • Abstracting the method calculateToRead of Single consumer dispatcher and Multi consumer dispatcher into the parent class AbstractDispatcher, this will save codes.

Follow-up PR

After this PR, there are still such scenarios: failing to get avgMessagesPerEntry resulting in reading excessive messages:

  1. Create a new topic and a new subscription, since no data has been consumed yet, the consumer does not know how many messages per entry.
  2. Use the created topic, only one subscription, and use the failover mode for consumption. Every time a new consumer becomes an active consumer, can not get avgMessagesPerEntry.

The PR below will fix it.

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Nov 20, 2022
@poorbarcode poorbarcode force-pushed the improve/make_dispatch_limit_more_precise branch 2 times, most recently from 9f74a0b to be27cbd Compare November 23, 2022 08:59
@poorbarcode poorbarcode changed the title [do not merge] [improve] [broker] Make dispatch rate limiter more precise [improve] [broker] Make dispatch rate limiter more precise Nov 23, 2022
@poorbarcode poorbarcode force-pushed the improve/make_dispatch_limit_more_precise branch 2 times, most recently from 5db855a to fccd477 Compare November 23, 2022 16:30
@rdhabalia
Copy link
Contributor

first of all adding precise terminology in dispatch path is not correct and really misguiding. also have you considered performance impact due to this change? we should not take any performance impact because of this requirement.

@poorbarcode
Copy link
Contributor Author

poorbarcode commented Dec 2, 2022

Hi @rdhabalia

also have you considered performance impact due to this change?

This patch has almost no performance penalty, except that the first time a consumer is created it retrieves a property of another consumer directly from memory

@poorbarcode poorbarcode force-pushed the improve/make_dispatch_limit_more_precise branch 3 times, most recently from a37e875 to ffd378c Compare December 5, 2022 09:15
@Technoboy- Technoboy- changed the title [improve] [broker] Make dispatch rate limiter more precise [improve][broker] Make dispatch rate limiter more precise Dec 7, 2022
@Technoboy- Technoboy- closed this Dec 7, 2022
@Technoboy- Technoboy- reopened this Dec 7, 2022
@Technoboy- Technoboy- added this to the 2.12.0 milestone Dec 7, 2022
@Technoboy- Technoboy- added type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages area/broker labels Dec 7, 2022
@poorbarcode poorbarcode force-pushed the improve/make_dispatch_limit_more_precise branch from ffd378c to 529a928 Compare December 15, 2022 20:51
@github-actions
Copy link

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions bot added the Stale label Jan 20, 2023
@poorbarcode poorbarcode modified the milestones: 3.0.0, 3.1.0 Apr 10, 2023
@Technoboy- Technoboy- removed this from the 3.1.0 milestone Jul 31, 2023
@Technoboy- Technoboy- added this to the 3.2.0 milestone Jul 31, 2023
@Technoboy- Technoboy- modified the milestones: 3.2.0, 3.3.0 Dec 22, 2023
@coderzc coderzc modified the milestones: 3.3.0, 3.4.0 May 8, 2024
@lhotari
Copy link
Member

lhotari commented Oct 14, 2024

please rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/broker doc-not-needed Your PR changes do not impact docs ready-to-test release/4.0.9 Stale type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants