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

fix(pubsub): increase subscription buffer size to prevent message drops #1989

Merged
merged 1 commit into from
Jan 19, 2025

Conversation

olegshmuelov
Copy link
Contributor

Problem
Messages from libp2p were being validated successfully but were not reaching the message queue.
Upon enabling logs for the libp2p pubsub package, it was discovered that the following error was causing message drops:

Can't deliver message to subscription for topic ssv.v2....; subscriber too slow

This occurred because the default subscription buffer size was too small (32), resulting in messages being dropped when the buffer was full.

Solution

  • Increased the subscription buffer size to 128 to handle bursts of incoming messages and reduce message drops.
  • The value 128 was chosen based on:
    • It provides 4x the default buffer size, which is sufficient for moderate workloads.
    • it balances memory usage and burst tolerance without overcommitting resources.

After increasing the subscription buffer size to 128, we observed a drop in transmit bandwidth and rate of transmitted packets (see attached screenshot). This is a positive outcome, as the change mitigates message loss by providing more time for subscribers to process messages under load. The reduced bandwidth usage likely results from fewer message drops and retries, as the larger buffer prevents the "subscriber too slow" errors that previously caused excessive retransmissions.
Screenshot 2025-01-19 at 14 04 29

Additionally, the CPU usage dropped slightly but not significantly, and memory usage remained unchanged. These resource metrics suggest the fix improved message handling efficiency without introducing notable overhead.
Further tuning may still be required based on actual workload

@olegshmuelov olegshmuelov self-assigned this Jan 19, 2025
Copy link
Contributor

@moshe-blox moshe-blox left a comment

Choose a reason for hiding this comment

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

Great work 🔥

@olegshmuelov olegshmuelov merged commit 4ba0e85 into stage Jan 19, 2025
7 checks passed
@olegshmuelov olegshmuelov deleted the fix/pubsub-subscription-buffer branch January 19, 2025 13:34
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