Skip to content

Commit 567b770

Browse files
committed
docs: reorganized README and add online documentations
1 parent 3f2baa3 commit 567b770

File tree

2 files changed

+23
-78
lines changed

2 files changed

+23
-78
lines changed

README.cn.md

+11-36
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Go Reference](https://pkg.go.dev/badge/github.com/criyle/go-judge.svg)](https://pkg.go.dev/github.com/criyle/go-judge) [![Go Report Card](https://goreportcard.com/badge/github.com/criyle/go-judge)](https://goreportcard.com/report/github.com/criyle/go-judge) [![Release](https://img.shields.io/github/v/tag/criyle/go-judge)](https://github.com/criyle/go-judge/releases/latest) ![Build](https://github.com/criyle/go-judge/workflows/Build/badge.svg)
44

5-
[English](README.md)
5+
[English](README.md) | [文档](https://docs.goj.ac/cn)
66

77
快速,简单,安全
88

@@ -475,7 +475,7 @@ interface Output {
475475

476476
所有命令行参数都可以通过环境变量的形式来指定,(类似 `ES_HTTP_ADDR` 来指定 `-http-addr`)。使用 `go-judge --help` 查看所有环境变量
477477

478-
#### 编译 docker
478+
### 编译 docker
479479

480480
终端中运行 `docker build -t go-judge -f Dockerfile.exec .`
481481

@@ -530,6 +530,14 @@ interface Output {
530530

531531
### 注意
532532

533+
#### 使用 cgroup
534+
535+
在 cgroup v1 系统上 `go-judge` 需要 `root` 权限创建 `cgroup`。请使用 `sudo``root` 用户运行或者确保运行用户拥有以下目录的读写权限 `/sys/fs/cgroup/cpuacct/gojudge`, `/sys/fs/cgroup/memory/gojudge`, `/sys/fs/cgroup/pids/gojudge`
536+
537+
在 cgroup v2 系统上,`go-judge` 会和 `system dbus` 沟通,创建一个临时 `scope`。如果 `systemd` 不存在,并且拥有 `root` 权限那么将尝试进行嵌套初始化。
538+
539+
如果没有 `cgroup` 的权限,那么 `cgroup` 相关的资源配置将不会生效。
540+
533541
#### cgroup v2
534542

535543
`go-judge` 目前已经支持 cgroup v2 鉴于越来越多的 Linux 发行版默认启用 cgroup v2 而不是 v1 (比如 Ubuntu 21.10+,Fedora 31+)。然而,对于内核版本小于 5.19 的版本,因为 cgroup v2 在内存控制器里面缺少 `memory.max_usage_in_bytes`,内存使用量计数会转而采用 `maxrss` 指标。这项指标会显示的比使用 cgroup v1 时候要稍多,在运行使用内存较少的程序时比较明显。对于内核版本大于或等于 5.19 的版本,`memory.peak` 会被采用。
@@ -538,7 +546,7 @@ interface Output {
538546

539547
`systemd``init` 的发行版中运行时,`go-judge` 会使用 `dbus` 通知 `systemd` 来创建一个临时 `scope` 作为 `cgroup` 的根。
540548

541-
在高于 5.7 的内核中运行时,`go-judge` 会尝试更快的 `clone3(CLONE_INTO_CGROUP)` 方法.
549+
在高于 5.7 的内核中运行时,`go-judge` 会尝试更快的 `clone3(CLONE_INTO_CGROUP)` `vfork` 方法.
542550

543551
#### 内存使用
544552

@@ -573,36 +581,3 @@ WebSocket 流接口是用于运行一个程序,同时和它的输入输出进
573581
```
574582

575583
任何的不完整,或者不合法的消息会被认为是错误,并终止运行。
576-
577-
### 压力测试
578-
579-
使用 `wrk``t.lua`: `wrk -s t.lua -c 1 -t 1 -d 30s --latency http://localhost:5050/run`.
580-
581-
注意,这些结果只是极限情况下的表现,实际情况和使用方式相关。通常沙箱服务相比于直接运行程序,通常有 1 毫秒左右额外延迟。
582-
583-
```lua
584-
wrk.method = "POST"
585-
wrk.body = '{"cmd":[{"args":["/bin/cat","a.hs"],"env":["PATH=/usr/bin:/bin"],"files":[{"content":""},{"name":"stdout","max":10240},{"name":"stderr","max":10240}],"cpuLimit":10000000000,"memoryLimit":104857600,"procLimit":50,"copyIn":{"a.hs":{"content":"main = putStrLn \\"Hello, World!\\""},"b":{"content":"TEST"}}}]}'
586-
wrk.headers["Content-Type"] = "application/json;charset=UTF-8"
587-
```
588-
589-
- 单线程 ~800-860 op/s Windows 10 WSL2 @ 5800X
590-
- 多线程 ~4500-6000 op/s Windows 10 WSL2 @ 5800X
591-
592-
单线程:
593-
594-
```text
595-
Running 30s test @ http://localhost:5050/run
596-
1 threads and 1 connections
597-
Thread Stats Avg Stdev Max +/- Stdev
598-
Latency 1.16ms 132.89us 6.20ms 90.15%
599-
Req/Sec 0.87k 19.33 0.91k 85.33%
600-
Latency Distribution
601-
50% 1.13ms
602-
75% 1.18ms
603-
90% 1.27ms
604-
99% 1.61ms
605-
25956 requests in 30.01s, 6.88MB read
606-
Requests/sec: 864.88
607-
Transfer/sec: 234.68KB
608-
```

README.md

+12-42
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Go Reference](https://pkg.go.dev/badge/github.com/criyle/go-judge.svg)](https://pkg.go.dev/github.com/criyle/go-judge) [![Go Report Card](https://goreportcard.com/badge/github.com/criyle/go-judge)](https://goreportcard.com/report/github.com/criyle/go-judge) [![Release](https://img.shields.io/github/v/tag/criyle/go-judge)](https://github.com/criyle/go-judge/releases/latest) ![Build](https://github.com/criyle/go-judge/workflows/Build/badge.svg)
44

5-
[中文文档](README.cn.md)
5+
[中文文档](README.cn.md) | [Documentation](https://docs.goj.ac)
66

77
Fast, Simple, Secure
88

@@ -659,15 +659,11 @@ Sandbox:
659659

660660
Environment variable will be override by command line arguments if they both present and all command line arguments have its correspond environment variable (e.g. `ES_HTTP_ADDR`). Run `go-judge --help` to see all the environment variable configurations.
661661

662-
#### Build go judge
662+
### Build go judge
663663

664664
Build by your own `docker build -t go-judge -f Dockerfile.exec .`
665665

666-
For cgroup v1, the `go-judge` need root privilege to create `cgroup`. Either creates sub-directory `/sys/fs/cgroup/cpuacct/go_judge`, `/sys/fs/cgroup/memory/go_judge`, `/sys/fs/cgroup/pids/go_judge` and make execution user readable or use `sudo` to run it.
667-
668-
For cgroup v2, systemd dbus will be used to create a transient scope for cgroup integration.
669-
670-
#### Build Shared object
666+
### Build Shared object
671667

672668
Build container init `cinit`:
673669

@@ -754,6 +750,14 @@ If a bind mount is specifying a target within the previous mounted one, please e
754750

755751
### Notice
756752

753+
#### cgroup usage
754+
755+
For cgroup v1, the `go-judge` need root privilege to create `cgroup`. Either creates sub-directory `/sys/fs/cgroup/cpuacct/gojudge`, `/sys/fs/cgroup/memory/gojudge`, `/sys/fs/cgroup/pids/gojudge` and make execution user readable or use `sudo` to run it.
756+
757+
For cgroup v2, systemd dbus will be used to create a transient scope for cgroup integration.
758+
759+
If no permission to create cgroup, the cgroup related limit will not be effective.
760+
757761
#### cgroup v2 support
758762

759763
The cgroup v2 is supported by `go-judge` now when running as root since more Linux distribution are enabling cgroup v2 by default (e.g. Ubuntu 21.10+, Fedora 31+). However, for kernel < 5.19, due to missing `memory.max_usage_in_bytes` in `memory` controller, the memory usage is now accounted by `maxrss` returned by `wait4` syscall. Thus, the memory usage appears higher than those who uses cgroup v1. For kernel >= 5.19, `memory.peak` is being used.
@@ -762,7 +766,7 @@ When running in containers, the `go-judge` will migrate all processed into `/api
762766

763767
When running in Linux distributions powered by `systemd`, the `go-judge` will contact `systemd` via `dbus` to create a transient scope as cgroup root.
764768

765-
When running with kernel >= 5.7, the `go-judge` will try faster `clone3(CLONE_INTO_CGROUP)` method.
769+
When running with kernel >= 5.7, the `go-judge` will try faster `clone3(CLONE_INTO_CGROUP)` and `vfork` method.
766770

767771
#### Memory Usage
768772

@@ -797,37 +801,3 @@ type =
797801
```
798802

799803
Any incomplete / invalid message will be treated as error.
800-
801-
### Benchmark
802-
803-
By `wrk` with `t.lua`: `wrk -s t.lua -c 1 -t 1 -d 30s --latency http://localhost:5050/run`.
804-
805-
However, these results are not the real use cases since the running time depends on the actual program specifies in the request. Normally, the go judge consumes ~1ms more compare to running without sandbox.
806-
807-
```lua
808-
wrk.method = "POST"
809-
wrk.body = '{"cmd":[{"args":["/bin/cat","a.hs"],"env":["PATH=/usr/bin:/bin"],"files":[{"content":""},{"name":"stdout","max":10240},{"name":"stderr","max":10240}],"cpuLimit":10000000000,"memoryLimit":104857600,"procLimit":50,"copyIn":{"a.hs":{"content":"main = putStrLn \\"Hello, World!\\""},"b":{"content":"TEST"}}}]}'
810-
wrk.headers["Content-Type"] = "application/json;charset=UTF-8"
811-
```
812-
813-
- Single thread ~800-860 op/s Windows 10 WSL2 @ 5800X
814-
- Multi thread ~4500-6000 op/s Windows 10 WSL2 @ 5800X
815-
816-
Single thread:
817-
818-
```text
819-
Running 30s test @ http://localhost:5050/run
820-
1 threads and 1 connections
821-
Thread Stats Avg Stdev Max +/- Stdev
822-
Latency 1.16ms 132.89us 6.20ms 90.15%
823-
Req/Sec 0.87k 19.33 0.91k 85.33%
824-
Latency Distribution
825-
50% 1.13ms
826-
75% 1.18ms
827-
90% 1.27ms
828-
99% 1.61ms
829-
25956 requests in 30.01s, 6.88MB read
830-
Requests/sec: 864.88
831-
Transfer/sec: 234.68KB
832-
```
833-

0 commit comments

Comments
 (0)