From f18a8d3d7162e28de3e8f0931901da8f7c39192a Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Mon, 7 Sep 2026 14:33:45 +0000 Subject: [PATCH] Add nbd/nbdssl perf tests --- README.md | 3 +- tests/perf/test_compare.py | 56 ++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 0a3ac3e..e744979 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,8 @@ tox -e integration ``` Compare write/read throughput of openvixdisklib and native VDDK -(`64KiB`, 129-sector, and `32MiB` transfers): +(`64KiB`, 129-sector, and `32MiB` transfers; `nbdssl` and `nbd`; +plain and FastLZ): ```bash tox -e perf diff --git a/tests/perf/test_compare.py b/tests/perf/test_compare.py index ce47f22..edf187a 100644 --- a/tests/perf/test_compare.py +++ b/tests/perf/test_compare.py @@ -6,7 +6,7 @@ from __future__ import annotations import time -from typing import Any, Optional +from typing import Any from openvixdisklib import openvixdisklib as open_vix from tests.integration import vixdisklib @@ -19,18 +19,21 @@ _SIZES = ( ) -def _connect_extra(lab: LabEnv, module: Any) -> Optional[dict[str, Any]]: +def _connect_extra( + lab: LabEnv, module: Any, transport_mode: str) -> dict[str, Any]: """Return extra ``connect`` kwargs needed by ``module``.""" + extra: dict[str, Any] = {"transport_modes": transport_mode} if module is open_vix: - return {"allow_untrusted": lab.allow_untrusted} - return None + extra["allow_untrusted"] = lab.allow_untrusted + return extra def _time_write_read( lab: LabEnv, module: Any, payload: bytes, - flags: int = 0) -> tuple[float, float]: + flags: int = 0, + transport_mode: str = "nbdssl") -> tuple[float, float]: """Write ``payload`` at sector 0, read it back, and return durations.""" n_sectors = len(payload) // SECTOR_SIZE handle = module.VixDiskLibHandle( @@ -39,7 +42,8 @@ def _time_write_read( write_buf = module.get_buffer(len(payload)) read_buf = module.get_buffer(len(payload)) write_buf[:len(payload)] = payload - kwargs = lab.vixdisklib_connect_kwargs(_connect_extra(lab, module)) + kwargs = lab.vixdisklib_connect_kwargs( + _connect_extra(lab, module, transport_mode)) with handle.connect(**kwargs) as conn: with handle.open(conn, lab.disk_path, flags=flags) as disk: started = time.perf_counter() @@ -66,33 +70,39 @@ class TestCompare: ("vddk", vixdisklib), ("openvixdisklib", open_vix), ) + transports = ("nbdssl", "nbd") open_modes = ( ("plain", 0), ("fastlz", vixdisklib.VIXDISKLIB_FLAG_OPEN_COMPRESSION_FASTLZ), ) - rows: list[tuple[str, str, str, float, float, float, float]] = [] + rows: list[tuple[str, str, str, str, float, float, float, float]] = [] for label, nbytes in _SIZES: payload = pattern_bytes(nbytes, f"PERF-{label}-".encode()) - for mode_name, flags in open_modes: - for name, module in libraries: - write_s, read_s = _time_write_read( - lab, module, payload, flags=flags) - rows.append(( - label, - mode_name, - name, - write_s, - read_s, - _mib_per_s(nbytes, write_s), - _mib_per_s(nbytes, read_s), - )) + for transport_mode in transports: + for mode_name, flags in open_modes: + for name, module in libraries: + write_s, read_s = _time_write_read( + lab, module, payload, flags=flags, + transport_mode=transport_mode) + rows.append(( + label, + transport_mode, + mode_name, + name, + write_s, + read_s, + _mib_per_s(nbytes, write_s), + _mib_per_s(nbytes, read_s), + )) print() print( - f"{'size':<14} {'flags':<8} {'library':<16} " + f"{'size':<14} {'transport':<10} {'flags':<8} {'library':<16} " f"{'write_s':>10} {'read_s':>10} " f"{'write_MiB/s':>12} {'read_MiB/s':>12}") - for label, mode_name, name, write_s, read_s, write_r, read_r in rows: + for ( + label, transport_mode, mode_name, name, + write_s, read_s, write_r, read_r) in rows: print( - f"{label:<14} {mode_name:<8} {name:<16} " + f"{label:<14} {transport_mode:<10} {mode_name:<8} {name:<16} " f"{write_s:10.3f} {read_s:10.3f} " f"{write_r:12.1f} {read_r:12.1f}")