mirror of
https://github.com/libp2p/go-libp2p-resource-manager.git
synced 2025-01-27 12:50:07 +08:00
adjust default limits
This commit is contained in:
parent
927d2d70b5
commit
572b3eb374
11
limit.go
11
limit.go
@ -198,3 +198,14 @@ func StreamBaseLimit() BaseLimit {
|
||||
StreamsOutbound: 1,
|
||||
}
|
||||
}
|
||||
|
||||
func memoryLimit(memoryCap int64, minMemory, maxMemory int64) int64 {
|
||||
switch {
|
||||
case memoryCap < minMemory:
|
||||
return minMemory
|
||||
case memoryCap > maxMemory:
|
||||
return maxMemory
|
||||
default:
|
||||
return memoryCap
|
||||
}
|
||||
}
|
||||
|
@ -33,13 +33,7 @@ func (l *DynamicLimit) GetMemoryLimit() int64 {
|
||||
freemem += (memstat.HeapInuse - memstat.HeapAlloc) + (memstat.HeapIdle - memstat.HeapReleased)
|
||||
|
||||
limit := int64(float64(freemem) * l.MemoryFraction)
|
||||
if limit < l.MinMemory {
|
||||
limit = l.MinMemory
|
||||
} else if limit > l.MaxMemory {
|
||||
limit = l.MaxMemory
|
||||
}
|
||||
|
||||
return limit
|
||||
return memoryLimit(limit, l.MinMemory, l.MaxMemory)
|
||||
}
|
||||
|
||||
func (l *DynamicLimit) WithMemoryLimit(memFraction float64, minMemory, maxMemory int64) Limit {
|
||||
@ -94,31 +88,31 @@ func NewDynamicLimiter(memFraction float64, minMemory, maxMemory int64) *BasicLi
|
||||
BaseLimit: DefaultSystemBaseLimit(),
|
||||
}
|
||||
transient := &DynamicLimit{
|
||||
MinMemory: minMemory / 4,
|
||||
MaxMemory: maxMemory / 4,
|
||||
MemoryFraction: memFraction / 4,
|
||||
MinMemory: 64 << 20,
|
||||
MaxMemory: 128 << 20,
|
||||
MemoryFraction: memFraction / 16,
|
||||
BaseLimit: DefaultTransientBaseLimit(),
|
||||
}
|
||||
svc := &DynamicLimit{
|
||||
MinMemory: minMemory / 4,
|
||||
MaxMemory: maxMemory / 4,
|
||||
MinMemory: 64 << 20,
|
||||
MaxMemory: 512 << 20,
|
||||
MemoryFraction: memFraction / 4,
|
||||
BaseLimit: DefaultServiceBaseLimit(),
|
||||
}
|
||||
proto := &DynamicLimit{
|
||||
MinMemory: minMemory / 4,
|
||||
MaxMemory: maxMemory / 4,
|
||||
MemoryFraction: memFraction / 4,
|
||||
MinMemory: 64 << 20,
|
||||
MaxMemory: 128 << 20,
|
||||
MemoryFraction: memFraction / 16,
|
||||
BaseLimit: DefaultProtocolBaseLimit(),
|
||||
}
|
||||
peer := &DynamicLimit{
|
||||
MinMemory: minMemory / 4,
|
||||
MaxMemory: maxMemory / 4,
|
||||
MemoryFraction: memFraction / 4,
|
||||
MinMemory: 64 << 20,
|
||||
MaxMemory: 128 << 20,
|
||||
MemoryFraction: memFraction / 16,
|
||||
BaseLimit: DefaultPeerBaseLimit(),
|
||||
}
|
||||
conn := &StaticLimit{
|
||||
Memory: 16 << 20,
|
||||
Memory: 1 << 20,
|
||||
BaseLimit: ConnBaseLimit(),
|
||||
}
|
||||
stream := &StaticLimit{
|
||||
|
@ -63,13 +63,7 @@ func (l *StaticLimit) WithFDLimit(numFD int) Limit {
|
||||
// a fraction of total system memory. The assigned memory will not be less than minMemory or more
|
||||
// than maxMemory.
|
||||
func NewStaticLimiter(memFraction float64, minMemory, maxMemory int64) *BasicLimiter {
|
||||
memoryCap := int64(float64(memory.TotalMemory()) * memFraction)
|
||||
switch {
|
||||
case memoryCap < minMemory:
|
||||
memoryCap = minMemory
|
||||
case memoryCap > maxMemory:
|
||||
memoryCap = maxMemory
|
||||
}
|
||||
memoryCap := memoryLimit(int64(float64(memory.TotalMemory())*memFraction), minMemory, maxMemory)
|
||||
return newDefaultStaticLimiter(memoryCap)
|
||||
}
|
||||
|
||||
@ -84,23 +78,23 @@ func newDefaultStaticLimiter(memoryCap int64) *BasicLimiter {
|
||||
BaseLimit: DefaultSystemBaseLimit(),
|
||||
}
|
||||
transient := &StaticLimit{
|
||||
Memory: memoryCap / 4,
|
||||
Memory: memoryLimit(memoryCap/16, 64<<20, 128<<20),
|
||||
BaseLimit: DefaultTransientBaseLimit(),
|
||||
}
|
||||
svc := &StaticLimit{
|
||||
Memory: memoryCap / 4,
|
||||
Memory: memoryLimit(memoryCap/4, 64<<20, 512<<20),
|
||||
BaseLimit: DefaultServiceBaseLimit(),
|
||||
}
|
||||
proto := &StaticLimit{
|
||||
Memory: memoryCap / 4,
|
||||
Memory: memoryLimit(memoryCap/16, 64<<20, 128<<20),
|
||||
BaseLimit: DefaultProtocolBaseLimit(),
|
||||
}
|
||||
peer := &StaticLimit{
|
||||
Memory: memoryCap / 4,
|
||||
Memory: memoryLimit(memoryCap/16, 64<<20, 128<<20),
|
||||
BaseLimit: DefaultPeerBaseLimit(),
|
||||
}
|
||||
conn := &StaticLimit{
|
||||
Memory: 16 << 20,
|
||||
Memory: 1 << 20,
|
||||
BaseLimit: ConnBaseLimit(),
|
||||
}
|
||||
stream := &StaticLimit{
|
||||
|
Loading…
Reference in New Issue
Block a user