feat(config): connmgr: expose silence period (#10827)

This commit is contained in:
Hector Sanjuan 2025-06-17 15:55:57 +02:00 committed by GitHub
parent 0cf1b22536
commit eb6cc02c06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 34 additions and 10 deletions

View File

@ -95,6 +95,9 @@ const DefaultConnMgrLowWater = 32
// grace period.
const DefaultConnMgrGracePeriod = time.Second * 20
// DefaultConnMgrSilencePeriod controls how often the connection manager enforces the limits.
const DefaultConnMgrSilencePeriod = time.Second * 10
// DefaultConnMgrType is the default value for the connection managers
// type.
const DefaultConnMgrType = "basic"

View File

@ -104,10 +104,11 @@ type Transports struct {
// ConnMgr defines configuration options for the libp2p connection manager.
type ConnMgr struct {
Type *OptionalString `json:",omitempty"`
LowWater *OptionalInteger `json:",omitempty"`
HighWater *OptionalInteger `json:",omitempty"`
GracePeriod *OptionalDuration `json:",omitempty"`
Type *OptionalString `json:",omitempty"`
LowWater *OptionalInteger `json:",omitempty"`
HighWater *OptionalInteger `json:",omitempty"`
GracePeriod *OptionalDuration `json:",omitempty"`
SilencePeriod *OptionalDuration `json:",omitempty"`
}
// ResourceMgr defines configuration options for the libp2p Network Resource Manager

View File

@ -49,7 +49,9 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part
grace := cfg.Swarm.ConnMgr.GracePeriod.WithDefault(config.DefaultConnMgrGracePeriod)
low := int(cfg.Swarm.ConnMgr.LowWater.WithDefault(config.DefaultConnMgrLowWater))
high := int(cfg.Swarm.ConnMgr.HighWater.WithDefault(config.DefaultConnMgrHighWater))
connmgr = fx.Provide(libp2p.ConnectionManager(low, high, grace))
silence := cfg.Swarm.ConnMgr.SilencePeriod.WithDefault(config.DefaultConnMgrSilencePeriod)
connmgr = fx.Provide(libp2p.ConnectionManager(low, high, grace, silence))
default:
return fx.Error(fmt.Errorf("unrecognized Swarm.ConnMgr.Type: %q", connMgrType))
}

View File

@ -25,9 +25,12 @@ type Libp2pOpts struct {
Opts []libp2p.Option `group:"libp2p"`
}
func ConnectionManager(low, high int, grace time.Duration) func() (opts Libp2pOpts, err error) {
func ConnectionManager(low, high int, grace, silence time.Duration) func() (opts Libp2pOpts, err error) {
return func() (opts Libp2pOpts, err error) {
cm, err := connmgr.NewConnManager(low, high, connmgr.WithGracePeriod(grace))
cm, err := connmgr.NewConnManager(low, high,
connmgr.WithGracePeriod(grace),
connmgr.WithSilencePeriod(silence),
)
if err != nil {
return opts, err
}

View File

@ -88,6 +88,10 @@ To revert to the previous behavior for A/B testing, set `Internal.Bitswap.Broadc
The `filestore` command has a new option, `--remove-bad-blocks`, to verify objects in the filestore and remove those that fail verification.
#### ConnMgr.SilencePeriod configuration setting exposed
This connection manager option controls how often connections are swept and potentially terminated. See the [ConnMgr documentation](https://github.com/ipfs/kubo/blob/master/docs/config.md#swarmconnmgrsilenceperiod).
#### 📦️ Important dependency updates
- update `go-libp2p-kad-dht` to [v0.33.0](https://github.com/libp2p/go-libp2p-kad-dht/releases/tag/v0.33.0)

View File

@ -171,6 +171,7 @@ config file at runtime.
- [`Swarm.ConnMgr.LowWater`](#swarmconnmgrlowwater)
- [`Swarm.ConnMgr.HighWater`](#swarmconnmgrhighwater)
- [`Swarm.ConnMgr.GracePeriod`](#swarmconnmgrgraceperiod)
- [`Swarm.ConnMgr.SilencePeriod`](#swarmconnmgrsilenceperiod)
- [`Swarm.ResourceMgr`](#swarmresourcemgr)
- [`Swarm.ResourceMgr.Enabled`](#swarmresourcemgrenabled)
- [`Swarm.ResourceMgr.MaxMemory`](#swarmresourcemgrmaxmemory)
@ -2357,8 +2358,9 @@ Type: `optionalString` (default when unset or empty)
The basic connection manager uses a "high water", a "low water", and internal
scoring to periodically close connections to free up resources. When a node
using the basic connection manager reaches `HighWater` idle connections, it will
close the least useful ones until it reaches `LowWater` idle connections.
using the basic connection manager reaches `HighWater` idle connections, it
will close the least useful ones until it reaches `LowWater` idle
connections. The process of closing connections happens every `SilencePeriod`.
The connection manager considers a connection idle if:
@ -2377,7 +2379,8 @@ The connection manager considers a connection idle if:
"Type": "basic",
"LowWater": 100,
"HighWater": 200,
"GracePeriod": "30s"
"GracePeriod": "30s",
"SilencePeriod": "10s"
}
}
}
@ -2411,6 +2414,14 @@ Default: `"20s"`
Type: `optionalDuration`
##### `Swarm.ConnMgr.SilencePeriod`
SilencePeriod is the time duration between connection manager runs, when connections that are idle are closed.
Default: `"10s"`
Type: `optionalDuration`
### `Swarm.ResourceMgr`
Learn more about Kubo's usage of libp2p Network Resource Manager