Smallest possible benchmark result tracking.

This commit is contained in:
Itamar Turner-Trauring 2023-09-05 12:23:50 -04:00
parent 31624019be
commit c88c241f5c
2 changed files with 45 additions and 16 deletions

View File

@ -9,6 +9,8 @@ from os.path import abspath
from shutil import which, rmtree from shutil import which, rmtree
from tempfile import mkdtemp from tempfile import mkdtemp
from pathlib import Path from pathlib import Path
from contextlib import contextmanager
from time import time
import pytest import pytest
import pytest_twisted import pytest_twisted
@ -105,3 +107,22 @@ def client_node(request, grid, storage_nodes, number_of_nodes) -> Client:
) )
print(f"Client node pid: {client_node.process.transport.pid}") print(f"Client node pid: {client_node.process.transport.pid}")
return client_node return client_node
class Benchmarker:
"""Keep track of benchmarking results."""
@contextmanager
def record(self, name, **parameters):
"""Record the timing of running some code, if it succeeds."""
start = time()
yield
elapsed = time() - start
# For now we just print the outcome:
parameters = " ".join(f"{k}={v}" for (k, v) in parameters.items())
print(f"BENCHMARK RESULT: {name} {parameters} elapsed {elapsed} secs")
@pytest.fixture(scope="session")
def tahoe_benchmarker():
return Benchmarker()

View File

@ -12,7 +12,9 @@ def cli_alias(client_node):
cli(client_node.process, "create-alias", "cli") cli(client_node.process, "create-alias", "cli")
def test_get_put_one_file(client_node, cli_alias, tmp_path): def test_get_put_one_file(
client_node, cli_alias, tmp_path, tahoe_benchmarker, number_of_nodes
):
""" """
Upload a file with ``tahoe put`` and then download it with ``tahoe get``, Upload a file with ``tahoe put`` and then download it with ``tahoe get``,
measuring the latency of both operations. measuring the latency of both operations.
@ -20,21 +22,27 @@ def test_get_put_one_file(client_node, cli_alias, tmp_path):
file_size = 1000 # parameterize later on file_size = 1000 # parameterize later on
file_path = tmp_path / "file" file_path = tmp_path / "file"
DATA = b"0123456789" * (file_size // 10) DATA = b"0123456789" * (file_size // 10)
with file_path.open("wb") as f: with file_path.open("wb") as f:
f.write(DATA) f.write(DATA)
cli(client_node.process, "put", str(file_path), "cli:tostdout")
p = Popen( with tahoe_benchmarker.record(
[ "cli-put-file", file_size=file_size, number_of_nodes=number_of_nodes
"tahoe", ):
"--node-directory", cli(client_node.process, "put", str(file_path), "cli:tostdout")
client_node.process.node_dir,
"get", with tahoe_benchmarker.record(
"cli:tostdout", "cli-get-file", file_size=file_size, number_of_nodes=number_of_nodes
"-", ):
], p = Popen(
stdout=PIPE, [
) "tahoe",
assert p.stdout.read() == DATA "--node-directory",
assert p.wait() == 0 client_node.process.node_dir,
"get",
"cli:tostdout",
"-",
],
stdout=PIPE,
)
assert p.stdout.read() == DATA
assert p.wait() == 0