Skip to content

Commit 8c5bec4

Browse files
committed
benchmark: add a testcase for creating a pod and a container
Add a testcase for measuring the time of creating a pod and container. Signed-off-by: Fupan Li <[email protected]>
1 parent 5f10256 commit 8c5bec4

File tree

2 files changed

+276
-0
lines changed

2 files changed

+276
-0
lines changed

pkg/benchmark/README.md

+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# pod and container lifecycle benchmark for kata
2+
3+
This repocitory is mainly focused on the pod and container's lifecircle benchmark for kata. The way to run a kata container is
4+
used cri + containerd + containerd-shim-kata-v2.
5+
6+
## Install
7+
8+
### Install kata components
9+
```sh
10+
ARCH=$(arch)
11+
sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/katacontainers:/releases:/${ARCH}:/master/xUbuntu_$(lsb_release -rs)/ /' > /etc/apt/sources.list.d/kata-containers.list"
12+
curl -sL http://download.opensuse.org/repositories/home:/katacontainers:/releases:/${ARCH}:/master/xUbuntu_$(lsb_release -rs)/Release.key | sudo apt-key add -
13+
sudo -E apt-get update
14+
sudo -E apt-get -y install kata-runtime kata-proxy kata-shim
15+
```
16+
### Install kata shimv2
17+
```sh
18+
go get github.com/kata-containers/runtime
19+
pushd $GOPATH/src/github.com/kata-containers/runtime
20+
make
21+
sudo -E PATH=$PATH make install
22+
popd
23+
24+
sed -i 's/image =/#image =/' /usr/share/defaults/kata-containers/configuration.toml
25+
```
26+
### Install critest
27+
28+
```sh
29+
go get https://github.com/kubernetes-sigs/cri-tools.git
30+
pushd $GOPATH/src/github.com/kubernetes-sigs/cri-tools
31+
make;make install
32+
```
33+
34+
### Install containerd
35+
```sh
36+
sudo apt-get update
37+
sudo apt-get install libseccomp-dev btrfs-tools git -y
38+
go get github.com/containerd/containerd
39+
pushd $GOPATH/src/github.com/containerd/containerd
40+
make
41+
sudo -E PATH=$PATH make install
42+
popd
43+
```
44+
45+
### Install cni plugin
46+
```sh
47+
go get github.com/containernetworking/plugins
48+
pushd $GOPATH/src/github.com/containernetworking/plugins
49+
./build_linux.sh
50+
mkdir /opt/cni
51+
cp -r bin /opt/cni/
52+
popd
53+
```
54+
55+
## Setup cni plugin
56+
```sh
57+
sudo mkdir -p /etc/cni/net.d
58+
cat >/etc/cni/net.d/10-mynet.conf <<EOF
59+
{
60+
"cniVersion": "0.2.0",
61+
"name": "mynet",
62+
"type": "bridge",
63+
"bridge": "cni0",
64+
"isGateway": true,
65+
"ipMasq": true,
66+
"ipam": {
67+
"type": "host-local",
68+
"subnet": "172.19.0.0/24",
69+
"routes": [
70+
{ "dst": "0.0.0.0/0" }
71+
]
72+
}
73+
}
74+
EOF
75+
```
76+
77+
## Setup containerd
78+
### create containerd configure file
79+
```sh
80+
sudo mkdir -p /etc/containerd/
81+
cat > /etc/containerd/config.toml <<EOF
82+
[plugins]
83+
[plugins.cri]
84+
sandbox_image = "mirrorgooglecontainers/pause-amd64:3.1"
85+
[plugins.cri.containerd]
86+
[plugins.cri.containerd.default_runtime]
87+
runtime_type = "io.containerd.kata.v2"
88+
[plugins.cri.cni]
89+
# conf_dir is the directory in which the admin places a CNI conf.
90+
conf_dir = "/etc/cni/net.d"
91+
EOF
92+
```
93+
94+
### create containerd systemd service
95+
```sh
96+
sudo cat > /etc/systemd/system/containerd.service <<EOF
97+
[Unit]
98+
Description=containerd container runtime
99+
Documentation=https://containerd.io
100+
After=network.target
101+
102+
[Service]
103+
ExecStartPre=/sbin/modprobe overlay
104+
ExecStart=/usr/local/bin/containerd --config /etc/containerd/config.toml
105+
Restart=always
106+
RestartSec=5
107+
Delegate=yes
108+
KillMode=process
109+
OOMScoreAdjust=-999
110+
LimitNOFILE=1048576
111+
# Having non-zero Limit*s causes performance problems due to accounting overhead
112+
# in the kernel. We recommend using cgroups to do container-local accounting.
113+
LimitNPROC=infinity
114+
LimitCORE=infinity
115+
116+
[Install]
117+
WantedBy=multi-user.target
118+
EOF
119+
```
120+
### start containerd
121+
```sh
122+
systemctl enable containerd
123+
systemctl start containerd
124+
```
125+
126+
## Run benchmark test
127+
```sh
128+
critest -benchmark --runtime-endpoint /run/containerd/containerd.sock
129+
```
130+
Then you will get some benchmark outputs as below on the screen
131+
```sh
132+
• [MEASUREMENT]
133+
[k8s.io] PodSandbox
134+
/root/gopath/src/github.com/kubernetes-sigs/cri-tools/pkg/framework/framework.go:72
135+
benchmark about operations on PodSandbox
136+
/root/gopath/src/github.com/kubernetes-sigs/cri-tools/pkg/benchmark/pod.go:41
137+
benchmark about lifecycle of PodSandbox
138+
/root/gopath/src/github.com/kubernetes-sigs/cri-tools/pkg/benchmark/pod.go:42
139+
140+
Ran 20 samples:
141+
create PodSandbox:
142+
Fastest Time: 2.234s
143+
Slowest Time: 2.625s
144+
Average Time: 2.499s ± 0.083s
145+
PodSandbox status:
146+
Fastest Time: 0.000s
147+
Slowest Time: 0.002s
148+
Average Time: 0.001s ± 0.000s
149+
stop PodSandbox:
150+
Fastest Time: 0.287s
151+
Slowest Time: 0.355s
152+
Average Time: 0.321s ± 0.019s
153+
remove PodSandbox:
154+
Fastest Time: 0.008s
155+
Slowest Time: 0.015s
156+
Average Time: 0.009s ± 0.002s
157+
158+
• [MEASUREMENT]
159+
[k8s.io] Container
160+
/root/gopath/src/github.com/kubernetes-sigs/cri-tools/pkg/framework/framework.go:72
161+
benchmark about operations on Container
162+
/root/gopath/src/github.com/kubernetes-sigs/cri-tools/pkg/benchmark/container.go:39
163+
benchmark about basic operations on Container
164+
/root/gopath/src/github.com/kubernetes-sigs/cri-tools/pkg/benchmark/container.go:54
165+
166+
Ran 20 samples:
167+
create Container:
168+
Fastest Time: 0.036s
169+
Slowest Time: 0.070s
170+
Average Time: 0.053s ± 0.010s
171+
start Container:
172+
Fastest Time: 0.144s
173+
Slowest Time: 0.222s
174+
Average Time: 0.165s ± 0.016s
175+
Container status:
176+
Fastest Time: 0.001s
177+
Slowest Time: 0.005s
178+
Average Time: 0.001s ± 0.001s
179+
stop Container:
180+
Fastest Time: 0.149s
181+
Slowest Time: 0.220s
182+
Average Time: 0.185s ± 0.019s
183+
remove Container:
184+
Fastest Time: 0.007s
185+
Slowest Time: 0.014s
186+
Average Time: 0.008s ± 0.001s
187+
188+
• [MEASUREMENT]
189+
[k8s.io] PodSandbox
190+
/root/gopath/src/github.com/kubernetes-sigs/cri-tools/pkg/framework/framework.go:72
191+
benchmark about start a container from scratch
192+
/root/gopath/src/github.com/kubernetes-sigs/cri-tools/pkg/benchmark/pod_container.go:47
193+
benchmark about start a container from scratch
194+
/root/gopath/src/github.com/kubernetes-sigs/cri-tools/pkg/benchmark/pod_container.go:48
195+
196+
Ran 20 samples:
197+
create PodSandbox and container:
198+
Fastest Time: 2.695s
199+
Slowest Time: 2.963s
200+
Average Time: 2.841s ± 0.067s
201+
202+
```

pkg/benchmark/pod_container.go

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package benchmark
18+
19+
import (
20+
"github.com/kubernetes-sigs/cri-tools/pkg/framework"
21+
internalapi "k8s.io/kubernetes/pkg/kubelet/apis/cri"
22+
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
23+
24+
. "github.com/onsi/ginkgo"
25+
. "github.com/onsi/gomega"
26+
)
27+
28+
var _ = framework.KubeDescribe("PodSandbox", func() {
29+
f := framework.NewDefaultCRIFramework()
30+
31+
var rc internalapi.RuntimeService
32+
var ic internalapi.ImageManagerService
33+
var podID string
34+
35+
BeforeEach(func() {
36+
rc = f.CRIClient.CRIRuntimeClient
37+
ic = f.CRIClient.CRIImageClient
38+
})
39+
40+
AfterEach(func() {
41+
By("stop PodSandbox")
42+
rc.StopPodSandbox(podID)
43+
By("delete PodSandbox")
44+
rc.RemovePodSandbox(podID)
45+
})
46+
47+
Context("benchmark about start a container from scratch", func() {
48+
Measure("benchmark about start a container from scratch", func(b Benchmarker) {
49+
var err error
50+
51+
podSandboxName := "PodSandbox-for-creating-pod-and-container-performance-test-" + framework.NewUUID()
52+
uid := framework.DefaultUIDPrefix + framework.NewUUID()
53+
namespace := framework.DefaultNamespacePrefix + framework.NewUUID()
54+
55+
config := &runtimeapi.PodSandboxConfig{
56+
Metadata: framework.BuildPodSandboxMetadata(podSandboxName, uid, namespace, framework.DefaultAttempt),
57+
Linux: &runtimeapi.LinuxPodSandboxConfig{},
58+
}
59+
60+
operation := b.Time("create PodSandbox and container", func() {
61+
By("run PodSandbox")
62+
podID, err = rc.RunPodSandbox(config, framework.TestContext.RuntimeHandler)
63+
framework.ExpectNoError(err, "failed to create PodSandbox: %v", err)
64+
By("create container in PodSandbox")
65+
containerID := framework.CreateDefaultContainer(rc, ic, podID, config, "Pod-Container-for-creating-benchmark-")
66+
By("start container in PodSandbox")
67+
err = rc.StartContainer(containerID)
68+
})
69+
70+
framework.ExpectNoError(err, "failed to start Container: %v", err)
71+
Expect(operation.Seconds()).Should(BeNumerically("<", 5), "create PodSandbox shouldn't take too long.")
72+
}, defaultOperationTimes)
73+
})
74+
})

0 commit comments

Comments
 (0)