Documentation ¶
Overview ¶
Package rcmgr is the resource manager for go-libp2p. This allows you to track resources being used throughout your go-libp2p process. As well as making sure that the process doesn't use more resources than what you define as your limits. The resource manager only knows about things it is told about, so it's the responsibility of the user of this library (either go-libp2p or a go-libp2p user) to make sure they check with the resource manager before actually allocating the resource.
Index ¶
- Variables
- func IsConnScope(name string) bool
- func IsSpan(name string) bool
- func IsStreamScope(name string) bool
- func IsSystemScope(name string) bool
- func IsTransientScope(name string) bool
- func MustRegisterWith(reg prometheus.Registerer)
- func NewResourceManager(limits Limiter, opts ...Option) (network.ResourceManager, error)
- func ParseProtocolScopeName(name string) string
- func PeerStrInScopeName(name string) string
- type Allowlist
- type BaseLimit
- func (l *BaseLimit) Apply(l2 BaseLimit)
- func (l BaseLimit) GetConnLimit(dir network.Direction) int
- func (l BaseLimit) GetConnTotalLimit() int
- func (l BaseLimit) GetFDLimit() int
- func (l BaseLimit) GetMemoryLimit() int64
- func (l BaseLimit) GetStreamLimit(dir network.Direction) int
- func (l BaseLimit) GetStreamTotalLimit() int
- func (l BaseLimit) ToResourceLimits() ResourceLimits
- type BaseLimitIncrease
- type ConcreteLimitConfig
- type ConnLimitPerSubnet
- type ErrMemoryLimitExceeded
- type ErrStreamOrConnLimitExceeded
- type Limit
- type LimitVal
- type LimitVal64
- type Limiter
- type MetricsReporter
- type NetworkPrefixLimit
- type Option
- func WithAllowlistedMultiaddrs(mas []multiaddr.Multiaddr) Option
- func WithLimitPerSubnet(ipv4 []ConnLimitPerSubnet, ipv6 []ConnLimitPerSubnet) Option
- func WithMetrics(reporter MetricsReporter) Option
- func WithMetricsDisabled() Option
- func WithNetworkPrefixLimit(ipv4 []NetworkPrefixLimit, ipv6 []NetworkPrefixLimit) Option
- func WithTrace(path string) Option
- func WithTraceReporter(reporter TraceReporter) Option
- type PartialLimitConfig
- type ResourceLimits
- type ResourceManagerStat
- type ResourceManagerState
- type ResourceScopeLimiter
- type ScalingLimitConfig
- func (cfg *ScalingLimitConfig) AddPeerLimit(p peer.ID, base BaseLimit, inc BaseLimitIncrease)
- func (cfg *ScalingLimitConfig) AddProtocolLimit(proto protocol.ID, base BaseLimit, inc BaseLimitIncrease)
- func (cfg *ScalingLimitConfig) AddProtocolPeerLimit(proto protocol.ID, base BaseLimit, inc BaseLimitIncrease)
- func (cfg *ScalingLimitConfig) AddServiceLimit(svc string, base BaseLimit, inc BaseLimitIncrease)
- func (cfg *ScalingLimitConfig) AddServicePeerLimit(svc string, base BaseLimit, inc BaseLimitIncrease)
- func (cfg *ScalingLimitConfig) AutoScale() ConcreteLimitConfig
- func (cfg *ScalingLimitConfig) Scale(memory int64, numFD int) ConcreteLimitConfig
- type StatsTraceReporter
- type TraceEvt
- type TraceEvtTyp
- type TraceReporter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultLimits = ScalingLimitConfig{ SystemBaseLimit: BaseLimit{ ConnsInbound: 64, ConnsOutbound: 128, Conns: 128, StreamsInbound: 64 * 16, StreamsOutbound: 128 * 16, Streams: 128 * 16, Memory: 128 << 20, FD: 256, }, SystemLimitIncrease: BaseLimitIncrease{ ConnsInbound: 64, ConnsOutbound: 128, Conns: 128, StreamsInbound: 64 * 16, StreamsOutbound: 128 * 16, Streams: 128 * 16, Memory: 1 << 30, FDFraction: 1, }, TransientBaseLimit: BaseLimit{ ConnsInbound: 32, ConnsOutbound: 64, Conns: 64, StreamsInbound: 128, StreamsOutbound: 256, Streams: 256, Memory: 32 << 20, FD: 64, }, TransientLimitIncrease: BaseLimitIncrease{ ConnsInbound: 16, ConnsOutbound: 32, Conns: 32, StreamsInbound: 128, StreamsOutbound: 256, Streams: 256, Memory: 128 << 20, FDFraction: 0.25, }, AllowlistedSystemBaseLimit: BaseLimit{ ConnsInbound: 64, ConnsOutbound: 128, Conns: 128, StreamsInbound: 64 * 16, StreamsOutbound: 128 * 16, Streams: 128 * 16, Memory: 128 << 20, FD: 256, }, AllowlistedSystemLimitIncrease: BaseLimitIncrease{ ConnsInbound: 64, ConnsOutbound: 128, Conns: 128, StreamsInbound: 64 * 16, StreamsOutbound: 128 * 16, Streams: 128 * 16, Memory: 1 << 30, FDFraction: 1, }, AllowlistedTransientBaseLimit: BaseLimit{ ConnsInbound: 32, ConnsOutbound: 64, Conns: 64, StreamsInbound: 128, StreamsOutbound: 256, Streams: 256, Memory: 32 << 20, FD: 64, }, AllowlistedTransientLimitIncrease: BaseLimitIncrease{ ConnsInbound: 16, ConnsOutbound: 32, Conns: 32, StreamsInbound: 128, StreamsOutbound: 256, Streams: 256, Memory: 128 << 20, FDFraction: 0.25, }, ServiceBaseLimit: BaseLimit{ StreamsInbound: 1024, StreamsOutbound: 4096, Streams: 4096, Memory: 64 << 20, }, ServiceLimitIncrease: BaseLimitIncrease{ StreamsInbound: 512, StreamsOutbound: 2048, Streams: 2048, Memory: 128 << 20, }, ServicePeerBaseLimit: BaseLimit{ StreamsInbound: 128, StreamsOutbound: 256, Streams: 256, Memory: 16 << 20, }, ServicePeerLimitIncrease: BaseLimitIncrease{ StreamsInbound: 4, StreamsOutbound: 8, Streams: 8, Memory: 4 << 20, }, ProtocolBaseLimit: BaseLimit{ StreamsInbound: 512, StreamsOutbound: 2048, Streams: 2048, Memory: 64 << 20, }, ProtocolLimitIncrease: BaseLimitIncrease{ StreamsInbound: 256, StreamsOutbound: 512, Streams: 512, Memory: 164 << 20, }, ProtocolPeerBaseLimit: BaseLimit{ StreamsInbound: 64, StreamsOutbound: 128, Streams: 256, Memory: 16 << 20, }, ProtocolPeerLimitIncrease: BaseLimitIncrease{ StreamsInbound: 4, StreamsOutbound: 8, Streams: 16, Memory: 4, }, PeerBaseLimit: BaseLimit{ ConnsInbound: 8, ConnsOutbound: 8, Conns: 8, StreamsInbound: 256, StreamsOutbound: 512, Streams: 512, Memory: 64 << 20, FD: 4, }, PeerLimitIncrease: BaseLimitIncrease{ StreamsInbound: 128, StreamsOutbound: 256, Streams: 256, Memory: 128 << 20, FDFraction: 1.0 / 64, }, ConnBaseLimit: BaseLimit{ ConnsInbound: 1, ConnsOutbound: 1, Conns: 1, FD: 1, Memory: 32 << 20, }, StreamBaseLimit: BaseLimit{ StreamsInbound: 1, StreamsOutbound: 1, Streams: 1, Memory: 16 << 20, }, }
DefaultLimits are the limits used by the default limiter constructors.
var DefaultNetworkPrefixLimitV4 = sortNetworkPrefixes([]NetworkPrefixLimit{ { Network: netip.MustParsePrefix("127.0.0.0/8"), ConnCount: math.MaxInt, }, })
var DefaultNetworkPrefixLimitV6 = sortNetworkPrefixes([]NetworkPrefixLimit{ { Network: netip.MustParsePrefix("::1/128"), ConnCount: math.MaxInt, }, })
var InfiniteLimits = ConcreteLimitConfig{ // contains filtered or unexported fields }
InfiniteLimits are a limiter configuration that uses unlimited limits, thus effectively not limiting anything. Keep in mind that the operating system limits the number of file descriptors that an application can use.
Functions ¶
func IsConnScope ¶
func IsStreamScope ¶
func IsSystemScope ¶
func IsTransientScope ¶
func MustRegisterWith ¶ added in v0.29.0
func MustRegisterWith(reg prometheus.Registerer)
func NewResourceManager ¶
func NewResourceManager(limits Limiter, opts ...Option) (network.ResourceManager, error)
func ParseProtocolScopeName ¶
ParseProtocolScopeName returns the service name if name is a serviceScopeName. Otherwise returns ""
func PeerStrInScopeName ¶ added in v0.25.0
PeerStrInScopeName returns "" if name is not a peerScopeName. Returns a string to avoid allocating a peer ID object
Types ¶
type Allowlist ¶
type Allowlist struct {
// contains filtered or unexported fields
}
func GetAllowlist ¶
func GetAllowlist(rcmgr network.ResourceManager) *Allowlist
GetAllowlist tries to get the allowlist from the given resourcemanager interface by checking to see if its concrete type is a resourceManager. Returns nil if it fails to get the allowlist.
func (*Allowlist) Add ¶
Add takes a multiaddr and adds it to the allowlist. The multiaddr should be an ip address of the peer with or without a `/p2p` protocol. e.g. /ip4/1.2.3.4/p2p/QmFoo, /ip4/1.2.3.4, and /ip4/1.2.3.0/ipcidr/24 are valid. /p2p/QmFoo is not valid.
func (*Allowlist) AllowedPeerAndMultiaddr ¶
type BaseLimit ¶
type BaseLimit struct { Streams int `json:",omitempty"` StreamsInbound int `json:",omitempty"` StreamsOutbound int `json:",omitempty"` Conns int `json:",omitempty"` ConnsInbound int `json:",omitempty"` ConnsOutbound int `json:",omitempty"` FD int `json:",omitempty"` Memory int64 `json:",omitempty"` }
BaseLimit is a mixin type for basic resource limits.
func (*BaseLimit) Apply ¶
Apply overwrites all zero-valued limits with the values of l2 Must not use a pointer receiver.
func (BaseLimit) GetConnTotalLimit ¶
func (BaseLimit) GetFDLimit ¶
func (BaseLimit) GetMemoryLimit ¶
func (BaseLimit) GetStreamTotalLimit ¶
func (BaseLimit) ToResourceLimits ¶ added in v0.25.0
func (l BaseLimit) ToResourceLimits() ResourceLimits
ToResourceLimits converts the BaseLimit to a ResourceLimits
type BaseLimitIncrease ¶
type BaseLimitIncrease struct { Streams int `json:",omitempty"` StreamsInbound int `json:",omitempty"` StreamsOutbound int `json:",omitempty"` Conns int `json:",omitempty"` ConnsInbound int `json:",omitempty"` ConnsOutbound int `json:",omitempty"` // Memory is in bytes. Values over 1>>30 (1GiB) don't make sense. Memory int64 `json:",omitempty"` // FDFraction is expected to be >= 0 and <= 1. FDFraction float64 `json:",omitempty"` }
BaseLimitIncrease is the increase per GiB of allowed memory.
func (*BaseLimitIncrease) Apply ¶
func (l *BaseLimitIncrease) Apply(l2 BaseLimitIncrease)
Apply overwrites all zero-valued limits with the values of l2 Must not use a pointer receiver.
type ConcreteLimitConfig ¶ added in v0.25.0
type ConcreteLimitConfig struct {
// contains filtered or unexported fields
}
ConcreteLimitConfig is similar to PartialLimitConfig, but all values are defined. There is no unset "default" value. Commonly constructed by calling PartialLimitConfig.Build(rcmgr.DefaultLimits.AutoScale())
func (ConcreteLimitConfig) ToPartialLimitConfig ¶ added in v0.25.0
func (cfg ConcreteLimitConfig) ToPartialLimitConfig() PartialLimitConfig
ToPartialLimitConfig converts a ConcreteLimitConfig to a PartialLimitConfig. The returned PartialLimitConfig will have no default values.
type ConnLimitPerSubnet ¶ added in v0.35.0
type ConnLimitPerSubnet struct { // This defines how big the subnet is. For example, a /24 subnet has a // PrefixLength of 24. All IPs that share the same 24 bit prefix are in the same // subnet. Are in the same subnet, and bound to the same limit. PrefixLength int // The maximum number of connections allowed for each subnet. ConnCount int }
type ErrMemoryLimitExceeded ¶ added in v0.25.0
type ErrMemoryLimitExceeded struct {
// contains filtered or unexported fields
}
func (*ErrMemoryLimitExceeded) Error ¶ added in v0.25.0
func (e *ErrMemoryLimitExceeded) Error() string
func (*ErrMemoryLimitExceeded) Unwrap ¶ added in v0.25.0
func (e *ErrMemoryLimitExceeded) Unwrap() error
type ErrStreamOrConnLimitExceeded ¶ added in v0.25.0
type ErrStreamOrConnLimitExceeded struct {
// contains filtered or unexported fields
}
func (*ErrStreamOrConnLimitExceeded) Error ¶ added in v0.25.0
func (e *ErrStreamOrConnLimitExceeded) Error() string
func (*ErrStreamOrConnLimitExceeded) Unwrap ¶ added in v0.25.0
func (e *ErrStreamOrConnLimitExceeded) Unwrap() error
type Limit ¶
type Limit interface { // GetMemoryLimit returns the (current) memory limit. GetMemoryLimit() int64 // GetStreamLimit returns the stream limit, for inbound or outbound streams. GetStreamLimit(network.Direction) int // GetStreamTotalLimit returns the total stream limit GetStreamTotalLimit() int // GetConnLimit returns the connection limit, for inbound or outbound connections. GetConnLimit(network.Direction) int // GetConnTotalLimit returns the total connection limit GetConnTotalLimit() int // GetFDLimit returns the file descriptor limit. GetFDLimit() int }
Limit is an object that specifies basic resource limits.
type LimitVal ¶ added in v0.25.0
type LimitVal int
const ( // DefaultLimit is the default value for resources. The exact value depends on the context, but will get values from `DefaultLimits`. DefaultLimit LimitVal = 0 // Unlimited is the value for unlimited resources. An arbitrarily high number will also work. Unlimited LimitVal = -1 // BlockAllLimit is the LimitVal for allowing no amount of resources. BlockAllLimit LimitVal = -2 )
func (LimitVal) MarshalJSON ¶ added in v0.25.0
func (*LimitVal) UnmarshalJSON ¶ added in v0.25.0
type LimitVal64 ¶ added in v0.25.0
type LimitVal64 int64
const ( // Default is the default value for resources. DefaultLimit64 LimitVal64 = 0 // Unlimited is the value for unlimited resources. Unlimited64 LimitVal64 = -1 // BlockAllLimit64 is the LimitVal for allowing no amount of resources. BlockAllLimit64 LimitVal64 = -2 )
func (LimitVal64) Build ¶ added in v0.25.0
func (l LimitVal64) Build(defaultVal int64) int64
func (LimitVal64) MarshalJSON ¶ added in v0.25.0
func (l LimitVal64) MarshalJSON() ([]byte, error)
func (*LimitVal64) UnmarshalJSON ¶ added in v0.25.0
func (l *LimitVal64) UnmarshalJSON(b []byte) error
type Limiter ¶
type Limiter interface { GetSystemLimits() Limit GetTransientLimits() Limit GetAllowlistedSystemLimits() Limit GetAllowlistedTransientLimits() Limit GetServiceLimits(svc string) Limit GetServicePeerLimits(svc string) Limit GetProtocolLimits(proto protocol.ID) Limit GetProtocolPeerLimits(proto protocol.ID) Limit GetPeerLimits(p peer.ID) Limit GetStreamLimits(p peer.ID) Limit GetConnLimits() Limit }
Limiter is the interface for providing limits to the resource manager.
func NewDefaultLimiterFromJSON ¶
NewDefaultLimiterFromJSON creates a new limiter by parsing a json configuration, using the default limits for fallback.
func NewFixedLimiter ¶
func NewFixedLimiter(conf ConcreteLimitConfig) Limiter
func NewLimiterFromJSON ¶
func NewLimiterFromJSON(in io.Reader, defaults ConcreteLimitConfig) (Limiter, error)
NewLimiterFromJSON creates a new limiter by parsing a json configuration.
type MetricsReporter ¶
type MetricsReporter interface { // AllowConn is invoked when opening a connection is allowed AllowConn(dir network.Direction, usefd bool) // BlockConn is invoked when opening a connection is blocked BlockConn(dir network.Direction, usefd bool) // AllowStream is invoked when opening a stream is allowed AllowStream(p peer.ID, dir network.Direction) // BlockStream is invoked when opening a stream is blocked BlockStream(p peer.ID, dir network.Direction) // AllowPeer is invoked when attaching ac onnection to a peer is allowed AllowPeer(p peer.ID) // BlockPeer is invoked when attaching ac onnection to a peer is blocked BlockPeer(p peer.ID) // AllowProtocol is invoked when setting the protocol for a stream is allowed AllowProtocol(proto protocol.ID) // BlockProtocol is invoked when setting the protocol for a stream is blocked BlockProtocol(proto protocol.ID) // BlockProtocolPeer is invoked when setting the protocol for a stream is blocked at the per protocol peer scope BlockProtocolPeer(proto protocol.ID, p peer.ID) // AllowService is invoked when setting the protocol for a stream is allowed AllowService(svc string) // BlockService is invoked when setting the protocol for a stream is blocked BlockService(svc string) // BlockServicePeer is invoked when setting the service for a stream is blocked at the per service peer scope BlockServicePeer(svc string, p peer.ID) // AllowMemory is invoked when a memory reservation is allowed AllowMemory(size int) // BlockMemory is invoked when a memory reservation is blocked BlockMemory(size int) }
MetricsReporter is an interface for collecting metrics from resource manager actions
type NetworkPrefixLimit ¶ added in v0.35.0
type Option ¶
type Option func(*resourceManager) error
func WithAllowlistedMultiaddrs ¶
func WithAllowlistedMultiaddrs(mas []multiaddr.Multiaddr) Option
WithAllowlistedMultiaddrs sets the multiaddrs to be in the allowlist
Example ¶
somePeer, err := test.RandPeerID() if err != nil { panic("Failed to generate somePeer") } limits := DefaultLimits.AutoScale() rcmgr, err := NewResourceManager(NewFixedLimiter(limits), WithAllowlistedMultiaddrs([]multiaddr.Multiaddr{ // Any peer connecting from this IP address multiaddr.StringCast("/ip4/1.2.3.4"), // Only the specified peer from this address multiaddr.StringCast("/ip4/2.2.3.4/p2p/" + somePeer.String()), // Only peers from this 1.2.3.0/24 IP address range multiaddr.StringCast("/ip4/1.2.3.0/ipcidr/24"), })) if err != nil { panic("Failed to start resource manager") } // Use rcmgr as before _ = rcmgr
Output:
func WithLimitPerSubnet ¶ added in v0.35.0
func WithLimitPerSubnet(ipv4 []ConnLimitPerSubnet, ipv6 []ConnLimitPerSubnet) Option
WithLimitPerSubnet sets the limits for the number of connections allowed per subnet. This will limit the number of connections per subnet if that subnet is not defined in the NetworkPrefixLimit option. Think of this as a default limit for any given subnet.
func WithMetrics ¶
func WithMetrics(reporter MetricsReporter) Option
WithMetrics is a resource manager option to enable metrics collection
func WithMetricsDisabled ¶ added in v0.29.0
func WithMetricsDisabled() Option
func WithNetworkPrefixLimit ¶ added in v0.35.0
func WithNetworkPrefixLimit(ipv4 []NetworkPrefixLimit, ipv6 []NetworkPrefixLimit) Option
WithNetworkPrefixLimit sets the limits for the number of connections allowed for a specific Network Prefix. Use this when you want to set higher limits for a specific subnet than the default limit per subnet.
func WithTraceReporter ¶
func WithTraceReporter(reporter TraceReporter) Option
type PartialLimitConfig ¶ added in v0.25.0
type PartialLimitConfig struct { System ResourceLimits `json:",omitempty"` Transient ResourceLimits `json:",omitempty"` // Limits that are applied to resources with an allowlisted multiaddr. // These will only be used if the normal System & Transient limits are // reached. AllowlistedSystem ResourceLimits `json:",omitempty"` AllowlistedTransient ResourceLimits `json:",omitempty"` ServiceDefault ResourceLimits `json:",omitempty"` Service map[string]ResourceLimits `json:",omitempty"` ServicePeerDefault ResourceLimits `json:",omitempty"` ServicePeer map[string]ResourceLimits `json:",omitempty"` ProtocolDefault ResourceLimits `json:",omitempty"` Protocol map[protocol.ID]ResourceLimits `json:",omitempty"` ProtocolPeerDefault ResourceLimits `json:",omitempty"` ProtocolPeer map[protocol.ID]ResourceLimits `json:",omitempty"` PeerDefault ResourceLimits `json:",omitempty"` Peer map[peer.ID]ResourceLimits `json:",omitempty"` Conn ResourceLimits `json:",omitempty"` Stream ResourceLimits `json:",omitempty"` }
func (*PartialLimitConfig) Apply ¶ added in v0.25.0
func (cfg *PartialLimitConfig) Apply(c PartialLimitConfig)
func (PartialLimitConfig) Build ¶ added in v0.25.0
func (cfg PartialLimitConfig) Build(defaults ConcreteLimitConfig) ConcreteLimitConfig
func (*PartialLimitConfig) MarshalJSON ¶ added in v0.25.0
func (cfg *PartialLimitConfig) MarshalJSON() ([]byte, error)
type ResourceLimits ¶ added in v0.25.0
type ResourceLimits struct { Streams LimitVal `json:",omitempty"` StreamsInbound LimitVal `json:",omitempty"` StreamsOutbound LimitVal `json:",omitempty"` Conns LimitVal `json:",omitempty"` ConnsInbound LimitVal `json:",omitempty"` ConnsOutbound LimitVal `json:",omitempty"` FD LimitVal `json:",omitempty"` Memory LimitVal64 `json:",omitempty"` }
ResourceLimits is the type for basic resource limits.
func (*ResourceLimits) Apply ¶ added in v0.25.0
func (l *ResourceLimits) Apply(l2 ResourceLimits)
Apply overwrites all default limits with the values of l2
func (*ResourceLimits) Build ¶ added in v0.25.0
func (l *ResourceLimits) Build(defaults Limit) BaseLimit
func (*ResourceLimits) IsDefault ¶ added in v0.25.0
func (l *ResourceLimits) IsDefault() bool
func (*ResourceLimits) ToMaybeNilPtr ¶ added in v0.25.0
func (l *ResourceLimits) ToMaybeNilPtr() *ResourceLimits
type ResourceManagerStat ¶
type ResourceManagerState ¶
type ResourceManagerState interface { ListServices() []string ListProtocols() []protocol.ID ListPeers() []peer.ID Stat() ResourceManagerStat }
ResourceManagerStat is a trait that allows you to access resource manager state.
type ResourceScopeLimiter ¶
ResourceScopeLimiter is a trait interface that allows you to access scope limits.
type ScalingLimitConfig ¶
type ScalingLimitConfig struct { SystemBaseLimit BaseLimit SystemLimitIncrease BaseLimitIncrease TransientBaseLimit BaseLimit TransientLimitIncrease BaseLimitIncrease AllowlistedSystemBaseLimit BaseLimit AllowlistedSystemLimitIncrease BaseLimitIncrease AllowlistedTransientBaseLimit BaseLimit AllowlistedTransientLimitIncrease BaseLimitIncrease ServiceBaseLimit BaseLimit ServiceLimitIncrease BaseLimitIncrease ServiceLimits map[string]baseLimitConfig // use AddServiceLimit to modify ServicePeerBaseLimit BaseLimit ServicePeerLimitIncrease BaseLimitIncrease ServicePeerLimits map[string]baseLimitConfig // use AddServicePeerLimit to modify ProtocolBaseLimit BaseLimit ProtocolLimitIncrease BaseLimitIncrease ProtocolLimits map[protocol.ID]baseLimitConfig // use AddProtocolLimit to modify ProtocolPeerBaseLimit BaseLimit ProtocolPeerLimitIncrease BaseLimitIncrease ProtocolPeerLimits map[protocol.ID]baseLimitConfig // use AddProtocolPeerLimit to modify PeerBaseLimit BaseLimit PeerLimitIncrease BaseLimitIncrease PeerLimits map[peer.ID]baseLimitConfig // use AddPeerLimit to modify ConnBaseLimit BaseLimit ConnLimitIncrease BaseLimitIncrease StreamBaseLimit BaseLimit StreamLimitIncrease BaseLimitIncrease }
ScalingLimitConfig is a struct for configuring default limits. {}BaseLimit is the limits that Apply for a minimal node (128 MB of memory for libp2p) and 256 file descriptors. {}LimitIncrease is the additional limit granted for every additional 1 GB of RAM.
func (*ScalingLimitConfig) AddPeerLimit ¶
func (cfg *ScalingLimitConfig) AddPeerLimit(p peer.ID, base BaseLimit, inc BaseLimitIncrease)
func (*ScalingLimitConfig) AddProtocolLimit ¶
func (cfg *ScalingLimitConfig) AddProtocolLimit(proto protocol.ID, base BaseLimit, inc BaseLimitIncrease)
func (*ScalingLimitConfig) AddProtocolPeerLimit ¶
func (cfg *ScalingLimitConfig) AddProtocolPeerLimit(proto protocol.ID, base BaseLimit, inc BaseLimitIncrease)
func (*ScalingLimitConfig) AddServiceLimit ¶
func (cfg *ScalingLimitConfig) AddServiceLimit(svc string, base BaseLimit, inc BaseLimitIncrease)
func (*ScalingLimitConfig) AddServicePeerLimit ¶
func (cfg *ScalingLimitConfig) AddServicePeerLimit(svc string, base BaseLimit, inc BaseLimitIncrease)
func (*ScalingLimitConfig) AutoScale ¶
func (cfg *ScalingLimitConfig) AutoScale() ConcreteLimitConfig
func (*ScalingLimitConfig) Scale ¶
func (cfg *ScalingLimitConfig) Scale(memory int64, numFD int) ConcreteLimitConfig
Scale scales up a limit configuration. memory is the amount of memory that the stack is allowed to consume, for a dedicated node it's recommended to use 1/8 of the installed system memory. If memory is smaller than 128 MB, the base configuration will be used.
type StatsTraceReporter ¶ added in v0.29.0
type StatsTraceReporter struct{}
StatsTraceReporter reports stats on the resource manager using its traces.
func NewStatsTraceReporter ¶ added in v0.29.0
func NewStatsTraceReporter() (StatsTraceReporter, error)
func (StatsTraceReporter) ConsumeEvent ¶ added in v0.29.0
func (r StatsTraceReporter) ConsumeEvent(evt TraceEvt)
type TraceEvt ¶
type TraceEvt struct { Time string Type TraceEvtTyp Scope *scopeClass `json:",omitempty"` Name string `json:",omitempty"` Limit interface{} `json:",omitempty"` Priority uint8 `json:",omitempty"` Delta int64 `json:",omitempty"` DeltaIn int `json:",omitempty"` DeltaOut int `json:",omitempty"` Memory int64 `json:",omitempty"` StreamsIn int `json:",omitempty"` StreamsOut int `json:",omitempty"` ConnsIn int `json:",omitempty"` ConnsOut int `json:",omitempty"` FD int `json:",omitempty"` }
type TraceEvtTyp ¶
type TraceEvtTyp string
const ( TraceStartEvt TraceEvtTyp = "start" TraceCreateScopeEvt TraceEvtTyp = "create_scope" TraceDestroyScopeEvt TraceEvtTyp = "destroy_scope" TraceReserveMemoryEvt TraceEvtTyp = "reserve_memory" TraceBlockReserveMemoryEvt TraceEvtTyp = "block_reserve_memory" TraceReleaseMemoryEvt TraceEvtTyp = "release_memory" TraceAddStreamEvt TraceEvtTyp = "add_stream" TraceBlockAddStreamEvt TraceEvtTyp = "block_add_stream" TraceRemoveStreamEvt TraceEvtTyp = "remove_stream" TraceAddConnEvt TraceEvtTyp = "add_conn" TraceBlockAddConnEvt TraceEvtTyp = "block_add_conn" TraceRemoveConnEvt TraceEvtTyp = "remove_conn" )
type TraceReporter ¶
type TraceReporter interface { // ConsumeEvent consumes a trace event. This is called synchronously, // implementations should process the event quickly. ConsumeEvent(TraceEvt) }