Skip to content

Commit 73d7560

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 73d7560

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

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)