Skip to content

Commit 69af13c

Browse files
committed
libct/int: add exec benchmark
This is a benchmark which checks how fast we can execute /bin/true inside a container. Results from my machine are below. As you can see, in default setup about 70% of exec time is spent for CVE-2019-5736 (copying runc binary), and using either RUNC_DMZ=true or memfd-bind helps a lot. This can also be used for profiling (using -test.cpuprofile option). === Default setup === [kir@kir-tp1 integration]$ sudo ./integration.test -test.run xxx -test.v -test.benchtime 5s -test.count 5 -test.bench . . goos: linux goarch: amd64 pkg: github.com/opencontainers/runc/libcontainer/integration cpu: 12th Gen Intel(R) Core(TM) i7-12800H BenchmarkExecTrue BenchmarkExecTrue-20 327 24475677 ns/op BenchmarkExecTrue-20 244 25242718 ns/op BenchmarkExecTrue-20 232 26187174 ns/op BenchmarkExecTrue-20 237 26780030 ns/op BenchmarkExecTrue-20 318 18487219 ns/op PASS === With DMZ enabled === [kir@kir-tp1 integration]$ sudo -E RUNC_DMZ=true ./integration.test -test.run xxx -test.v -test.benchtime 5s -test.count 5 -test.bench . . goos: linux goarch: amd64 pkg: github.com/opencontainers/runc/libcontainer/integration cpu: 12th Gen Intel(R) Core(TM) i7-12800H BenchmarkExecTrue BenchmarkExecTrue-20 694 8263744 ns/op BenchmarkExecTrue-20 778 8483228 ns/op BenchmarkExecTrue-20 784 8456018 ns/op BenchmarkExecTrue-20 732 8160239 ns/op BenchmarkExecTrue-20 769 8236972 ns/op PASS === With memfd-bind === [kir@kir-tp1 integration]$ sudo systemctl start memfd-bind@$(systemd-escape -p $PWD/integration.test) [kir@kir-tp1 integration]$ sudo ./integration.test -test.run xxx -test.v -test.benchtime 5s -test.count 5 -test.bench . . goos: linux goarch: amd64 pkg: github.com/opencontainers/runc/libcontainer/integration cpu: 12th Gen Intel(R) Core(TM) i7-12800H BenchmarkExecTrue BenchmarkExecTrue-20 800 7538839 ns/op BenchmarkExecTrue-20 717 7424755 ns/op BenchmarkExecTrue-20 848 7747787 ns/op BenchmarkExecTrue-20 800 7668740 ns/op BenchmarkExecTrue-20 751 7304373 ns/op PASS Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 4f20cfc commit 69af13c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package integration
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/opencontainers/runc/libcontainer"
8+
)
9+
10+
func BenchmarkExecTrue(b *testing.B) {
11+
config := newTemplateConfig(b, nil)
12+
container, err := newContainer(b, config)
13+
ok(b, err)
14+
defer destroyContainer(container)
15+
16+
// Execute a first process in the container
17+
stdinR, stdinW, err := os.Pipe()
18+
ok(b, err)
19+
process := &libcontainer.Process{
20+
Cwd: "/",
21+
Args: []string{"cat"},
22+
Env: standardEnvironment,
23+
Stdin: stdinR,
24+
Init: true,
25+
}
26+
err = container.Run(process)
27+
_ = stdinR.Close()
28+
defer func() {
29+
_ = stdinW.Close()
30+
if _, err := process.Wait(); err != nil {
31+
b.Log(err)
32+
}
33+
}()
34+
ok(b, err)
35+
36+
b.ResetTimer()
37+
for i := 0; i < b.N; i++ {
38+
exec := &libcontainer.Process{
39+
Cwd: "/",
40+
Args: []string{"/bin/true"},
41+
Env: standardEnvironment,
42+
LogLevel: "0", // Minimize forwardChildLogs involvement.
43+
}
44+
err := container.Run(exec)
45+
if err != nil {
46+
b.Fatal("exec failed:", err)
47+
}
48+
waitProcess(exec, b)
49+
}
50+
b.StopTimer()
51+
}

0 commit comments

Comments
 (0)