-
Notifications
You must be signed in to change notification settings - Fork 2k
Measure jailer startup performance #5282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ShadowCurse
wants to merge
6
commits into
firecracker-microvm:main
Choose a base branch
from
ShadowCurse:jailer_tweaks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
735687f
feat(jailer): remove requirement for an executable name
ShadowCurse 0f38378
feat(jailer): check if executable has exec permissions
ShadowCurse 2247cc9
chore: add note to CHANGELOG
ShadowCurse 38e7741
feat(jailer): remove panic on errors
ShadowCurse ce24d23
feat: add jailer_time binary for jailer perf tests
ShadowCurse 9e5b112
feat: add jailer performance tests
ShadowCurse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// This is used by `performance/test_jailer.py` | ||
|
||
#include <stdio.h> | ||
#include <time.h> | ||
|
||
int main(int argc, char** argv) { | ||
// print current time in us | ||
struct timespec now = {0}; | ||
clock_gettime(CLOCK_MONOTONIC, &now); | ||
unsigned long long current_ns = (unsigned long long)now.tv_sec * 1000000000 + (unsigned long long)now.tv_nsec; | ||
unsigned long long current_us = current_ns / 1000; | ||
printf("%llu\n", current_us); | ||
|
||
// print the --start-time-us value | ||
printf("%s", argv[4]); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
"""Performance benchmark for the jailer.""" | ||
|
||
import os | ||
import shutil | ||
import subprocess | ||
|
||
import pytest | ||
|
||
from framework.jailer import DEFAULT_CHROOT_PATH, JailerContext | ||
|
||
|
||
@pytest.mark.nonci | ||
@pytest.mark.parametrize("jailers", [1, 100, 300, 500]) | ||
@pytest.mark.parametrize("mounts", [0, 100, 300, 500]) | ||
def test_jailer_startup(jailer_time_bin, microvm_factory, jailers, mounts, metrics): | ||
""" | ||
Test the overhead of jailer startup without and with bind mounts | ||
""" | ||
|
||
jailer_binary = microvm_factory.jailer_binary_path | ||
|
||
# Create bind mount points. The exact location of them | ||
# does not matter, they just need to exist. | ||
mounts_paths = "/tmp/mounts" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't really matter as perf tests are run sequentially, but you could use a tempdir from |
||
os.makedirs(mounts_paths) | ||
for m in range(mounts): | ||
mount_path = f"{mounts_paths}/mount{m}" | ||
os.makedirs(mount_path) | ||
subprocess.run( | ||
["mount", "--bind", f"{mount_path}", f"{mount_path}"], check=True | ||
) | ||
|
||
metrics.set_dimensions( | ||
{ | ||
"performance_test": "test_boottime", | ||
"jailers": jailers, | ||
"mounts": mounts, | ||
} | ||
) | ||
|
||
# Testing 1 jailer will give 1 data point which is not enough, | ||
# so do 100 runs in this case. | ||
if jailers == 1: | ||
iterations = 100 | ||
else: | ||
iterations = 1 | ||
|
||
for i in range(iterations): | ||
processes = [] | ||
for j in range(jailers): | ||
jailer = JailerContext( | ||
jailer_id=f"fakefc{i}{j}", | ||
exec_file=jailer_time_bin, | ||
# Don't deamonize to get the stdout | ||
daemonize=False, | ||
) | ||
jailer.setup() | ||
|
||
cmd = [str(jailer_binary), *jailer.construct_param_list()] | ||
processes.append( | ||
subprocess.Popen( | ||
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False | ||
) | ||
) | ||
|
||
for p in processes: | ||
r = p.communicate()[0] | ||
e, s = r.split() | ||
metrics.put_metric( | ||
"startup", | ||
int(e) - int(s), | ||
unit="Microseconds", | ||
) | ||
|
||
# Cleanup mounts and jailer dirs | ||
for d in os.listdir(mounts_paths): | ||
subprocess.run(["umount", f"{mounts_paths}/{d}"], check=True) | ||
shutil.rmtree(mounts_paths) | ||
shutil.rmtree(DEFAULT_CHROOT_PATH) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this requiring that's executable by all users, while in reality it just needs to be executable by the jailer? Is there any issues with just having the
execve
fail with permission error?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This checks that there is at
least some
executable bit set.Personally, I added this as I though it was already a requirement, just not explicitly checked and failing with a bit nicer message is better. I can drop it if people find it not necessary.