mirror of
https://github.com/libp2p/go-libp2p-resource-manager.git
synced 2025-03-31 22:50:19 +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,
|
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)
|
freemem += (memstat.HeapInuse - memstat.HeapAlloc) + (memstat.HeapIdle - memstat.HeapReleased)
|
||||||
|
|
||||||
limit := int64(float64(freemem) * l.MemoryFraction)
|
limit := int64(float64(freemem) * l.MemoryFraction)
|
||||||
if limit < l.MinMemory {
|
return memoryLimit(limit, l.MinMemory, l.MaxMemory)
|
||||||
limit = l.MinMemory
|
|
||||||
} else if limit > l.MaxMemory {
|
|
||||||
limit = l.MaxMemory
|
|
||||||
}
|
|
||||||
|
|
||||||
return limit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DynamicLimit) WithMemoryLimit(memFraction float64, minMemory, maxMemory int64) Limit {
|
func (l *DynamicLimit) WithMemoryLimit(memFraction float64, minMemory, maxMemory int64) Limit {
|
||||||
@ -94,31 +88,31 @@ func NewDynamicLimiter(memFraction float64, minMemory, maxMemory int64) *BasicLi
|
|||||||
BaseLimit: DefaultSystemBaseLimit(),
|
BaseLimit: DefaultSystemBaseLimit(),
|
||||||
}
|
}
|
||||||
transient := &DynamicLimit{
|
transient := &DynamicLimit{
|
||||||
MinMemory: minMemory / 4,
|
MinMemory: 64 << 20,
|
||||||
MaxMemory: maxMemory / 4,
|
MaxMemory: 128 << 20,
|
||||||
MemoryFraction: memFraction / 4,
|
MemoryFraction: memFraction / 16,
|
||||||
BaseLimit: DefaultTransientBaseLimit(),
|
BaseLimit: DefaultTransientBaseLimit(),
|
||||||
}
|
}
|
||||||
svc := &DynamicLimit{
|
svc := &DynamicLimit{
|
||||||
MinMemory: minMemory / 4,
|
MinMemory: 64 << 20,
|
||||||
MaxMemory: maxMemory / 4,
|
MaxMemory: 512 << 20,
|
||||||
MemoryFraction: memFraction / 4,
|
MemoryFraction: memFraction / 4,
|
||||||
BaseLimit: DefaultServiceBaseLimit(),
|
BaseLimit: DefaultServiceBaseLimit(),
|
||||||
}
|
}
|
||||||
proto := &DynamicLimit{
|
proto := &DynamicLimit{
|
||||||
MinMemory: minMemory / 4,
|
MinMemory: 64 << 20,
|
||||||
MaxMemory: maxMemory / 4,
|
MaxMemory: 128 << 20,
|
||||||
MemoryFraction: memFraction / 4,
|
MemoryFraction: memFraction / 16,
|
||||||
BaseLimit: DefaultProtocolBaseLimit(),
|
BaseLimit: DefaultProtocolBaseLimit(),
|
||||||
}
|
}
|
||||||
peer := &DynamicLimit{
|
peer := &DynamicLimit{
|
||||||
MinMemory: minMemory / 4,
|
MinMemory: 64 << 20,
|
||||||
MaxMemory: maxMemory / 4,
|
MaxMemory: 128 << 20,
|
||||||
MemoryFraction: memFraction / 4,
|
MemoryFraction: memFraction / 16,
|
||||||
BaseLimit: DefaultPeerBaseLimit(),
|
BaseLimit: DefaultPeerBaseLimit(),
|
||||||
}
|
}
|
||||||
conn := &StaticLimit{
|
conn := &StaticLimit{
|
||||||
Memory: 16 << 20,
|
Memory: 1 << 20,
|
||||||
BaseLimit: ConnBaseLimit(),
|
BaseLimit: ConnBaseLimit(),
|
||||||
}
|
}
|
||||||
stream := &StaticLimit{
|
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
|
// a fraction of total system memory. The assigned memory will not be less than minMemory or more
|
||||||
// than maxMemory.
|
// than maxMemory.
|
||||||
func NewStaticLimiter(memFraction float64, minMemory, maxMemory int64) *BasicLimiter {
|
func NewStaticLimiter(memFraction float64, minMemory, maxMemory int64) *BasicLimiter {
|
||||||
memoryCap := int64(float64(memory.TotalMemory()) * memFraction)
|
memoryCap := memoryLimit(int64(float64(memory.TotalMemory())*memFraction), minMemory, maxMemory)
|
||||||
switch {
|
|
||||||
case memoryCap < minMemory:
|
|
||||||
memoryCap = minMemory
|
|
||||||
case memoryCap > maxMemory:
|
|
||||||
memoryCap = maxMemory
|
|
||||||
}
|
|
||||||
return newDefaultStaticLimiter(memoryCap)
|
return newDefaultStaticLimiter(memoryCap)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,23 +78,23 @@ func newDefaultStaticLimiter(memoryCap int64) *BasicLimiter {
|
|||||||
BaseLimit: DefaultSystemBaseLimit(),
|
BaseLimit: DefaultSystemBaseLimit(),
|
||||||
}
|
}
|
||||||
transient := &StaticLimit{
|
transient := &StaticLimit{
|
||||||
Memory: memoryCap / 4,
|
Memory: memoryLimit(memoryCap/16, 64<<20, 128<<20),
|
||||||
BaseLimit: DefaultTransientBaseLimit(),
|
BaseLimit: DefaultTransientBaseLimit(),
|
||||||
}
|
}
|
||||||
svc := &StaticLimit{
|
svc := &StaticLimit{
|
||||||
Memory: memoryCap / 4,
|
Memory: memoryLimit(memoryCap/4, 64<<20, 512<<20),
|
||||||
BaseLimit: DefaultServiceBaseLimit(),
|
BaseLimit: DefaultServiceBaseLimit(),
|
||||||
}
|
}
|
||||||
proto := &StaticLimit{
|
proto := &StaticLimit{
|
||||||
Memory: memoryCap / 4,
|
Memory: memoryLimit(memoryCap/16, 64<<20, 128<<20),
|
||||||
BaseLimit: DefaultProtocolBaseLimit(),
|
BaseLimit: DefaultProtocolBaseLimit(),
|
||||||
}
|
}
|
||||||
peer := &StaticLimit{
|
peer := &StaticLimit{
|
||||||
Memory: memoryCap / 4,
|
Memory: memoryLimit(memoryCap/16, 64<<20, 128<<20),
|
||||||
BaseLimit: DefaultPeerBaseLimit(),
|
BaseLimit: DefaultPeerBaseLimit(),
|
||||||
}
|
}
|
||||||
conn := &StaticLimit{
|
conn := &StaticLimit{
|
||||||
Memory: 16 << 20,
|
Memory: 1 << 20,
|
||||||
BaseLimit: ConnBaseLimit(),
|
BaseLimit: ConnBaseLimit(),
|
||||||
}
|
}
|
||||||
stream := &StaticLimit{
|
stream := &StaticLimit{
|
||||||
|
Loading…
Reference in New Issue
Block a user