Skip to content

Commit

Permalink
increase cpu hold duration
Browse files Browse the repository at this point in the history
  • Loading branch information
frostbyte73 committed Dec 15, 2023
1 parent 50db799 commit 9f5f461
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions pkg/stats/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9f5f461

Please sign in to comment.