Skip to content

Commit dd69210

Browse files
authored
Merge pull request #419 from lifupan/kata_support
add a benchmark testcase for measuring the time of creating pod and a container
2 parents bbd67db + 42cb1cf commit dd69210

File tree

3 files changed

+81
-7
lines changed

3 files changed

+81
-7
lines changed

pkg/benchmark/container.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ var _ = framework.KubeDescribe("Container", func() {
9696
}, defaultOperationTimes)
9797

9898
Measure("benchmark about listing Container", func(b Benchmarker) {
99-
containerList := make([]string, framework.TestContext.Number)
99+
containerList := make([]string, 0, framework.TestContext.Number)
100100
var err error
101101

102102
for i := 0; i < framework.TestContext.Number; i++ {

pkg/benchmark/pod.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,32 +58,32 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
5858
})
5959

6060
framework.ExpectNoError(err, "failed to create PodSandbox: %v", err)
61-
Expect(operation.Seconds()).Should(BeNumerically("<", 2), "create PodSandbox shouldn't take too long.")
61+
Expect(operation.Seconds()).Should(BeNumerically("<", 5), "create PodSandbox shouldn't take too long.")
6262

6363
operation = b.Time("PodSandbox status", func() {
6464
_, err = c.PodSandboxStatus(podID)
6565
})
6666

6767
framework.ExpectNoError(err, "failed to get PodSandbox status: %v", err)
68-
Expect(operation.Seconds()).Should(BeNumerically("<", 2), "get PodSandbox status shouldn't take too long.")
68+
Expect(operation.Seconds()).Should(BeNumerically("<", 5), "get PodSandbox status shouldn't take too long.")
6969

7070
operation = b.Time("stop PodSandbox", func() {
7171
err = c.StopPodSandbox(podID)
7272
})
7373

7474
framework.ExpectNoError(err, "failed to stop PodSandbox: %v", err)
75-
Expect(operation.Seconds()).Should(BeNumerically("<", 2), "stop PodSandbox shouldn't take too long.")
75+
Expect(operation.Seconds()).Should(BeNumerically("<", 5), "stop PodSandbox shouldn't take too long.")
7676

7777
operation = b.Time("remove PodSandbox", func() {
7878
c.RemovePodSandbox(podID)
7979
})
8080

8181
framework.ExpectNoError(err, "failed to remove PodSandbox: %v", err)
82-
Expect(operation.Seconds()).Should(BeNumerically("<", 2), "remove PodSandbox shouldn't take too long.")
82+
Expect(operation.Seconds()).Should(BeNumerically("<", 5), "remove PodSandbox shouldn't take too long.")
8383
}, defaultOperationTimes)
8484

8585
Measure("benchmark about listing PodSandbox", func(b Benchmarker) {
86-
podList := make([]string, framework.TestContext.Number)
86+
podList := make([]string, 0, framework.TestContext.Number)
8787
var err error
8888

8989
for i := 0; i < framework.TestContext.Number; i++ {
@@ -96,7 +96,7 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
9696
})
9797

9898
framework.ExpectNoError(err, "failed to list PodSandbox: %v", err)
99-
Expect(operation.Seconds()).Should(BeNumerically("<", 2), "list PodSandbox shouldn't take too long.")
99+
Expect(operation.Seconds()).Should(BeNumerically("<", 5), "list PodSandbox shouldn't take too long.")
100100

101101
for _, podID := range podList {
102102
c.StopPodSandbox(podID)

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)