Skip to content

Commit

Permalink
Allow configuring the max cpu usage to use when deciding whether to a…
Browse files Browse the repository at this point in the history
…cceopt a request (#561)
  • Loading branch information
biglittlebigben authored Dec 13, 2023
1 parent 5651166 commit d748818
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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

0 comments on commit d748818

Please sign in to comment.