From 9f5f46168192ac4845cf327b909e820dfa77f33d Mon Sep 17 00:00:00 2001 From: David Colburn Date: Thu, 14 Dec 2023 21:38:12 -0800 Subject: [PATCH] increase cpu hold duration --- pkg/stats/monitor.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pkg/stats/monitor.go b/pkg/stats/monitor.go index e326de86..08958a7d 100644 --- a/pkg/stats/monitor.go +++ b/pkg/stats/monitor.go @@ -47,7 +47,7 @@ type Monitor struct { prevEgressUsage map[string]float64 } -const cpuHoldDuration = time.Second * 5 +const cpuHoldDuration = time.Second * 10 func NewMonitor(conf *config.ServiceConfig) *Monitor { return &Monitor{ @@ -177,24 +177,23 @@ func (m *Monitor) CanAcceptRequest(req *rpc.StartEgressRequest) bool { func (m *Monitor) canAcceptRequest(req *rpc.StartEgressRequest) bool { accept := false - total := m.cpuStats.NumCPU() - available := m.cpuStats.GetCPUIdle() - m.pendingCPUs.Load() - - logger.Debugw("cpu check", - "total", total, - "available", available, - "active_requests", m.requests, - ) + var available float64 if m.requests.Load() == 0 { // if no requests, use total - available = total + available = total - m.pendingCPUs.Load() } else { // if already running requests, cap usage at MaxCpuUtilization - available -= (1 - m.cpuCostConfig.MaxCpuUtilization) * total + available = m.cpuStats.GetCPUIdle() - m.pendingCPUs.Load() - (1-m.cpuCostConfig.MaxCpuUtilization)*total } + logger.Debugw("cpu check", + "total", total, + "available", available, + "requests", m.requests, + ) + switch req.Request.(type) { case *rpc.StartEgressRequest_RoomComposite: accept = available >= m.cpuCostConfig.RoomCompositeCpuCost