Skip to content

Commit 0b5d3aa

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 <yegorlz@amazon.co.uk>
1 parent 67ae67f commit 0b5d3aa

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 numpy as np
10+
import pytest
11+
12+
from framework.jailer import DEFAULT_CHROOT_PATH, JailerContext
13+
14+
15+
@pytest.mark.nonci
16+
@pytest.mark.parametrize("jailers", [1, 100, 200, 300, 400])
17+
@pytest.mark.parametrize("mounts", [0, 100, 300, 500])
18+
def test_jailer_startup(jailer_time_bin, microvm_factory, jailers, mounts, metrics):
19+
"""
20+
Test the overhead of jailer startup without and with bind mounts
21+
"""
22+
23+
jailer_binary = microvm_factory.jailer_binary_path
24+
25+
# Create bind mount points. The exact location of them
26+
# does not matter, they just need to exist.
27+
mounts_paths = "/tmp/mounts"
28+
os.makedirs(mounts_paths)
29+
for m in range(mounts):
30+
mount_path = f"{mounts_paths}/mount{m}"
31+
os.makedirs(mount_path)
32+
subprocess.run(
33+
["mount", "--bind", f"{mount_path}", f"{mount_path}"], check=True
34+
)
35+
36+
processes = []
37+
for i in range(jailers):
38+
jailer = JailerContext(
39+
jailer_id=f"fakefc{i}",
40+
exec_file=jailer_time_bin,
41+
# Don't deamonize to get the stdout
42+
daemonize=False,
43+
)
44+
jailer.setup()
45+
46+
cmd = [str(jailer_binary), *jailer.construct_param_list()]
47+
processes.append(
48+
subprocess.Popen(
49+
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False
50+
)
51+
)
52+
53+
deltas = []
54+
for i, p in enumerate(processes):
55+
r = p.communicate()[0]
56+
e, s = r.split()
57+
deltas.append(int(e) - int(s))
58+
59+
p50 = np.percentile(deltas, 50)
60+
p90 = np.percentile(deltas, 90)
61+
62+
metrics.set_dimensions(
63+
{
64+
"performance_test": "test_boottime",
65+
"jailers": jailers,
66+
"mounts": mounts,
67+
}
68+
)
69+
metrics.put_metric(
70+
"p50",
71+
p50,
72+
unit="Microseconds",
73+
)
74+
metrics.put_metric(
75+
"p90",
76+
p90,
77+
unit="Microseconds",
78+
)
79+
80+
# Cleanup mounts and jailer dirs
81+
for d in os.listdir(mounts_paths):
82+
subprocess.run(["umount", f"{mounts_paths}/{d}"], check=True)
83+
shutil.rmtree(mounts_paths)
84+
shutil.rmtree(DEFAULT_CHROOT_PATH)

0 commit comments

Comments
 (0)