Add nbd/nbdssl perf tests

This commit is contained in:
Lucian Petrut
2026-09-07 14:33:45 +00:00
parent b11e109ec5
commit f18a8d3d71
2 changed files with 35 additions and 24 deletions
+2 -1
View File
@@ -99,7 +99,8 @@ tox -e integration
``` ```
Compare write/read throughput of openvixdisklib and native VDDK 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 ```bash
tox -e perf tox -e perf
+33 -23
View File
@@ -6,7 +6,7 @@
from __future__ import annotations from __future__ import annotations
import time import time
from typing import Any, Optional from typing import Any
from openvixdisklib import openvixdisklib as open_vix from openvixdisklib import openvixdisklib as open_vix
from tests.integration import vixdisklib 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``.""" """Return extra ``connect`` kwargs needed by ``module``."""
extra: dict[str, Any] = {"transport_modes": transport_mode}
if module is open_vix: if module is open_vix:
return {"allow_untrusted": lab.allow_untrusted} extra["allow_untrusted"] = lab.allow_untrusted
return None return extra
def _time_write_read( def _time_write_read(
lab: LabEnv, lab: LabEnv,
module: Any, module: Any,
payload: bytes, 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.""" """Write ``payload`` at sector 0, read it back, and return durations."""
n_sectors = len(payload) // SECTOR_SIZE n_sectors = len(payload) // SECTOR_SIZE
handle = module.VixDiskLibHandle( handle = module.VixDiskLibHandle(
@@ -39,7 +42,8 @@ def _time_write_read(
write_buf = module.get_buffer(len(payload)) write_buf = module.get_buffer(len(payload))
read_buf = module.get_buffer(len(payload)) read_buf = module.get_buffer(len(payload))
write_buf[:len(payload)] = 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.connect(**kwargs) as conn:
with handle.open(conn, lab.disk_path, flags=flags) as disk: with handle.open(conn, lab.disk_path, flags=flags) as disk:
started = time.perf_counter() started = time.perf_counter()
@@ -66,33 +70,39 @@ class TestCompare:
("vddk", vixdisklib), ("vddk", vixdisklib),
("openvixdisklib", open_vix), ("openvixdisklib", open_vix),
) )
transports = ("nbdssl", "nbd")
open_modes = ( open_modes = (
("plain", 0), ("plain", 0),
("fastlz", vixdisklib.VIXDISKLIB_FLAG_OPEN_COMPRESSION_FASTLZ), ("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: for label, nbytes in _SIZES:
payload = pattern_bytes(nbytes, f"PERF-{label}-".encode()) payload = pattern_bytes(nbytes, f"PERF-{label}-".encode())
for mode_name, flags in open_modes: for transport_mode in transports:
for name, module in libraries: for mode_name, flags in open_modes:
write_s, read_s = _time_write_read( for name, module in libraries:
lab, module, payload, flags=flags) write_s, read_s = _time_write_read(
rows.append(( lab, module, payload, flags=flags,
label, transport_mode=transport_mode)
mode_name, rows.append((
name, label,
write_s, transport_mode,
read_s, mode_name,
_mib_per_s(nbytes, write_s), name,
_mib_per_s(nbytes, read_s), write_s,
)) read_s,
_mib_per_s(nbytes, write_s),
_mib_per_s(nbytes, read_s),
))
print() print()
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_s':>10} {'read_s':>10} "
f"{'write_MiB/s':>12} {'read_MiB/s':>12}") 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( 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_s:10.3f} {read_s:10.3f} "
f"{write_r:12.1f} {read_r:12.1f}") f"{write_r:12.1f} {read_r:12.1f}")