1 Star 0 Fork 0

CNCF/devstatscode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
threads.go 720 Bytes
一键复制 编辑 原始数据 按行查看 历史
Łukasz Gryglicki 提交于 2023-12-24 04:17 +08:00 . Add support for duynamic env variables 3
package devstatscode
import (
"runtime"
)
// GetThreadsNum returns the number of available CPUs
// If environment variable GHA2DB_ST is set it retuns 1
// It can be used to debug single threaded verion
// It runs on 95% CPU power by default
func GetThreadsNum(ctx *Ctx) int {
// Get CPUs setting from env
ctx.SetCPUs()
// Use environment variable to have singlethreaded version
if ctx.NCPUs > 0 {
n := runtime.NumCPU()
if ctx.NCPUs > n {
ctx.NCPUs = n
}
runtime.GOMAXPROCS(ctx.NCPUs)
return ctx.NCPUs
}
if ctx.ST {
return 1
}
thrN := runtime.NumCPU()
// thrN = (thrN * 19) / 20
runtime.GOMAXPROCS(thrN)
//http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost = 2 * thrN
return thrN
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cncf/devstatscode.git
git@gitee.com:cncf/devstatscode.git
cncf
devstatscode
devstatscode
master

搜索帮助