Skip to content

Commit 8e82ec8

Browse files
committed
feat: add jailer performance tests
The test measures p50 and p90 of jailer startup time. It is parametrized by the number of jailers starting up and the number of bind mount points present in the system. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 2891c1e commit 8e82ec8

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Performance benchmark for the jailer."""
4+
5+
import os
6+
import shutil
7+
import subprocess
8+
9+
import pytest
10+
11+
from framework.jailer import DEFAULT_CHROOT_PATH, JailerContext
12+
from framework.properties import global_props
13+
14+
15+
@pytest.mark.nonci
16+
@pytest.mark.parametrize("jailers", [1, 100, 300, 500])
17+
@pytest.mark.parametrize("mounts", [0, 100, 300, 500])
18+
def test_jailer_startup(
19+
jailer_time_bin, tmp_path, microvm_factory, jailers, mounts, metrics
20+
):
21+
"""
22+
Test the overhead of jailer startup without and with bind mounts
23+
"""
24+
25+
jailer_binary = microvm_factory.jailer_binary_path
26+
27+
# Create bind mount points. The exact location of them
28+
# does not matter, they just need to exist.
29+
mounts_paths = tmp_path / "mounts"
30+
os.makedirs(mounts_paths)
31+
for m in range(mounts):
32+
mount_path = f"{mounts_paths}/mount{m}"
33+
os.makedirs(mount_path)
34+
subprocess.run(
35+
["mount", "--bind", f"{mount_path}", f"{mount_path}"], check=True
36+
)
37+
38+
metrics.set_dimensions(
39+
{
40+
"instance": global_props.instance,
41+
"cpu_model": global_props.cpu_model,
42+
"performance_test": "test_jailer_startup",
43+
"jailers": str(jailers),
44+
"mounts": str(mounts),
45+
}
46+
)
47+
48+
# Testing 1 jailer will give 1 data point which is not enough,
49+
# so do 100 runs in this case.
50+
if jailers == 1:
51+
iterations = 100
52+
else:
53+
iterations = 1
54+
55+
for i in range(iterations):
56+
processes = []
57+
for j in range(jailers):
58+
jailer = JailerContext(
59+
jailer_id=f"fakefc{i}{j}",
60+
exec_file=jailer_time_bin,
61+
# Don't deamonize to get the stdout
62+
daemonize=False,
63+
)
64+
jailer.setup()
65+
66+
cmd = [str(jailer_binary), *jailer.construct_param_list()]
67+
processes.append(
68+
subprocess.Popen(
69+
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False
70+
)
71+
)
72+
73+
for p in processes:
74+
r = p.communicate()[0]
75+
e, s = r.split()
76+
metrics.put_metric(
77+
"startup",
78+
int(e) - int(s),
79+
unit="Microseconds",
80+
)
81+
82+
# Cleanup mounts and jailer dirs
83+
for d in os.listdir(mounts_paths):
84+
subprocess.run(["umount", f"{mounts_paths}/{d}"], check=True)
85+
shutil.rmtree(DEFAULT_CHROOT_PATH)

0 commit comments

Comments
 (0)