mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: reorg agent config (#853)
* fn: reorg agent config *) Moving constants in agent to agent config, which helps with testing, tuning. *) Added max total cpu & memory for testing & clamping max mem & cpu usage if needed. * fn: adjust PipeIO time * fn: for hot, cannot reliably test EndOfLogs in TestRouteRunnerExecution
This commit is contained in:
@@ -74,14 +74,14 @@ type resourceTracker struct {
|
||||
tokenWaiterCount uint64
|
||||
}
|
||||
|
||||
func NewResourceTracker() ResourceTracker {
|
||||
func NewResourceTracker(cfg *AgentConfig) ResourceTracker {
|
||||
|
||||
obj := &resourceTracker{
|
||||
cond: sync.NewCond(new(sync.Mutex)),
|
||||
}
|
||||
|
||||
obj.initializeMemory()
|
||||
obj.initializeCPU()
|
||||
obj.initializeMemory(cfg)
|
||||
obj.initializeCPU(cfg)
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ func clampUint64(val, min, max uint64) uint64 {
|
||||
return val
|
||||
}
|
||||
|
||||
func (a *resourceTracker) initializeCPU() {
|
||||
func (a *resourceTracker) initializeCPU(cfg *AgentConfig) {
|
||||
|
||||
var maxSyncCPU, maxAsyncCPU, cpuAsyncHWMark uint64
|
||||
var totalCPU, availCPU uint64
|
||||
@@ -320,6 +320,11 @@ func (a *resourceTracker) initializeCPU() {
|
||||
availCPU = minUint64(availCPU, cgroupCPU)
|
||||
}
|
||||
|
||||
// now based on cfg, further clamp on calculated values
|
||||
if cfg != nil && cfg.MaxTotalCPU != 0 {
|
||||
availCPU = minUint64(cfg.MaxTotalCPU, availCPU)
|
||||
}
|
||||
|
||||
// TODO: check cgroup cpuset to clamp this further. We might be restricted into
|
||||
// a subset of CPUs. (eg. /sys/fs/cgroup/cpuset/cpuset.effective_cpus)
|
||||
|
||||
@@ -360,7 +365,7 @@ func (a *resourceTracker) initializeCPU() {
|
||||
a.cpuAsyncTotal = maxAsyncCPU
|
||||
}
|
||||
|
||||
func (a *resourceTracker) initializeMemory() {
|
||||
func (a *resourceTracker) initializeMemory(cfg *AgentConfig) {
|
||||
|
||||
var maxSyncMemory, maxAsyncMemory, ramAsyncHWMark uint64
|
||||
|
||||
@@ -389,6 +394,11 @@ func (a *resourceTracker) initializeMemory() {
|
||||
}
|
||||
availMemory = availMemory - headRoom
|
||||
|
||||
// now based on cfg, further clamp on calculated values
|
||||
if cfg != nil && cfg.MaxTotalMemory != 0 {
|
||||
availMemory = minUint64(cfg.MaxTotalMemory, availMemory)
|
||||
}
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"totalMemory": totalMemory,
|
||||
"availMemory": availMemory,
|
||||
@@ -420,9 +430,9 @@ func (a *resourceTracker) initializeMemory() {
|
||||
}
|
||||
|
||||
if maxSyncMemory+maxAsyncMemory < 256*Mem1MB {
|
||||
logrus.Warn("Severaly Limited memory: ramSync + ramAsync < 256MB")
|
||||
logrus.Warn("Severely Limited memory: ramSync + ramAsync < 256MB")
|
||||
} else if maxAsyncMemory < 256*Mem1MB {
|
||||
logrus.Warn("Severaly Limited memory: ramAsync < 256MB")
|
||||
logrus.Warn("Severely Limited memory: ramAsync < 256MB")
|
||||
}
|
||||
|
||||
a.ramAsyncHWMark = ramAsyncHWMark
|
||||
|
||||
Reference in New Issue
Block a user