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

Allow configuring the max cpu utilization to use when deciding whether to accept a request #561

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions pkg/config/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
participantCpuCost = 1
trackCompositeCpuCost = 1
trackCpuCost = 0.5
maxCpuUtilization = 0.8

defaultTemplatePort = 7980
defaultTemplateBaseTemplate = "http://localhost:%d/"
Expand All @@ -50,6 +51,7 @@ type ServiceConfig struct {
}

type CPUCostConfig struct {
MaxCpuUtilization float64 `yaml:"max_cpu_utilization"` // Maximum allowed CPU utilization when deciding to accept a request. Default to 80%.
RoomCompositeCpuCost float64 `yaml:"room_composite_cpu_cost"`
WebCpuCost float64 `yaml:"web_cpu_cost"`
ParticipantCpuCost float64 `yaml:"participant_cpu_cost"`
Expand Down Expand Up @@ -94,6 +96,9 @@ func NewServiceConfig(confString string) (*ServiceConfig, error) {
if conf.TrackCpuCost <= 0 {
conf.TrackCpuCost = trackCpuCost
}
if conf.MaxCpuUtilization <= 0 {
conf.MaxCpuUtilization = maxCpuUtilization
}

if conf.TemplateBase == "" {
conf.TemplateBase = fmt.Sprintf(defaultTemplateBaseTemplate, conf.TemplatePort)
Expand Down
4 changes: 2 additions & 2 deletions pkg/stats/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ func (m *Monitor) canAcceptRequest(req *rpc.StartEgressRequest) bool {
// if no requests, use total
available = total
} else {
// if already running requests, cap usage at 90%
available -= 0.1 * total
// if already running requests, cap usage at MaxCpuUtilization
available -= (1 - m.cpuCostConfig.MaxCpuUtilization) * total
}

switch req.Request.(type) {
Expand Down