Skip to content

Commit dc8fb2f

Browse files
committed
test: add post-restore latency test
Add a snapshot latency test that output metrics on how long it takes to memset a 128MB memory region post-snapshot restore. We only collect these latencies for a single configuration (1024MB, 2vCPU), since they will be the same no matter the size of the memory. Signed-off-by: Patrick Roy <[email protected]>
1 parent b94a365 commit dc8fb2f

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tests/integration_tests/performance/test_snapshot_ab.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
"""Performance benchmark for snapshot restore."""
4+
import signal
45
import tempfile
6+
import time
57
from dataclasses import dataclass
68
from functools import lru_cache
79

@@ -11,6 +13,7 @@
1113
from framework.microvm import Microvm
1214

1315
USEC_IN_MSEC = 1000
16+
NS_IN_MSEC = 1_000_000
1417
ITERATIONS = 30
1518

1619

@@ -88,7 +91,7 @@ def configure_vm(self, microvm_factory, guest_kernel, rootfs, metrics) -> Microv
8891
"test_setup",
8992
[
9093
SnapshotRestoreTest(mem=128, vcpus=1),
91-
SnapshotRestoreTest(mem=1024, vcpus=1),
94+
SnapshotRestoreTest(mem=1024, vcpus=2),
9295
SnapshotRestoreTest(mem=2048, vcpus=2),
9396
SnapshotRestoreTest(mem=4096, vcpus=3),
9497
SnapshotRestoreTest(mem=6144, vcpus=4),
@@ -128,3 +131,38 @@ def test_restore_latency(
128131
break
129132
assert value > 0
130133
metrics.put_metric("latency", value, "Milliseconds")
134+
135+
136+
@pytest.mark.nonci
137+
@pytest.mark.parametrize("uffd_handler", [None, "valid"])
138+
def test_post_restore_latency(
139+
microvm_factory, rootfs, guest_kernel_linux_5_10, metrics, uffd_handler
140+
):
141+
"""Collects latency metric of post-restore memory accesses done inside the guest"""
142+
test_setup = SnapshotRestoreTest(mem=1024, vcpus=2)
143+
vm = test_setup.configure_vm(
144+
microvm_factory, guest_kernel_linux_5_10, rootfs, metrics
145+
)
146+
147+
vm.ssh.check_output(
148+
"nohup /usr/local/bin/fast_page_fault_helper >/dev/null 2>&1 </dev/null &"
149+
)
150+
151+
# Give helper time to initialize
152+
time.sleep(5)
153+
154+
snapshot = vm.snapshot_full()
155+
vm.kill()
156+
157+
for microvm in microvm_factory.build_n_from_snapshot(
158+
snapshot, ITERATIONS, uffd_handler_name=uffd_handler
159+
):
160+
_, pid, _ = microvm.ssh.check_output("pidof fast_page_fault_helper")
161+
162+
microvm.ssh.check_output(f"kill -s {signal.SIGUSR1} {pid}")
163+
164+
_, duration, _ = microvm.ssh.check_output(
165+
"while [ ! -f /tmp/fast_page_fault_helper.out ]; do sleep 1; done; cat /tmp/fast_page_fault_helper.out"
166+
)
167+
168+
metrics.put_metric("fault_latency", int(duration) / NS_IN_MSEC, "Milliseconds")

0 commit comments

Comments
 (0)