use cgroup builder

This commit is contained in:
criyle 2019-11-16 15:14:28 -08:00
parent 2903d42e1d
commit efaf626235
4 changed files with 16 additions and 9 deletions

2
go.mod
View File

@ -2,4 +2,4 @@ module github.com/criyle/go-judge
go 1.13 go 1.13
require github.com/criyle/go-sandbox v0.0.0-20191016053250-f2a28034f310 require github.com/criyle/go-sandbox v0.0.0-20191024083121-348ed481d341

8
go.sum
View File

@ -1,5 +1,5 @@
github.com/criyle/go-sandbox v0.0.0-20191016053250-f2a28034f310 h1:mE+H7/ycELStwFvM4+1hPUhILrf5lC4WbdiyT8RlD5M= github.com/criyle/go-sandbox v0.0.0-20191024083121-348ed481d341 h1:gqP5zsvfS10vwZ6lxeX955PJp4AGlCsz99Zpa4/KdH8=
github.com/criyle/go-sandbox v0.0.0-20191016053250-f2a28034f310/go.mod h1:q6ywqlRA0V2VxWo9E+dQkzK2s5mHyq2GXHtF8oZq+mI= github.com/criyle/go-sandbox v0.0.0-20191024083121-348ed481d341/go.mod h1:m017SHr+tj51H1ChJEiMYz5XFbR76ohRCp7WAD3TKgQ=
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo= github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY= golang.org/x/sys v0.0.0-20191023151326-f89234f9a2c2 h1:I7efaDQAsIQmkTF+WSdcydwVWzK07Yuz8IFF8rNkDe0=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191023151326-f89234f9a2c2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -6,7 +6,6 @@ import (
"time" "time"
"github.com/criyle/go-sandbox/daemon" "github.com/criyle/go-sandbox/daemon"
"github.com/criyle/go-sandbox/pkg/cgroup"
"github.com/criyle/go-sandbox/pkg/pipe" "github.com/criyle/go-sandbox/pkg/pipe"
stypes "github.com/criyle/go-sandbox/types" stypes "github.com/criyle/go-sandbox/types"
@ -17,7 +16,6 @@ import (
) )
const maxOutput = 4 << 20 // 4M const maxOutput = 4 << 20 // 4M
const cgroupPrefix = "go-judge"
const minCPUPercent = 40 // 40% const minCPUPercent = 40 // 40%
const checkIntervalMS = 50 const checkIntervalMS = 50
@ -48,7 +46,7 @@ func (r *Runner) run(done <-chan struct{}, task *types.RunTask) *types.RunTaskRe
defer errorPipe.W.Close() defer errorPipe.W.Close()
// init cgroup // init cgroup
cg, err := cgroup.NewCGroup(cgroupPrefix) cg, err := r.CgroupBuilder.Build()
if err != nil { if err != nil {
return errResult("initialize cgroup: " + err.Error()) return errResult("initialize cgroup: " + err.Error())
} }

View File

@ -6,6 +6,7 @@ import (
"github.com/criyle/go-judge/language" "github.com/criyle/go-judge/language"
"github.com/criyle/go-judge/taskqueue" "github.com/criyle/go-judge/taskqueue"
"github.com/criyle/go-sandbox/daemon" "github.com/criyle/go-sandbox/daemon"
"github.com/criyle/go-sandbox/pkg/cgroup"
) )
// DaemonBuilder defines the abstract builder for daemon // DaemonBuilder defines the abstract builder for daemon
@ -13,6 +14,11 @@ type DaemonBuilder interface {
Build() (*daemon.Master, error) Build() (*daemon.Master, error)
} }
// CgroupBuilder builds cgroup for runner
type CgroupBuilder interface {
Build() (cg *cgroup.CGroup, err error)
}
// Runner is the task runner // Runner is the task runner
type Runner struct { type Runner struct {
// Queue is the message queue to receive run tasks // Queue is the message queue to receive run tasks
@ -21,6 +27,9 @@ type Runner struct {
// Builder builds the sandbox runner // Builder builds the sandbox runner
Builder DaemonBuilder Builder DaemonBuilder
// Builder for cgroups
CgroupBuilder CgroupBuilder
Language language.Language Language language.Language
// pool of sandbox to use // pool of sandbox to use