Created
October 16, 2019 15:22
-
-
Save CAFxX/5ad21199fe8c72d7be1feec786fe81e7 to your computer and use it in GitHub Desktop.
optcpu.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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