From 4ba0e857a494af4d0fb456e8c9adbe3258c5f875 Mon Sep 17 00:00:00 2001 From: olegshmuelov <45327364+olegshmuelov@users.noreply.github.com> Date: Sun, 19 Jan 2025 15:33:59 +0200 Subject: [PATCH] increase subscription buffer size (#1989) --- network/topics/container.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/network/topics/container.go b/network/topics/container.go index 4fd2a32442..0c905e5b31 100644 --- a/network/topics/container.go +++ b/network/topics/container.go @@ -6,6 +6,9 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" ) +// Increased from the default (32) to reduce message drops caused by slow subscribers. +const subscriptionBufferSize = 128 + type onTopicJoined func(ps *pubsub.PubSub, topic *pubsub.Topic) type topicsContainer struct { @@ -94,6 +97,8 @@ func (tc *topicsContainer) Subscribe(name string, opts ...pubsub.SubOpt) (*pubsu return nil, err } + opts = append(opts, pubsub.WithBufferSize(subscriptionBufferSize)) + s, err := topic.Subscribe(opts...) if err != nil { return nil, err