Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kraken: Count number of unprefetched messages in queue + increase prefetch #3968

Merged
merged 2 commits into from
Apr 7, 2023

Conversation

pbougue
Copy link
Contributor

@pbougue pbougue commented Apr 6, 2023

Increasing prefetched messages (default to 100) should improve retrieval speed.
Consume messages until this unprefetched+prefetched count (or max - increased to 10000 by default) is reached.
This allows for larger timeouts when there are unprefetched messages, as Kraken will stop at that number, and avoid continuing as long as messages arrive (which is constantly the case for some contributors). If there are only prefetched messages, rushing is possible.

Also:

  • Add short "prefetch" timeouts config - 100ms and 10s (in additional to "classic" ones - increased to 1s and 2min)
  • Common queue declaration (to avoid bad-redeclaration)
  • Check (only for log currently) that consumer is unique
  • minor cleanups of useless variables

Notes:

  • DeclareQueue() uses DeclareQueueWithCounts() under the cover in SimpleAmpqClient, which allows for the common queue declaration refactor.
  • BasicConsume() declares a consumer that prefetches 1 message by default. DeclareQueueWithCounts doesn't include prefetched messages. Hence tricky max_message_to_retrieve.

JIRA: https://navitia.atlassian.net/browse/NAV-1879

Increasing prefetched messages should improve retrieval speed.
Consume messages until this unprefetched+prefetched count (or max) is
reached.
This allows for larger timeouts when there are unprefetched messages, as
Kraken will stop at that number, and avoid continuing as long as messages
arrive (which is constantly the case for some contributors).
If there are only prefetched messages, rushing is possible.

Also:
* Add short "prefetch" timeouts config (in additional to "classic" ones)
* Common queue declaration (to avoid bad-redeclaration)
* Check (only for log currently) that consumer is unique
* minor cleanups of useless variables

Notes:
* DeclareQueue() uses DeclareQueueWithCounts() under the cover in
  SimpleAmpqClient, which allows for the common queue declaration refactor.
* BasicConsume() declares a consumer that prefetches 1 message by default.
  DeclareQueueWithCounts doesn't count prefetched messages.
  Hence tricky max_message_to_retrieve.

JIRA: https://navitia.atlassian.net/browse/NAV-1879
@pbougue pbougue requested review from woshilapin, xlqian and pbench April 6, 2023 07:30
if (queue_is_empty_or_unreachable) {
LOG4CPLUS_ERROR(logger,
"Could not retrieve all the messages counted for RabbitMQ's RT queue " << queue_name);
// going on with what was retrieved so far
break;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An idea by @pbench (correct me if needed) to simplify code and params would be:

  1. put a continue here instead of a break
  2. only one total_timeout (i.e. 30s), single timeout may be hardcoded
  3. remove count and just go with what was retrieved during those 30s

This would simplify code, the inconvenient is to have a strict latency even if there is only one message (and tests would need a little parameter adaptation for that reason).

Copy link
Member

@xlqian xlqian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 GG

@pbougue pbougue merged commit a112350 into dev Apr 7, 2023
@pbougue pbougue deleted the improve_rabbit_rt_message_retrieval branch April 7, 2023 12:15
@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 7, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

51.8% 51.8% Coverage
0.0% 0.0% Duplication

pbougue pushed a commit that referenced this pull request May 3, 2023
As the number of prefetched message is unsure when no ready message is
available, avoid logging in this case.

improvement after #3968

fix https://github.com/hove-io/navitia-docker-compose/issues/153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants