Skip to content

Commit ab8df46

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 585fee5 commit ab8df46

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

0 commit comments

Comments
 (0)