@@ -16,6 +16,7 @@ package main
16
16
import (
17
17
"context"
18
18
"testing"
19
+ "time"
19
20
20
21
"github.com/containerd/containerd"
21
22
"github.com/containerd/containerd/namespaces"
@@ -26,7 +27,32 @@ import (
26
27
"github.com/stretchr/testify/require"
27
28
)
28
29
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 ) {
30
56
require := require .New (b )
31
57
32
58
client , err := containerd .New (containerdSockPath , containerd .WithDefaultRuntime (firecrackerRuntime ))
@@ -39,34 +65,46 @@ func benchmarkCreateAndStopVM(b *testing.B, vcpuCount uint32, kernelArgs string)
39
65
require .NoError (err , "failed to create ttrpc client" )
40
66
41
67
fcClient := fccontrol .NewFirecrackerClient (pluginClient .Client ())
68
+ request := proto.CreateVMRequest {
69
+ KernelArgs : kernelArgs ,
70
+ MachineCfg : & proto.FirecrackerMachineConfiguration {
71
+ VcpuCount : vcpuCount ,
72
+ },
73
+ }
42
74
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
+ }()
46
82
47
- vmID := uuid .String ()
83
+ for i := 0 ; i < b .N ; i ++ {
84
+ ctx , cancel := context .WithTimeout (ctx , 5 * time .Second )
85
+ defer cancel ()
48
86
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
+ }
57
94
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 )
60
98
}
61
99
}
62
100
63
101
func BenchmarkCreateAndStopVM_Vcpu1_Isolated (b * testing.B ) {
64
102
prepareIntegTest (b )
65
- benchmarkCreateAndStopVM (b , 1 , defaultRuntimeConfig .KernelArgs )
103
+ benchmarkCreateAndStopVM (b , 1 , defaultRuntimeConfig .KernelArgs , 1 )
66
104
}
67
105
func BenchmarkCreateAndStopVM_Vcpu5_Isolated (b * testing.B ) {
68
106
prepareIntegTest (b )
69
- benchmarkCreateAndStopVM (b , 5 , defaultRuntimeConfig .KernelArgs )
107
+ benchmarkCreateAndStopVM (b , 5 , defaultRuntimeConfig .KernelArgs , 1 )
70
108
}
71
109
72
110
func BenchmarkCreateAndStopVM_Quiet_Isolated (b * testing.B ) {
@@ -76,5 +114,10 @@ func BenchmarkCreateAndStopVM_Quiet_Isolated(b *testing.B) {
76
114
1 ,
77
115
// Same as https://github.com/firecracker-microvm/firecracker-demo/blob/c22499567b63b4edd85e19ca9b0e9fa398b3300b/start-firecracker.sh#L9
78
116
"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 ,
79
118
)
80
119
}
120
+ func BenchmarkCreateAndStopVM_Parallel10_Isolated (b * testing.B ) {
121
+ prepareIntegTest (b )
122
+ benchmarkCreateAndStopVM (b , 1 , defaultRuntimeConfig .KernelArgs , 10 )
123
+ }
0 commit comments