Skip to content

Instantly share code, notes, and snippets.

@CAFxX
Created October 16, 2019 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CAFxX/5ad21199fe8c72d7be1feec786fe81e7 to your computer and use it in GitHub Desktop.
Save CAFxX/5ad21199fe8c72d7be1feec786fe81e7 to your computer and use it in GitHub Desktop.
optcpu.go
func getOptimalCpuConfig(request, limit float64) (request, limit float64, cores int) {
if request == 0 && limit == 0 {
return
} else if request < 0 {
panic("negative request")
} else if limit < 0 {
panic("negative limit")
} else if limit != 0 && request > limit {
panic("request > limit")
}
if limit == 0 {
limit = request*2
}
cores = math.Ceil(limit)
limit = cores + limit/3
return
}
func getOptimalCpuConfigSimple(request float64) (request, limit float64, cores int) {
return getOptimalCpuConfig(request, 0)
}
func getOptimalCpuConfigQoS(request float64) (request, limit float64, cores int) {
if request == 0 {
return
} else if request < 0 {
panic("negative request")
}
cores = math.Floor(request * 3/4)
if cores == 0 {
cores = 1
request = 1 + request/3
}
limit = request
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment