feat: allow to configure runner concurrency
This commit is contained in:
parent
98578709f8
commit
1dfe296820
@ -39,6 +39,7 @@ Storage:
|
|||||||
|
|
||||||
Runner:
|
Runner:
|
||||||
CGroup: ${CGROUP_PATH}
|
CGroup: ${CGROUP_PATH}
|
||||||
|
Concurrency: ${RUNNER_CONCURRENCY}
|
||||||
|
|
||||||
Metrics:
|
Metrics:
|
||||||
Namespace: ${METRICS_NAMESPACE}
|
Namespace: ${METRICS_NAMESPACE}
|
||||||
|
@ -75,6 +75,7 @@ function extract_storage() {
|
|||||||
|
|
||||||
function extract_runner() {
|
function extract_runner() {
|
||||||
check_env "CGROUP_PATH" "/sys/fs/cgroup/nsjail" true
|
check_env "CGROUP_PATH" "/sys/fs/cgroup/nsjail" true
|
||||||
|
check_env "RUNNER_CONCURRENCY" 0 false
|
||||||
}
|
}
|
||||||
|
|
||||||
function extract_metrics() {
|
function extract_metrics() {
|
||||||
|
@ -50,7 +50,8 @@ type ConfigStorage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ConfigRunner struct {
|
type ConfigRunner struct {
|
||||||
CGroup string `yaml:"CGroup"`
|
CGroup string `yaml:"CGroup"`
|
||||||
|
Concurrency int `yaml:"Concurrency"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigMetrics struct {
|
type ConfigMetrics struct {
|
||||||
|
@ -38,9 +38,13 @@ type Service interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewService(i *do.Injector) (Service, error) {
|
func NewService(i *do.Injector) (Service, error) {
|
||||||
concurrency := utils.If(runtime.NumCPU() > 1, runtime.NumCPU()-1, 1)
|
|
||||||
cfg := do.MustInvoke[config.Service](i).GetConfig()
|
cfg := do.MustInvoke[config.Service](i).GetConfig()
|
||||||
|
|
||||||
|
concurrency := cfg.Runner.Concurrency
|
||||||
|
if concurrency <= 0 {
|
||||||
|
concurrency = utils.If(runtime.NumCPU() > 1, runtime.NumCPU()-1, 1)
|
||||||
|
}
|
||||||
|
|
||||||
srv := &service{
|
srv := &service{
|
||||||
log: do.MustInvoke[log.Service](i).GetLogger("runner"),
|
log: do.MustInvoke[log.Service](i).GetLogger("runner"),
|
||||||
pool: pool.NewTaskPool(concurrency, concurrency),
|
pool: pool.NewTaskPool(concurrency, concurrency),
|
||||||
|
@ -24,7 +24,10 @@ func GetService(dev bool) Service {
|
|||||||
|
|
||||||
cfg := &FakeConfigService{conf: model.Config{
|
cfg := &FakeConfigService{conf: model.Config{
|
||||||
Development: dev,
|
Development: dev,
|
||||||
Runner: model.ConfigRunner{CGroup: "/sys/fs/cgroup/nsjail"},
|
Runner: model.ConfigRunner{
|
||||||
|
CGroup: "/sys/fs/cgroup/nsjail",
|
||||||
|
Concurrency: 0,
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
do.ProvideValue[config.Service](injector, cfg)
|
do.ProvideValue[config.Service](injector, cfg)
|
||||||
|
Loading…
Reference in New Issue
Block a user