Skip to content

Commit ace03d7

Browse files
committed
Benchmark a paralell VM launch case
It should be slower, and it is. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 635545d commit ace03d7

File tree

1 file changed

+60
-17
lines changed

1 file changed

+60
-17
lines changed

runtime/benchmark_test.go

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package main
1616
import (
1717
"context"
1818
"testing"
19+
"time"
1920

2021
"github.com/containerd/containerd"
2122
"github.com/containerd/containerd/namespaces"
@@ -26,7 +27,32 @@ import (
2627
"github.com/stretchr/testify/require"
2728
)
2829

29-
func benchmarkCreateAndStopVM(b *testing.B, vcpuCount uint32, kernelArgs string) {
30+
func createAndStopVM(
31+
ctx context.Context,
32+
fcClient fccontrol.FirecrackerService,
33+
request proto.CreateVMRequest,
34+
) error {
35+
uuid, err := uuid.NewV4()
36+
if err != nil {
37+
return err
38+
}
39+
40+
request.VMID = uuid.String()
41+
42+
_, err = fcClient.CreateVM(ctx, &request)
43+
if err != nil {
44+
return err
45+
}
46+
47+
_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: request.VMID})
48+
if err != nil {
49+
return err
50+
}
51+
52+
return nil
53+
}
54+
55+
func benchmarkCreateAndStopVM(b *testing.B, vcpuCount uint32, kernelArgs string, parallel int) {
3056
require := require.New(b)
3157

3258
client, err := containerd.New(containerdSockPath, containerd.WithDefaultRuntime(firecrackerRuntime))
@@ -39,34 +65,46 @@ func benchmarkCreateAndStopVM(b *testing.B, vcpuCount uint32, kernelArgs string)
3965
require.NoError(err, "failed to create ttrpc client")
4066

4167
fcClient := fccontrol.NewFirecrackerClient(pluginClient.Client())
68+
request := proto.CreateVMRequest{
69+
KernelArgs: kernelArgs,
70+
MachineCfg: &proto.FirecrackerMachineConfiguration{
71+
VcpuCount: vcpuCount,
72+
},
73+
}
4274

43-
for i := 0; i < b.N; i++ {
44-
uuid, err := uuid.NewV4()
45-
require.NoError(err)
75+
ch := make(chan error, parallel)
76+
for i := 0; i < parallel; i++ {
77+
go func() {
78+
var err error
79+
defer func() {
80+
ch <- err
81+
}()
4682

47-
vmID := uuid.String()
83+
for i := 0; i < b.N; i++ {
84+
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
85+
defer cancel()
4886

49-
_, err = fcClient.CreateVM(ctx, &proto.CreateVMRequest{
50-
VMID: vmID,
51-
KernelArgs: kernelArgs,
52-
MachineCfg: &proto.FirecrackerMachineConfiguration{
53-
VcpuCount: vcpuCount,
54-
},
55-
})
56-
require.NoError(err)
87+
err = createAndStopVM(ctx, fcClient, request)
88+
if err != nil {
89+
return
90+
}
91+
}
92+
}()
93+
}
5794

58-
_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: vmID})
59-
require.NoError(err)
95+
// Make sure all goroutines are finished successfully.
96+
for i := 0; i < parallel; i++ {
97+
require.NoError(<-ch)
6098
}
6199
}
62100

63101
func BenchmarkCreateAndStopVM_Vcpu1_Isolated(b *testing.B) {
64102
prepareIntegTest(b)
65-
benchmarkCreateAndStopVM(b, 1, defaultRuntimeConfig.KernelArgs)
103+
benchmarkCreateAndStopVM(b, 1, defaultRuntimeConfig.KernelArgs, 1)
66104
}
67105
func BenchmarkCreateAndStopVM_Vcpu5_Isolated(b *testing.B) {
68106
prepareIntegTest(b)
69-
benchmarkCreateAndStopVM(b, 5, defaultRuntimeConfig.KernelArgs)
107+
benchmarkCreateAndStopVM(b, 5, defaultRuntimeConfig.KernelArgs, 1)
70108
}
71109

72110
func BenchmarkCreateAndStopVM_Quiet_Isolated(b *testing.B) {
@@ -76,5 +114,10 @@ func BenchmarkCreateAndStopVM_Quiet_Isolated(b *testing.B) {
76114
1,
77115
// Same as https://github.com/firecracker-microvm/firecracker-demo/blob/c22499567b63b4edd85e19ca9b0e9fa398b3300b/start-firecracker.sh#L9
78116
"ro noapic reboot=k panic=1 pci=off nomodules systemd.log_color=false systemd.unit=firecracker.target init=/sbin/overlay-init tsc=reliable quiet 8250.nr_uarts=0 ipv6.disable=1",
117+
1,
79118
)
80119
}
120+
func BenchmarkCreateAndStopVM_Parallel10_Isolated(b *testing.B) {
121+
prepareIntegTest(b)
122+
benchmarkCreateAndStopVM(b, 1, defaultRuntimeConfig.KernelArgs, 10)
123+
}

0 commit comments

Comments
 (0)