discovery: make gossip filter semaphore capacity configurable

In this commit, we make the gossip filter semaphore capacity configurable
through a new FilterConcurrency field. This change allows node operators
to tune the number of concurrent gossip filter applications based on
their node's resources and network position.

The previous hard-coded limit of 5 concurrent filter applications could
become a bottleneck when multiple peers attempt to synchronize
simultaneously. By making this value configurable via the new
gossip.filter-concurrency option, operators can increase this limit
for better performance on well-resourced nodes or maintain conservative
values on resource-constrained systems.

We keep the default value at 5 to maintain backward compatibility and
avoid unexpected resource usage increases for existing deployments. The
sample configuration file is updated to document this new option.
This commit is contained in:
Olaoluwa Osuntokun
2025-07-21 11:51:37 -05:00
committed by Oliver Gugger
parent f6c5cd7ffc
commit 57872b9cff
3 changed files with 23 additions and 4 deletions

View File

@@ -25,8 +25,9 @@ const (
// network as possible.
DefaultHistoricalSyncInterval = time.Hour
// filterSemaSize is the capacity of gossipFilterSema.
filterSemaSize = 5
// DefaultFilterConcurrency is the default maximum number of concurrent
// gossip filter applications that can be processed.
DefaultFilterConcurrency = 5
// DefaultMsgBytesBurst is the allotted burst in bytes we'll permit.
// This is the most that can be sent in a given go. Requests beyond
@@ -136,6 +137,10 @@ type SyncManagerCfg struct {
// AllotedMsgBytesBurst is the amount of burst bytes we'll permit, if
// we've exceeded the hard upper limit.
AllotedMsgBytesBurst uint64
// FilterConcurrency is the maximum number of concurrent gossip filter
// applications that can be processed. If not set, defaults to 5.
FilterConcurrency int
}
// SyncManager is a subsystem of the gossiper that manages the gossip syncers
@@ -207,8 +212,13 @@ type SyncManager struct {
// newSyncManager constructs a new SyncManager backed by the given config.
func newSyncManager(cfg *SyncManagerCfg) *SyncManager {
filterSema := make(chan struct{}, filterSemaSize)
for i := 0; i < filterSemaSize; i++ {
filterConcurrency := cfg.FilterConcurrency
if filterConcurrency == 0 {
filterConcurrency = DefaultFilterConcurrency
}
filterSema := make(chan struct{}, filterConcurrency)
for i := 0; i < filterConcurrency; i++ {
filterSema <- struct{}{}
}