implementing results csv and local to local
This commit is contained in:
36
benchmark.py
Normal file
36
benchmark.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# copyright: Canonical
|
||||||
|
"Run the bench cases (remote to local)."
|
||||||
|
import datetime
|
||||||
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from loguru import logger as log
|
||||||
|
|
||||||
|
|
||||||
|
def run_single_bench(
|
||||||
|
runnum,
|
||||||
|
test_case,
|
||||||
|
files_type,
|
||||||
|
source,
|
||||||
|
target,
|
||||||
|
results,
|
||||||
|
):
|
||||||
|
log.info(f"Syncing {runnum} {test_case} {files_type}")
|
||||||
|
start = datetime.datetime.now()
|
||||||
|
subprocess.run(
|
||||||
|
[
|
||||||
|
"rsync",
|
||||||
|
"-a",
|
||||||
|
f"{source}",
|
||||||
|
f"{target}",
|
||||||
|
],
|
||||||
|
capture_output=True,
|
||||||
|
# shell=True,
|
||||||
|
)
|
||||||
|
time = datetime.datetime.now() - start
|
||||||
|
size = sum(f.stat().st_size for f in Path(target).glob("**/*") if f.is_file())
|
||||||
|
size_MB = size / 1000 / 1000 / 8
|
||||||
|
speed = size_MB / time.total_seconds()
|
||||||
|
log.info(f"{files_type} - {speed} MB/s")
|
||||||
|
subprocess.run(["rm", "-rf", target])
|
||||||
|
results.add([runnum, test_case, files_type, speed, time.total_seconds(), size_MB])
|
||||||
23
results_tools.py
Normal file
23
results_tools.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# copyright: Canonical
|
||||||
|
"Tools for managing results."
|
||||||
|
import csv
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
|
||||||
|
class Results:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.result_list = [["Run num", "test_case", "files", "MB/s", "time", "full size"]]
|
||||||
|
|
||||||
|
def add(self, row: list) -> None:
|
||||||
|
"""Add a row to the results lists.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
row (list): a row of results.
|
||||||
|
"""
|
||||||
|
self.result_list.append(row)
|
||||||
|
|
||||||
|
def save_to_csv(self) -> None:
|
||||||
|
"""Save results to csv file in the current directory."""
|
||||||
|
with open(f"results{uuid4()}.csv", "w") as f:
|
||||||
|
cw = csv.writer(f)
|
||||||
|
cw.writerows(self.result_list)
|
||||||
69
run.py
69
run.py
@@ -1,46 +1,41 @@
|
|||||||
"Run the bench cases."
|
|
||||||
# copyright: Canonical
|
# copyright: Canonical
|
||||||
import datetime
|
"Run the bench cases (remote to local)."
|
||||||
import json
|
import json
|
||||||
import subprocess
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from loguru import logger as log
|
import click
|
||||||
|
|
||||||
|
from benchmark import run_single_bench
|
||||||
from definitions import BENCH_DIR_NAMES, CEPH_ROOT, INST_STO_ROOT, REMOTE_INST_STO_ROOT, SERV_URL
|
from definitions import BENCH_DIR_NAMES, CEPH_ROOT, INST_STO_ROOT, REMOTE_INST_STO_ROOT, SERV_URL
|
||||||
|
from results_tools import Results
|
||||||
|
|
||||||
RESULTS = [["Run num", "test_case", "files", "MB/s", "time", "full size"]]
|
results = Results()
|
||||||
|
|
||||||
|
|
||||||
def run_single_bench(
|
@click.group()
|
||||||
runnum,
|
def cli():
|
||||||
test_case,
|
pass
|
||||||
files_type,
|
|
||||||
source,
|
|
||||||
target,
|
|
||||||
):
|
|
||||||
log.info(f"Syncing {runnum} {test_case} {files_type}")
|
|
||||||
start = datetime.datetime.now()
|
|
||||||
subprocess.run(
|
|
||||||
[
|
|
||||||
"rsync",
|
|
||||||
"-a",
|
|
||||||
f"{source}",
|
|
||||||
f"{target}",
|
|
||||||
],
|
|
||||||
capture_output=True,
|
|
||||||
# shell=True,
|
|
||||||
)
|
|
||||||
time = datetime.datetime.now() - start
|
|
||||||
size = sum(f.stat().st_size for f in Path(target).glob("**/*") if f.is_file())
|
|
||||||
size_MB = size / 1000 / 1000 / 8
|
|
||||||
speed = size_MB / time.total_seconds()
|
|
||||||
log.info(f"{files_type} - {speed} MB/s")
|
|
||||||
subprocess.run(["rm", "-rf", target])
|
|
||||||
RESULTS.append([runnum, test_case, files_type, speed, time.total_seconds(), size_MB])
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
@cli.command()
|
||||||
|
def local():
|
||||||
|
click.echo("Running locally")
|
||||||
|
for runnum in range(50):
|
||||||
|
for files_type in BENCH_DIR_NAMES:
|
||||||
|
test_case = "Distant-InsSto to InsSto"
|
||||||
|
source = f"{INST_STO_ROOT}/{files_type}"
|
||||||
|
target = CEPH_ROOT + files_type
|
||||||
|
run_single_bench(
|
||||||
|
runnum,
|
||||||
|
test_case,
|
||||||
|
files_type,
|
||||||
|
source,
|
||||||
|
target,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
def distant():
|
||||||
|
click.echo("Running distant to local")
|
||||||
for runnum in range(50):
|
for runnum in range(50):
|
||||||
for files_type in BENCH_DIR_NAMES:
|
for files_type in BENCH_DIR_NAMES:
|
||||||
test_case = "Distant-InsSto to InsSto"
|
test_case = "Distant-InsSto to InsSto"
|
||||||
@@ -63,6 +58,12 @@ if __name__ == "__main__":
|
|||||||
files_type,
|
files_type,
|
||||||
source,
|
source,
|
||||||
target,
|
target,
|
||||||
|
results,
|
||||||
)
|
)
|
||||||
|
|
||||||
json.dump(RESULTS, open("results.json", "w"))
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
cli()
|
||||||
|
|
||||||
|
json.dump(results.result_list, open("results.json", "w"))
|
||||||
|
results.save_to_csv()
|
||||||
|
|||||||
Reference in New Issue
Block a user