From 4bf6f869f5e7e28db1d5b4905cabcacf6b4c1533 Mon Sep 17 00:00:00 2001 From: criyle Date: Sat, 12 Dec 2020 23:44:01 -0800 Subject: [PATCH] Add ability to limit cpu usage rate by CFS cgroup --- README.md | 42 ++++- cmd/executorserver/config/config.go | 2 + cmd/executorserver/grpc.go | 1 + cmd/executorserver/main.go | 2 + cmd/executorserver/model/model.go | 12 +- cmd/executorserver/version.go | 2 +- env/config.go | 4 + env/env_linux.go | 7 +- pb/judge.pb.go | 275 +++++++++++++++------------- pb/judge.proto | 1 + pkg/envexec/cmd.go | 1 + pkg/envexec/interface.go | 1 + pkg/envexec/run_single.go | 1 + pkg/pool/cgroup_fake_pool_linux.go | 11 +- pkg/pool/cgroup_wrapper_linux.go | 31 +++- pkg/pool/cgrouppool_linux.go | 10 +- pkg/pool/envbuilder_linux.go | 5 +- pkg/pool/environment_linux.go | 10 +- worker/model.go | 1 + worker/worker.go | 1 + 20 files changed, 257 insertions(+), 163 deletions(-) diff --git a/README.md b/README.md index 985845c..ed17e0b 100644 --- a/README.md +++ b/README.md @@ -61,11 +61,13 @@ The `executorserver` need root privilege to create `cgroup`. Either creates sub- - The default CGroup prefix is `executor_server`, Can be specified with `-cgroup-prefix` flag. - `-auth-token` to add token-based authentication to REST / gRPC - `-src-prefix` to restrict `src` copyIn path (need to be absolute path) -- `-time-limit-checker-interval` specifies time limit checker interval (default 100ms) +- `-time-limit-checker-interval` specifies time limit checker interval (default 100ms) (valid value: \[1ms, 1s\]) - `-output-limit` specifies size limit of POSIX rlimit of output - `-cpuset` specifies `cpuset.cpus` cgroup for each container - `-container-cred-start` specifies container `setuid` / `setgid` credential start point (default: 10000) - for example, by default container 0 will run with 10001 uid & gid and container 1 will run with 10002 uid & gid... +- `-enable-cpu-rate` enabled `cpu` cgroup to control cpu rate using cfs_quota & cfs_period control +- `-cpu-cfs-period` specifies cfs_period if cpu rate is enabled (default 100ms) (valid value: \[1ms, 1s\]) #### Environment Variables @@ -593,3 +595,41 @@ Compile On Windows (cygwin): } ] ``` + +Infinite loop with cpu rate control: + +```json +{ + "cmd": [{ + "args": ["/usr/bin/python3", "1.py"], + "env": ["PATH=/usr/bin:/bin"], + "files": [{"content": ""}, {"name": "stdout","max": 10240}, {"name": "stderr","max": 10240}], + "cpuLimit": 3000000000, + "realCpuLimit": 4000000000, + "memoryLimit": 104857600, + "procLimit": 50, + "cpuRate": 0.1, + "copyIn": { + "1.py": { + "content": "while True:\n pass" + } + } + }] +} +``` + +```json +[ + { + "status": "Time Limit Exceeded", + "exitStatus": 9, + "time": 414803599, + "memory": 3657728, + "runTime": 4046054900, + "files": { + "stderr": "", + "stdout": "" + } + } +] +``` diff --git a/cmd/executorserver/config/config.go b/cmd/executorserver/config/config.go index 9b44e99..fd177f0 100644 --- a/cmd/executorserver/config/config.go +++ b/cmd/executorserver/config/config.go @@ -29,6 +29,8 @@ type Config struct { ExtraMemoryLimit *envexec.Size `flagUsage:"specifies extra memory buffer for check memory limit" default:"16k"` OutputLimit *envexec.Size `flagUsage:"specifies POSIX rlimit for output for each command" default:"256m"` Cpuset string `flagUsage:"control the usage of cpuset for all containerd process"` + EnableCPURate bool `flagUsage:"enable cpu cgroup rate control"` + CPUCfsPeriod time.Duration `flagUsage:"set cpu.cfs_period" default:"100ms"` // server config HTTPAddr string `flagUsage:"specifies the http binding address" default:":5050"` diff --git a/cmd/executorserver/grpc.go b/cmd/executorserver/grpc.go index c3b52d6..44a8278 100644 --- a/cmd/executorserver/grpc.go +++ b/cmd/executorserver/grpc.go @@ -177,6 +177,7 @@ func convertPBCmd(c *pb.Request_CmdType, srcPrefix string) (cm worker.Cmd, strea MemoryLimit: c.GetMemoryLimit(), StackLimit: c.GetStackLimit(), ProcLimit: c.GetProcLimit(), + CPURateLimit: c.GetCPURateLimit(), CopyOut: c.GetCopyOut(), CopyOutCached: c.GetCopyOutCached(), CopyOutMax: c.GetCopyOutMax(), diff --git a/cmd/executorserver/main.go b/cmd/executorserver/main.go index 9823105..937ecbe 100644 --- a/cmd/executorserver/main.go +++ b/cmd/executorserver/main.go @@ -77,6 +77,8 @@ func main() { CgroupPrefix: conf.CgroupPrefix, Cpuset: conf.Cpuset, ContainerCredStart: conf.ContainerCredStart, + EnableCPURate: conf.EnableCPURate, + CPUCfsPeriod: conf.CPUCfsPeriod, Logger: logger.Sugar(), }) if err != nil { diff --git a/cmd/executorserver/model/model.go b/cmd/executorserver/model/model.go index 4fa07e0..dcfc6e1 100644 --- a/cmd/executorserver/model/model.go +++ b/cmd/executorserver/model/model.go @@ -26,11 +26,12 @@ type Cmd struct { Files []*CmdFile `json:"files,omitempty"` TTY bool `json:"tty,omitempty"` - CPULimit uint64 `json:"cpuLimit"` - RealCPULimit uint64 `json:"realCpuLimit"` - MemoryLimit uint64 `json:"memoryLimit"` - StackLimit uint64 `json:"stackLimit"` - ProcLimit uint64 `json:"procLimit"` + CPULimit uint64 `json:"cpuLimit"` + RealCPULimit uint64 `json:"realCpuLimit"` + MemoryLimit uint64 `json:"memoryLimit"` + StackLimit uint64 `json:"stackLimit"` + ProcLimit uint64 `json:"procLimit"` + CPURateLimit float64 `json:"cpuRateLimit"` CopyIn map[string]CmdFile `json:"copyIn"` @@ -164,6 +165,7 @@ func convertCmd(c Cmd, srcPrefix string) (worker.Cmd, error) { MemoryLimit: c.MemoryLimit, StackLimit: c.StackLimit, ProcLimit: c.ProcLimit, + CPURateLimit: c.CPURateLimit, CopyOut: c.CopyOut, CopyOutCached: c.CopyOutCached, CopyOutMax: c.CopyOutMax, diff --git a/cmd/executorserver/version.go b/cmd/executorserver/version.go index c4f853c..953a0b6 100644 --- a/cmd/executorserver/version.go +++ b/cmd/executorserver/version.go @@ -2,4 +2,4 @@ package main -const Version = `v0.6.10` \ No newline at end of file +const Version = `v0.8.4-2-gb1e9e0d` \ No newline at end of file diff --git a/env/config.go b/env/config.go index 237e8a9..74d7951 100644 --- a/env/config.go +++ b/env/config.go @@ -1,5 +1,7 @@ package env +import "time" + // Logger defines logger to print logs type Logger interface { Debug(args ...interface{}) @@ -17,5 +19,7 @@ type Config struct { CgroupPrefix string Cpuset string ContainerCredStart int + EnableCPURate bool + CPUCfsPeriod time.Duration Logger } diff --git a/env/env_linux.go b/env/env_linux.go index 7a6703f..90600e6 100644 --- a/env/env_linux.go +++ b/env/env_linux.go @@ -91,6 +91,9 @@ func NewBuilder(c Config) (pool.EnvBuilder, error) { if c.Cpuset != "" { cgb = cgb.WithCPUSet() } + if c.EnableCPURate { + cgb = cgb.WithCPU() + } cgb, err = cgb.FilterByEnv() if err != nil { return nil, err @@ -106,9 +109,9 @@ func NewBuilder(c Config) (pool.EnvBuilder, error) { var cgroupPool pool.CgroupPool if cgb != nil { - cgroupPool = pool.NewFakeCgroupPool(cgb) + cgroupPool = pool.NewFakeCgroupPool(cgb, c.CPUCfsPeriod) } - return pool.NewEnvBuilder(b, cgroupPool, workDir, c.Cpuset), nil + return pool.NewEnvBuilder(b, cgroupPool, workDir, c.Cpuset, c.EnableCPURate), nil } type credGen struct { diff --git a/pb/judge.pb.go b/pb/judge.pb.go index f241cc4..0fe518c 100644 --- a/pb/judge.pb.go +++ b/pb/judge.pb.go @@ -1040,6 +1040,7 @@ type Request_CmdType struct { MemoryLimit uint64 `protobuf:"varint,6,opt,name=memoryLimit,proto3" json:"memoryLimit,omitempty"` StackLimit uint64 `protobuf:"varint,12,opt,name=stackLimit,proto3" json:"stackLimit,omitempty"` ProcLimit uint64 `protobuf:"varint,7,opt,name=procLimit,proto3" json:"procLimit,omitempty"` + CPURateLimit float64 `protobuf:"fixed64,15,opt,name=CPURateLimit,proto3" json:"CPURateLimit,omitempty"` CopyIn map[string]*Request_File `protobuf:"bytes,8,rep,name=copyIn,proto3" json:"copyIn,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` CopyOut []string `protobuf:"bytes,9,rep,name=copyOut,proto3" json:"copyOut,omitempty"` CopyOutCached []string `protobuf:"bytes,10,rep,name=copyOutCached,proto3" json:"copyOutCached,omitempty"` @@ -1142,6 +1143,13 @@ func (x *Request_CmdType) GetProcLimit() uint64 { return 0 } +func (x *Request_CmdType) GetCPURateLimit() float64 { + if x != nil { + return x.CPURateLimit + } + return 0 +} + func (x *Request_CmdType) GetCopyIn() map[string]*Request_File { if x != nil { return x.CopyIn @@ -1592,7 +1600,7 @@ var file_judge_proto_rawDesc = []byte{ 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x28, 0x0a, 0x0c, 0x46, 0x69, 0x6c, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x69, 0x6c, 0x65, 0x49, 0x44, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x66, 0x69, 0x6c, 0x65, - 0x49, 0x44, 0x73, 0x22, 0xe7, 0x0a, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x49, 0x44, 0x73, 0x22, 0x8b, 0x0b, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x12, 0x25, 0x0a, 0x03, 0x63, 0x6d, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x62, 0x2e, @@ -1635,7 +1643,7 @@ var file_judge_proto_rawDesc = []byte{ 0x72, 0x65, 0x61, 0x6d, 0x4f, 0x75, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x48, 0x00, 0x52, 0x09, 0x73, 0x74, 0x72, 0x65, 0x61, - 0x6d, 0x4f, 0x75, 0x74, 0x42, 0x06, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x1a, 0x8f, 0x04, 0x0a, + 0x6d, 0x4f, 0x75, 0x74, 0x42, 0x06, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x1a, 0xb3, 0x04, 0x0a, 0x07, 0x43, 0x6d, 0x64, 0x54, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72, 0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x61, 0x72, 0x67, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x76, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x65, 0x6e, 0x76, 0x12, 0x26, @@ -1652,138 +1660,141 @@ var file_judge_proto_rawDesc = []byte{ 0x61, 0x63, 0x6b, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x72, 0x6f, 0x63, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x70, - 0x72, 0x6f, 0x63, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x37, 0x0a, 0x06, 0x63, 0x6f, 0x70, 0x79, - 0x49, 0x6e, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x6d, 0x64, 0x54, 0x79, 0x70, 0x65, 0x2e, 0x43, 0x6f, - 0x70, 0x79, 0x49, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x63, 0x6f, 0x70, 0x79, 0x49, - 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, 0x18, 0x09, 0x20, 0x03, - 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, 0x12, 0x24, 0x0a, 0x0d, 0x63, - 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, 0x43, 0x61, 0x63, 0x68, 0x65, 0x64, 0x18, 0x0a, 0x20, 0x03, - 0x28, 0x09, 0x52, 0x0d, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, 0x43, 0x61, 0x63, 0x68, 0x65, - 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, 0x44, 0x69, 0x72, 0x18, - 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, 0x44, 0x69, - 0x72, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, 0x4d, 0x61, 0x78, 0x18, - 0x0e, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, 0x4d, 0x61, - 0x78, 0x1a, 0x4b, 0x0a, 0x0b, 0x43, 0x6f, 0x70, 0x79, 0x49, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x72, 0x6f, 0x63, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x43, 0x50, 0x55, 0x52, + 0x61, 0x74, 0x65, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0c, + 0x43, 0x50, 0x55, 0x52, 0x61, 0x74, 0x65, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x37, 0x0a, 0x06, + 0x63, 0x6f, 0x70, 0x79, 0x49, 0x6e, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x70, + 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x6d, 0x64, 0x54, 0x79, 0x70, + 0x65, 0x2e, 0x43, 0x6f, 0x70, 0x79, 0x49, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x63, + 0x6f, 0x70, 0x79, 0x49, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, + 0x18, 0x09, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, 0x12, + 0x24, 0x0a, 0x0d, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, 0x43, 0x61, 0x63, 0x68, 0x65, 0x64, + 0x18, 0x0a, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0d, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, 0x43, + 0x61, 0x63, 0x68, 0x65, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, + 0x44, 0x69, 0x72, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x70, 0x79, 0x4f, + 0x75, 0x74, 0x44, 0x69, 0x72, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x75, 0x74, + 0x4d, 0x61, 0x78, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a, 0x63, 0x6f, 0x70, 0x79, 0x4f, + 0x75, 0x74, 0x4d, 0x61, 0x78, 0x1a, 0x4b, 0x0a, 0x0b, 0x43, 0x6f, 0x70, 0x79, 0x49, 0x6e, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x26, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, + 0x38, 0x01, 0x1a, 0x9c, 0x01, 0x0a, 0x07, 0x50, 0x69, 0x70, 0x65, 0x4d, 0x61, 0x70, 0x12, 0x2d, + 0x0a, 0x02, 0x69, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x70, 0x62, 0x2e, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x50, 0x69, 0x70, 0x65, 0x4d, 0x61, 0x70, 0x2e, + 0x50, 0x69, 0x70, 0x65, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x02, 0x69, 0x6e, 0x12, 0x2f, 0x0a, + 0x03, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x70, 0x62, 0x2e, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x50, 0x69, 0x70, 0x65, 0x4d, 0x61, 0x70, 0x2e, + 0x50, 0x69, 0x70, 0x65, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x03, 0x6f, 0x75, 0x74, 0x1a, 0x31, + 0x0a, 0x09, 0x50, 0x69, 0x70, 0x65, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x14, 0x0a, 0x05, 0x69, + 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, + 0x78, 0x12, 0x0e, 0x0a, 0x02, 0x66, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x66, + 0x64, 0x22, 0xb9, 0x06, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, + 0x0a, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x12, 0x2d, 0x0a, 0x07, + 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, + 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x75, + 0x6c, 0x74, 0x52, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x65, + 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x1a, 0xc9, 0x05, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x36, 0x0a, 0x06, + 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1e, 0x2e, 0x70, + 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, + 0x74, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x54, 0x79, 0x70, 0x65, 0x52, 0x06, 0x73, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x65, 0x78, 0x69, 0x74, 0x53, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x65, 0x78, 0x69, 0x74, 0x53, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x69, + 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x18, + 0x0a, 0x07, 0x72, 0x75, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x04, 0x52, + 0x07, 0x72, 0x75, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x6d, 0x6f, + 0x72, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, + 0x12, 0x34, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x1e, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, + 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x12, 0x3a, 0x0a, 0x07, 0x66, 0x69, 0x6c, 0x65, 0x49, 0x44, + 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x46, 0x69, 0x6c, + 0x65, 0x49, 0x44, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x66, 0x69, 0x6c, 0x65, 0x49, + 0x44, 0x73, 0x1a, 0x38, 0x0a, 0x0a, 0x46, 0x69, 0x6c, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, - 0x65, 0x79, 0x12, 0x26, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x46, - 0x69, 0x6c, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x9c, - 0x01, 0x0a, 0x07, 0x50, 0x69, 0x70, 0x65, 0x4d, 0x61, 0x70, 0x12, 0x2d, 0x0a, 0x02, 0x69, 0x6e, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x2e, 0x50, 0x69, 0x70, 0x65, 0x4d, 0x61, 0x70, 0x2e, 0x50, 0x69, 0x70, 0x65, - 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x02, 0x69, 0x6e, 0x12, 0x2f, 0x0a, 0x03, 0x6f, 0x75, 0x74, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x2e, 0x50, 0x69, 0x70, 0x65, 0x4d, 0x61, 0x70, 0x2e, 0x50, 0x69, 0x70, 0x65, - 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x03, 0x6f, 0x75, 0x74, 0x1a, 0x31, 0x0a, 0x09, 0x50, 0x69, - 0x70, 0x65, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x0e, 0x0a, - 0x02, 0x66, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x66, 0x64, 0x22, 0xb9, 0x06, - 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x12, 0x2d, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x75, - 0x6c, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x62, 0x2e, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x07, - 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x1a, 0xc9, 0x05, - 0x0a, 0x06, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x36, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1e, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x53, 0x74, - 0x61, 0x74, 0x75, 0x73, 0x54, 0x79, 0x70, 0x65, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x12, 0x1e, 0x0a, 0x0a, 0x65, 0x78, 0x69, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x65, 0x78, 0x69, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x04, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x75, - 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x72, 0x75, 0x6e, - 0x54, 0x69, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x12, 0x34, 0x0a, 0x05, - 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x62, - 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, - 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x66, 0x69, 0x6c, - 0x65, 0x73, 0x12, 0x3a, 0x0a, 0x07, 0x66, 0x69, 0x6c, 0x65, 0x49, 0x44, 0x73, 0x18, 0x07, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x49, 0x44, 0x73, - 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x66, 0x69, 0x6c, 0x65, 0x49, 0x44, 0x73, 0x1a, 0x38, - 0x0a, 0x0a, 0x46, 0x69, 0x6c, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, + 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3a, 0x0a, 0x0c, + 0x46, 0x69, 0x6c, 0x65, 0x49, 0x44, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3a, 0x0a, 0x0c, 0x46, 0x69, 0x6c, 0x65, - 0x49, 0x44, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x3a, 0x02, 0x38, 0x01, 0x22, 0xa2, 0x02, 0x0a, 0x0a, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x54, - 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x00, - 0x12, 0x0c, 0x0a, 0x08, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x10, 0x01, 0x12, 0x0f, - 0x0a, 0x0b, 0x57, 0x72, 0x6f, 0x6e, 0x67, 0x41, 0x6e, 0x73, 0x77, 0x65, 0x72, 0x10, 0x02, 0x12, - 0x14, 0x0a, 0x10, 0x50, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x6c, 0x79, 0x43, 0x6f, 0x72, 0x72, - 0x65, 0x63, 0x74, 0x10, 0x03, 0x12, 0x17, 0x0a, 0x13, 0x4d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x4c, - 0x69, 0x6d, 0x69, 0x74, 0x45, 0x78, 0x63, 0x65, 0x65, 0x64, 0x65, 0x64, 0x10, 0x04, 0x12, 0x15, - 0x0a, 0x11, 0x54, 0x69, 0x6d, 0x65, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x45, 0x78, 0x63, 0x65, 0x65, - 0x64, 0x65, 0x64, 0x10, 0x05, 0x12, 0x17, 0x0a, 0x13, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x4c, - 0x69, 0x6d, 0x69, 0x74, 0x45, 0x78, 0x63, 0x65, 0x65, 0x64, 0x65, 0x64, 0x10, 0x06, 0x12, 0x0d, - 0x0a, 0x09, 0x46, 0x69, 0x6c, 0x65, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x07, 0x12, 0x15, 0x0a, - 0x11, 0x4e, 0x6f, 0x6e, 0x5a, 0x65, 0x72, 0x6f, 0x45, 0x78, 0x69, 0x74, 0x53, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x10, 0x08, 0x12, 0x0d, 0x0a, 0x09, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x6c, 0x65, - 0x64, 0x10, 0x09, 0x12, 0x14, 0x0a, 0x10, 0x44, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x6f, 0x75, 0x73, - 0x53, 0x79, 0x73, 0x63, 0x61, 0x6c, 0x6c, 0x10, 0x0a, 0x12, 0x13, 0x0a, 0x0f, 0x4a, 0x75, 0x64, - 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, 0x0b, 0x12, 0x16, - 0x0a, 0x12, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x61, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x10, 0x0c, 0x12, 0x11, 0x0a, 0x0d, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, - 0x61, 0x6c, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0d, 0x22, 0xd9, 0x02, 0x0a, 0x0d, 0x53, 0x74, - 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2f, 0x0a, 0x0b, 0x65, - 0x78, 0x65, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x0b, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x48, 0x00, 0x52, - 0x0b, 0x65, 0x78, 0x65, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x37, 0x0a, 0x09, - 0x65, 0x78, 0x65, 0x63, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x17, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x2e, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x48, 0x00, 0x52, 0x09, 0x65, 0x78, 0x65, 0x63, - 0x49, 0x6e, 0x70, 0x75, 0x74, 0x12, 0x3a, 0x0a, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x52, 0x65, 0x73, - 0x69, 0x7a, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x62, 0x2e, 0x53, - 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x52, 0x65, 0x73, - 0x69, 0x7a, 0x65, 0x48, 0x00, 0x52, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x52, 0x65, 0x73, 0x69, 0x7a, - 0x65, 0x1a, 0x35, 0x0a, 0x05, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, - 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x1a, 0x60, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x69, - 0x7a, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f, 0x77, 0x73, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x72, 0x6f, 0x77, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, - 0x6c, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x63, 0x6f, 0x6c, 0x73, 0x12, 0x0c, - 0x0a, 0x01, 0x78, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01, - 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x01, 0x79, 0x42, 0x09, 0x0a, 0x07, 0x72, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0xc5, 0x01, 0x0a, 0x0e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x32, 0x0a, 0x0c, 0x65, 0x78, 0x65, 0x63, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, - 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x48, 0x00, 0x52, 0x0c, - 0x65, 0x78, 0x65, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x0a, - 0x65, 0x78, 0x65, 0x63, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x19, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x48, 0x00, 0x52, 0x0a, 0x65, - 0x78, 0x65, 0x63, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x1a, 0x36, 0x0a, 0x06, 0x4f, 0x75, 0x74, - 0x70, 0x75, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, - 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, - 0x74, 0x42, 0x0a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x84, 0x02, - 0x0a, 0x08, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x6f, 0x72, 0x12, 0x21, 0x0a, 0x04, 0x45, 0x78, - 0x65, 0x63, 0x12, 0x0b, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x0c, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x37, 0x0a, - 0x0a, 0x45, 0x78, 0x65, 0x63, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x11, 0x2e, 0x70, 0x62, - 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, - 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x28, 0x01, 0x30, 0x01, 0x12, 0x27, 0x0a, 0x08, 0x46, 0x69, 0x6c, 0x65, 0x4c, 0x69, - 0x73, 0x74, 0x12, 0x09, 0x2e, 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x10, 0x2e, - 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, - 0x26, 0x0a, 0x07, 0x46, 0x69, 0x6c, 0x65, 0x47, 0x65, 0x74, 0x12, 0x0a, 0x2e, 0x70, 0x62, 0x2e, - 0x46, 0x69, 0x6c, 0x65, 0x49, 0x44, 0x1a, 0x0f, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6c, 0x65, - 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x26, 0x0a, 0x07, 0x46, 0x69, 0x6c, 0x65, 0x41, - 0x64, 0x64, 0x12, 0x0f, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x43, 0x6f, 0x6e, 0x74, - 0x65, 0x6e, 0x74, 0x1a, 0x0a, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x49, 0x44, 0x12, - 0x23, 0x0a, 0x0a, 0x46, 0x69, 0x6c, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x0a, 0x2e, - 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x49, 0x44, 0x1a, 0x09, 0x2e, 0x70, 0x62, 0x2e, 0x45, - 0x6d, 0x70, 0x74, 0x79, 0x42, 0x1f, 0x5a, 0x1d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x63, 0x72, 0x69, 0x79, 0x6c, 0x65, 0x2f, 0x67, 0x6f, 0x2d, 0x6a, 0x75, 0x64, - 0x67, 0x65, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xa2, 0x02, 0x0a, 0x0a, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x49, 0x6e, 0x76, 0x61, 0x6c, + 0x69, 0x64, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, + 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x57, 0x72, 0x6f, 0x6e, 0x67, 0x41, 0x6e, 0x73, 0x77, 0x65, + 0x72, 0x10, 0x02, 0x12, 0x14, 0x0a, 0x10, 0x50, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x6c, 0x79, + 0x43, 0x6f, 0x72, 0x72, 0x65, 0x63, 0x74, 0x10, 0x03, 0x12, 0x17, 0x0a, 0x13, 0x4d, 0x65, 0x6d, + 0x6f, 0x72, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x45, 0x78, 0x63, 0x65, 0x65, 0x64, 0x65, 0x64, + 0x10, 0x04, 0x12, 0x15, 0x0a, 0x11, 0x54, 0x69, 0x6d, 0x65, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x45, + 0x78, 0x63, 0x65, 0x65, 0x64, 0x65, 0x64, 0x10, 0x05, 0x12, 0x17, 0x0a, 0x13, 0x4f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x45, 0x78, 0x63, 0x65, 0x65, 0x64, 0x65, 0x64, + 0x10, 0x06, 0x12, 0x0d, 0x0a, 0x09, 0x46, 0x69, 0x6c, 0x65, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, + 0x07, 0x12, 0x15, 0x0a, 0x11, 0x4e, 0x6f, 0x6e, 0x5a, 0x65, 0x72, 0x6f, 0x45, 0x78, 0x69, 0x74, + 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x10, 0x08, 0x12, 0x0d, 0x0a, 0x09, 0x53, 0x69, 0x67, 0x6e, + 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x10, 0x09, 0x12, 0x14, 0x0a, 0x10, 0x44, 0x61, 0x6e, 0x67, 0x65, + 0x72, 0x6f, 0x75, 0x73, 0x53, 0x79, 0x73, 0x63, 0x61, 0x6c, 0x6c, 0x10, 0x0a, 0x12, 0x13, 0x0a, + 0x0f, 0x4a, 0x75, 0x64, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, + 0x10, 0x0b, 0x12, 0x16, 0x0a, 0x12, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x49, 0x6e, 0x74, + 0x65, 0x72, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x10, 0x0c, 0x12, 0x11, 0x0a, 0x0d, 0x49, 0x6e, + 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0d, 0x22, 0xd9, 0x02, + 0x0a, 0x0d, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x2f, 0x0a, 0x0b, 0x65, 0x78, 0x65, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x48, 0x00, 0x52, 0x0b, 0x65, 0x78, 0x65, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x37, 0x0a, 0x09, 0x65, 0x78, 0x65, 0x63, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x48, 0x00, 0x52, 0x09, + 0x65, 0x78, 0x65, 0x63, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x12, 0x3a, 0x0a, 0x0a, 0x65, 0x78, 0x65, + 0x63, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, + 0x70, 0x62, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x2e, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x48, 0x00, 0x52, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x52, + 0x65, 0x73, 0x69, 0x7a, 0x65, 0x1a, 0x35, 0x0a, 0x05, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x12, 0x12, + 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x1a, 0x60, 0x0a, 0x06, + 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f, + 0x77, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x72, 0x6f, 0x77, 0x73, 0x12, 0x12, + 0x0a, 0x04, 0x63, 0x6f, 0x6c, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x63, 0x6f, + 0x6c, 0x73, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x01, 0x78, + 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x01, 0x79, 0x42, 0x09, + 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0xc5, 0x01, 0x0a, 0x0e, 0x53, 0x74, + 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x32, 0x0a, 0x0c, + 0x65, 0x78, 0x65, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x48, 0x00, 0x52, 0x0c, 0x65, 0x78, 0x65, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x3b, 0x0a, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x48, + 0x00, 0x52, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x1a, 0x36, 0x0a, + 0x06, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, + 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x6f, + 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x42, 0x0a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x32, 0x84, 0x02, 0x0a, 0x08, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x6f, 0x72, 0x12, 0x21, + 0x0a, 0x04, 0x45, 0x78, 0x65, 0x63, 0x12, 0x0b, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x0c, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x37, 0x0a, 0x0a, 0x45, 0x78, 0x65, 0x63, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, + 0x11, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x30, 0x01, 0x12, 0x27, 0x0a, 0x08, 0x46, 0x69, + 0x6c, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x09, 0x2e, 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x70, 0x74, + 0x79, 0x1a, 0x10, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x26, 0x0a, 0x07, 0x46, 0x69, 0x6c, 0x65, 0x47, 0x65, 0x74, 0x12, 0x0a, + 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x49, 0x44, 0x1a, 0x0f, 0x2e, 0x70, 0x62, 0x2e, + 0x46, 0x69, 0x6c, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x26, 0x0a, 0x07, 0x46, + 0x69, 0x6c, 0x65, 0x41, 0x64, 0x64, 0x12, 0x0f, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6c, 0x65, + 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x1a, 0x0a, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6c, + 0x65, 0x49, 0x44, 0x12, 0x23, 0x0a, 0x0a, 0x46, 0x69, 0x6c, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x65, 0x12, 0x0a, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x49, 0x44, 0x1a, 0x09, 0x2e, + 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x1f, 0x5a, 0x1d, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x72, 0x69, 0x79, 0x6c, 0x65, 0x2f, 0x67, 0x6f, + 0x2d, 0x6a, 0x75, 0x64, 0x67, 0x65, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( diff --git a/pb/judge.proto b/pb/judge.proto index d13947c..fe47074 100644 --- a/pb/judge.proto +++ b/pb/judge.proto @@ -81,6 +81,7 @@ message Request { uint64 memoryLimit = 6; uint64 stackLimit = 12; uint64 procLimit = 7; + double CPURateLimit = 15; map copyIn = 8; diff --git a/pkg/envexec/cmd.go b/pkg/envexec/cmd.go index 723a827..5b6b47c 100644 --- a/pkg/envexec/cmd.go +++ b/pkg/envexec/cmd.go @@ -35,6 +35,7 @@ type Cmd struct { ExtraMemoryLimit Size OutputLimit Size ProcLimit uint64 + CPURateLimit float64 // file contents to copyin before exec CopyIn map[string]file.File diff --git a/pkg/envexec/interface.go b/pkg/envexec/interface.go index 1093a38..d4e00a3 100644 --- a/pkg/envexec/interface.go +++ b/pkg/envexec/interface.go @@ -34,6 +34,7 @@ type Limit struct { Proc uint64 // Process count limit Stack Size // Stack limit Output Size // Output limit + Rate float64 // CPU Rate limit } // Usage defines the peak process resource usage diff --git a/pkg/envexec/run_single.go b/pkg/envexec/run_single.go index a789b10..6e80cc8 100644 --- a/pkg/envexec/run_single.go +++ b/pkg/envexec/run_single.go @@ -47,6 +47,7 @@ func runSingle(pc context.Context, m Environment, c *Cmd, fds []*os.File, ptc [] Memory: memoryLimit, Proc: c.ProcLimit, Stack: stackLimit, + Rate: c.CPURateLimit, }, } diff --git a/pkg/pool/cgroup_fake_pool_linux.go b/pkg/pool/cgroup_fake_pool_linux.go index b5f2982..24b1ad6 100644 --- a/pkg/pool/cgroup_fake_pool_linux.go +++ b/pkg/pool/cgroup_fake_pool_linux.go @@ -1,15 +1,18 @@ package pool +import "time" + var _ CgroupPool = &FakeCgroupPool{} // FakeCgroupPool implements cgroup pool but not actually do pool type FakeCgroupPool struct { - builder CgroupBuilder + builder CgroupBuilder + cfsPeriod time.Duration } // NewFakeCgroupPool creates FakeCgroupPool -func NewFakeCgroupPool(builder CgroupBuilder) CgroupPool { - return &FakeCgroupPool{builder: builder} +func NewFakeCgroupPool(builder CgroupBuilder, cfsPeriod time.Duration) CgroupPool { + return &FakeCgroupPool{builder: builder, cfsPeriod: cfsPeriod} } // Get gets new cgroup @@ -18,7 +21,7 @@ func (f *FakeCgroupPool) Get() (Cgroup, error) { if err != nil { return nil, err } - return (*wCgroup)(cg), nil + return &wCgroup{cg: cg, cfsPeriod: f.cfsPeriod}, nil } // Put destory the cgroup diff --git a/pkg/pool/cgroup_wrapper_linux.go b/pkg/pool/cgroup_wrapper_linux.go index 138c2a3..0dbec80 100644 --- a/pkg/pool/cgroup_wrapper_linux.go +++ b/pkg/pool/cgroup_wrapper_linux.go @@ -11,27 +11,38 @@ var ( _ Cgroup = &wCgroup{} ) -type wCgroup cgroup.Cgroup +type wCgroup struct { + cg *cgroup.Cgroup + cfsPeriod time.Duration +} + +func (c *wCgroup) SetCPURate(s float64) error { + if err := c.cg.SetCPUCfsPeriod(uint64(c.cfsPeriod.Microseconds())); err != nil { + return err + } + quota := time.Duration(float64(c.cfsPeriod) * s) + return c.cg.SetCPUCfsQuota(uint64(quota.Microseconds())) +} func (c *wCgroup) SetCpuset(s string) error { - return (*cgroup.Cgroup)(c).SetCpusetCpus([]byte(s)) + return c.cg.SetCpusetCpus([]byte(s)) } func (c *wCgroup) SetMemoryLimit(s envexec.Size) error { - return (*cgroup.Cgroup)(c).SetMemoryLimitInBytes(uint64(s)) + return c.cg.SetMemoryLimitInBytes(uint64(s)) } func (c *wCgroup) SetProcLimit(l uint64) error { - return (*cgroup.Cgroup)(c).SetPidsMax(l) + return c.cg.SetPidsMax(l) } func (c *wCgroup) CPUUsage() (time.Duration, error) { - t, err := (*cgroup.Cgroup)(c).CpuacctUsage() + t, err := c.cg.CpuacctUsage() return time.Duration(t), err } func (c *wCgroup) MemoryUsage() (envexec.Size, error) { - s, err := (*cgroup.Cgroup)(c).MemoryMaxUsageInBytes() + s, err := c.cg.MemoryMaxUsageInBytes() if err != nil { return 0, err } @@ -45,19 +56,19 @@ func (c *wCgroup) MemoryUsage() (envexec.Size, error) { } func (c *wCgroup) AddProc(pid int) error { - return (*cgroup.Cgroup)(c).AddProc(pid) + return c.cg.AddProc(pid) } func (c *wCgroup) Reset() error { - if err := (*cgroup.Cgroup)(c).SetCpuacctUsage(0); err != nil { + if err := c.cg.SetCpuacctUsage(0); err != nil { return err } - if err := (*cgroup.Cgroup)(c).SetMemoryMaxUsageInBytes(0); err != nil { + if err := c.cg.SetMemoryMaxUsageInBytes(0); err != nil { return err } return nil } func (c *wCgroup) Destroy() error { - return (*cgroup.Cgroup)(c).Destroy() + return c.cg.Destroy() } diff --git a/pkg/pool/cgrouppool_linux.go b/pkg/pool/cgrouppool_linux.go index 58205b6..2147c50 100644 --- a/pkg/pool/cgrouppool_linux.go +++ b/pkg/pool/cgrouppool_linux.go @@ -12,6 +12,7 @@ type Cgroup interface { SetCpuset(string) error SetMemoryLimit(envexec.Size) error SetProcLimit(uint64) error + SetCPURate(float64) error CPUUsage() (time.Duration, error) MemoryUsage() (envexec.Size, error) @@ -29,15 +30,16 @@ type CgroupPool interface { // CgroupListPool implements cgroup pool type CgroupListPool struct { - builder CgroupBuilder + builder CgroupBuilder + cfsPeriod time.Duration cgs []Cgroup mu sync.Mutex } // NewCgroupListPool creates new cgroup pool -func NewCgroupListPool(builder CgroupBuilder) CgroupPool { - return &CgroupListPool{builder: builder} +func NewCgroupListPool(builder CgroupBuilder, cfsPeriod time.Duration) CgroupPool { + return &CgroupListPool{builder: builder, cfsPeriod: cfsPeriod} } // Get gets cgroup from pool, if pool is empty, creates new one @@ -55,7 +57,7 @@ func (w *CgroupListPool) Get() (Cgroup, error) { if err != nil { return nil, err } - return (*wCgroup)(cg), nil + return &wCgroup{cg: cg, cfsPeriod: w.cfsPeriod}, nil } // Put puts cgroup into the pool diff --git a/pkg/pool/envbuilder_linux.go b/pkg/pool/envbuilder_linux.go index 5e73149..6d4adfd 100644 --- a/pkg/pool/envbuilder_linux.go +++ b/pkg/pool/envbuilder_linux.go @@ -12,15 +12,17 @@ type environmentBuilder struct { cgPool CgroupPool workDir string cpuset string + cpuRate bool } // NewEnvBuilder creates builder for linux container pools -func NewEnvBuilder(builder EnvironmentBuilder, cgPool CgroupPool, workDir, cpuset string) EnvBuilder { +func NewEnvBuilder(builder EnvironmentBuilder, cgPool CgroupPool, workDir, cpuset string, cpuRate bool) EnvBuilder { return &environmentBuilder{ builder: builder, cgPool: cgPool, workDir: workDir, cpuset: cpuset, + cpuRate: cpuRate, } } @@ -43,5 +45,6 @@ func (b *environmentBuilder) Build() (Environment, error) { cgPool: b.cgPool, wd: wd[0], cpuset: b.cpuset, + cpuRate: b.cpuRate, }, nil } diff --git a/pkg/pool/environment_linux.go b/pkg/pool/environment_linux.go index 9ea6e95..911b8c0 100644 --- a/pkg/pool/environment_linux.go +++ b/pkg/pool/environment_linux.go @@ -17,9 +17,10 @@ var _ envexec.Environment = &environ{} // environ defines interface to access container resources type environ struct { container.Environment - cgPool CgroupPool - wd *os.File // container work dir - cpuset string + cgPool CgroupPool + wd *os.File // container work dir + cpuset string + cpuRate bool } // Destory destories the environment @@ -47,6 +48,9 @@ func (c *environ) Execve(ctx context.Context, param envexec.ExecveParam) (envexe if c.cpuset != "" { cg.SetCpuset(c.cpuset) } + if c.cpuRate && param.Limit.Rate > 0 { + cg.SetCPURate(param.Limit.Rate) + } cg.SetMemoryLimit(param.Limit.Memory) cg.SetProcLimit(param.Limit.Proc) syncFunc = cg.AddProc diff --git a/worker/model.go b/worker/model.go index b889170..af92561 100644 --- a/worker/model.go +++ b/worker/model.go @@ -14,6 +14,7 @@ type Cmd struct { MemoryLimit uint64 StackLimit uint64 ProcLimit uint64 + CPURateLimit float64 CopyIn map[string]CmdFile diff --git a/worker/worker.go b/worker/worker.go index 60911fa..a276a78 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -290,6 +290,7 @@ func (w *worker) prepareCmd(rc Cmd) (*envexec.Cmd, map[string]bool, error) { ExtraMemoryLimit: w.extraMemoryLimit, OutputLimit: w.outputLimit, ProcLimit: rc.ProcLimit, + CPURateLimit: rc.CPURateLimit, CopyIn: copyIn, CopyOut: copyOut, CopyOutDir: copyOutDir,