Skip to content

Commit 9381fbd

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 9381fbd

File tree

2 files changed

+280
-0
lines changed

2 files changed

+280
-0
lines changed

pkg/benchmark/README.md

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

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)