Skip to content

Commit f654000

Browse files
authored
Merge pull request #117 from nirs/perf
Improve performance test
2 parents faa2f74 + 35e34e8 commit f654000

File tree

3 files changed

+208
-52
lines changed

3 files changed

+208
-52
lines changed

test/README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Testing socket_vmnet
2+
3+
## Performance testing
4+
5+
You can run performance tests using the perf.sh script.
6+
7+
```console
8+
% test/perf.sh
9+
Usage test/perf.sh command [options]
10+
11+
Commands:
12+
create create test vms
13+
delete delete test vms
14+
run run benchmarks
15+
16+
Options:
17+
-c COUNT number of vms
18+
-t SECONDS time in seconds to transmit for (default 30)
19+
-v VM_TYPE lima vmType [vz, qemu] (default vz)
20+
-b IFACE if set, use lima bridged network with IFACE
21+
-o OUT_DIR output directory (default perf.out)
22+
```
23+
24+
### Example run
25+
26+
Create test vms:
27+
28+
```console
29+
test/perf.sh create -c 3 2>perf.log
30+
```
31+
32+
Run all tests with shared and bridged modes, vz and qemu vm type,
33+
using 1, 2, and 3 vms:
34+
35+
```
36+
for v in vz qemu; do
37+
for c in $(seq 3); do
38+
test/perf.sh run -c $c -v $v 2>>perf.log
39+
test/perf.sh run -c $c -v $v -b en10 2>>perf.log
40+
done
41+
done
42+
```
43+
44+
Delete the test vms:
45+
46+
```console
47+
test/perf.sh delete -c 3 2>>perf.log
48+
```
49+
50+
This creates the following results:
51+
52+
```console
53+
% tree test/perf.out
54+
test/perf.out
55+
├── bridged-qemu-1
56+
│   ├── host-to-vm.json
57+
│   └── vm-to-host.json
58+
├── bridged-qemu-2
59+
│   ├── host-to-vm.json
60+
│   ├── vm-to-host.json
61+
│   └── vm-to-vm.json
62+
├── bridged-qemu-3
63+
│   ├── host-to-vm.json
64+
│   ├── vm-to-host.json
65+
│   └── vm-to-vm.json
66+
...
67+
```
68+
69+
You can create reports like this:
70+
71+
```console
72+
% for c in 1 2 3; do
73+
result="test/perf.out/shared-vz-$c/host-to-vm.json"
74+
gbits_per_second=$(jq -r '.end.sum_received.bits_per_second / 1000000000' < "$result")
75+
printf "%d vms: %.2f Gbits/s\n" $c $gbits_per_second
76+
done
77+
1 vms: 2.35 Gbits/s
78+
2 vms: 1.83 Gbits/s
79+
3 vms: 1.15 Gbits/s
80+
```

test/lima.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ images:
44
- location: "https://cloud-images.ubuntu.com/releases/24.10/release/ubuntu-24.10-server-cloudimg-arm64.img"
55
arch: "aarch64"
66
cpus: 1
7-
memory: "2g"
7+
memory: "1g"
88
plain: true
99
networks:
1010
- socket: /var/run/socket_vmnet

test/perf.sh

Lines changed: 127 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,152 @@
11
#!/bin/bash
2+
23
set -e
3-
cd "$(dirname "$0")"
4+
set -o pipefail
45

5-
TIME=${2:-30}
6+
cd "$(dirname "$0")"
67

78
server_address() {
8-
limactl shell server ip -j -4 addr show dev lima0 | jq -r '.[0].addr_info[0].local'
9+
limactl shell perf1 ip -j -4 addr show dev lima0 | jq -r '.[0].addr_info[0].local'
910
}
1011

1112
create() {
12-
limactl create --name server --tty=false lima.yaml &
13-
limactl create --name client --tty=false lima.yaml &
13+
echo "[perf] Creating $count vms"
14+
for i in $(seq $count); do
15+
limactl create --name perf$i --tty=false lima.yaml &
16+
done
1417
wait
1518
}
1619

17-
host-to-vm() {
18-
limactl start server
19-
limactl shell server sudo systemctl start iperf3.service
20-
iperf3-darwin --client $(server_address) --time $TIME
21-
limactl stop server
20+
delete() {
21+
echo "[perf] Delete $count vms"
22+
for i in $(seq $count); do
23+
limactl delete -f perf$i
24+
done
2225
}
2326

24-
host-to-vm-2() {
25-
limactl start server &
26-
limactl start client &
27-
wait
28-
limactl shell server sudo systemctl start iperf3.service
29-
iperf3-darwin --client $(server_address) --time $TIME
30-
limactl stop server
31-
limactl stop client
27+
run() {
28+
echo "[perf] Updating vms"
29+
update_vms
30+
31+
echo "[perf] Starting vms"
32+
start_vms
33+
34+
echo "[perf] Starting iperf3 service"
35+
limactl shell perf1 sudo systemctl start iperf3.service >>perf.log
36+
37+
config="$out_dir/$mode-$vm_type-$count"
38+
mkdir -p "$config"
39+
addr=$(server_address)
40+
41+
echo "[perf] Running $config/host-to-vm"
42+
iperf3-darwin --client $addr --time $time --json > "$config/host-to-vm.json"
43+
44+
echo "[perf] Running $config/vm-to-host"
45+
iperf3-darwin --client $addr --time $time --reverse --json > "$config/vm-to-host.json"
46+
47+
if [ $count -gt 1 ]; then
48+
echo "[perf] Running $config/vm-to-vm"
49+
limactl shell perf2 iperf3 --client $addr --time $time --json > "$config/vm-to-vm.json"
50+
fi
51+
52+
echo "[perf] Stopping vms"
53+
stop_vms
54+
}
55+
56+
update_vms() {
57+
socket="/var/run/socket_vmnet"
58+
if [ "$mode" = "bridged" ]; then
59+
socket+=".bridged.$iface"
60+
fi
61+
for i in $(seq $count); do
62+
limactl edit perf$i --tty=false \
63+
--set ".vmType = \"$vm_type\" | .networks[0].socket = \"$socket\""
64+
done
3265
}
3366

34-
vm-to-vm() {
35-
limactl start server &
36-
limactl start client &
67+
start_vms() {
68+
for i in $(seq $count); do
69+
limactl start perf$i &
70+
done
3771
wait
38-
limactl shell server sudo systemctl start iperf3.service
39-
addr=$(server_address)
40-
limactl shell client iperf3 --client $addr --time $TIME
41-
limactl stop server
42-
limactl stop client
4372
}
4473

45-
delete() {
46-
limactl delete -f server
47-
limactl delete -f client
74+
stop_vms() {
75+
for i in $(seq $count); do
76+
limactl stop perf$i
77+
done
78+
}
79+
80+
usage() {
81+
echo "Usage $0 command [options]"
82+
echo
83+
echo "Commands:"
84+
echo " create create test vms"
85+
echo " delete delete test vms"
86+
echo " run run benchmarks"
87+
echo
88+
echo "Options:"
89+
echo " -c COUNT number of vms"
90+
echo " -t SECONDS time in seconds to transmit for (default 30)"
91+
echo " -v VM_TYPE lima vmType [vz, qemu] (default vz)"
92+
echo " -b IFACE if set, use lima bridged network with IFACE"
93+
echo " -o OUT_DIR output directory (default perf.out)"
4894
}
4995

96+
# Defaults
97+
count=2
98+
time=30
99+
vm_type=vz
100+
mode=shared
101+
iface=
102+
out_dir=perf.out
103+
50104
case $1 in
51-
create)
52-
create
53-
;;
54-
host-to-vm)
55-
host-to-vm
56-
;;
57-
host-to-vm-2)
58-
host-to-vm-2
59-
;;
60-
vm-to-vm)
61-
vm-to-vm
62-
;;
63-
delete)
64-
delete
105+
create|delete|run)
106+
command=$1
107+
shift
65108
;;
66109
*)
67-
echo "Usage $0 command"
68-
echo
69-
echo "Available commands:"
70-
echo " create create test vms"
71-
echo " delete delete test vms"
72-
echo " host-to-vm [TIME] test host to vm performance"
73-
echo " host-to-vm-2 [TIME] test host to vm performance with 1 extra vm"
74-
echo " vm-to-vm [TIME] test vm to vm performance"
110+
usage
111+
exit 1
75112
;;
76113
esac
114+
115+
args=$(getopt c:t:v:b:o: $*)
116+
if [ $? -ne 0 ]; then
117+
usage
118+
exit 1
119+
fi
120+
121+
set -- $args
122+
123+
while :; do
124+
case $1 in
125+
-c)
126+
count=$2
127+
shift; shift
128+
;;
129+
-t)
130+
time=$2
131+
shift; shift
132+
;;
133+
-v)
134+
vm_type="$2"
135+
shift; shift
136+
;;
137+
-b)
138+
mode=bridged
139+
iface="$2"
140+
shift; shift
141+
;;
142+
-o)
143+
out_dir="$2"
144+
shift; shift
145+
;;
146+
--)
147+
shift; break;
148+
;;
149+
esac
150+
done
151+
152+
$command

0 commit comments

Comments
 (0)