32 lines
548 B
Go
Raw Normal View History

2024-03-07 16:16:07 +01:00
package protocolstate
2024-03-07 17:28:24 +01:00
import (
"github.com/projectdiscovery/utils/env"
"github.com/projectdiscovery/utils/memguardian"
)
var (
MaxThreadsOnLowMemory = env.GetEnvOrDefault("MEMGUARDIAN_THREADS", 0)
)
2024-03-07 16:16:07 +01:00
func IsLowOnMemory() bool {
if memguardian.DefaultMemGuardian != nil && memguardian.DefaultMemGuardian.Warning.Load() {
return true
}
return false
}
2024-03-07 17:28:24 +01:00
func GuardThreads(current int) int {
if MaxThreadsOnLowMemory > 0 {
return MaxThreadsOnLowMemory
}
fraction := int(current / 5)
if fraction > 0 {
return fraction
}
return 1
}