Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce minIdle to CanAccept call #160

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pkg/stats/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ func (m *Monitor) CanAccept() bool {
return false
}

available := m.cpuStats.GetCPUIdle() - m.pendingCPUs.Load()

return available > m.maxCost
return m.getAvailable() > m.maxCost
}

func (m *Monitor) canAcceptIngress(info *livekit.IngressInfo) (bool, float64, float64) {
Expand All @@ -205,7 +203,7 @@ func (m *Monitor) canAcceptIngress(info *livekit.IngressInfo) (bool, float64, fl

var cpuHold float64
var accept bool
available := m.cpuStats.GetCPUIdle() - m.pendingCPUs.Load() - minIdle*m.cpuStats.NumCPU()
available := m.getAvailable()

switch info.InputType {
case livekit.IngressInput_RTMP_INPUT:
Expand All @@ -227,6 +225,8 @@ func (m *Monitor) canAcceptIngress(info *livekit.IngressInfo) (bool, float64, fl
logger.Errorw("unsupported request type", errors.New("invalid parameter"))
}

logger.Debugw("checking if request can be handled", "inputType", info.InputType, "accept", accept, "available", available, "cpuHold", cpuHold, "idle", m.cpuStats.GetCPUIdle(), "pending", m.pendingCPUs.Load())

return accept, cpuHold, available
}

Expand Down Expand Up @@ -267,3 +267,7 @@ func (m *Monitor) IngressEnded(info *livekit.IngressInfo) {

}
}

func (m *Monitor) getAvailable() float64 {
return m.cpuStats.GetCPUIdle() - m.pendingCPUs.Load() - minIdle*m.cpuStats.NumCPU()
}
Loading