Files
canonical-stuff/run.py
2023-09-06 12:23:40 +02:00

69 lines
1.9 KiB
Python

"Run the bench cases."
# copyright: Canonical
import datetime
import json
import subprocess
from pathlib import Path
from loguru import logger as log
from definitions import BENCH_DIR_NAMES, CEPH_ROOT, INST_STO_ROOT, REMOTE_INST_STO_ROOT, SERV_URL
RESULTS = [["Run num", "test_case", "files", "MB/s", "time", "full size"]]
def run_single_bench(
runnum,
test_case,
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__":
for runnum in range(50):
for files_type in BENCH_DIR_NAMES:
test_case = "Distant-InsSto to InsSto"
source = f"{SERV_URL}/{REMOTE_INST_STO_ROOT}/{files_type}"
target = INST_STO_ROOT + files_type
run_single_bench(
runnum,
test_case,
files_type,
source,
target,
)
test_case = "Distant-InsSto to CEPH"
source = f"{SERV_URL}/{REMOTE_INST_STO_ROOT}/{files_type}"
target = CEPH_ROOT + files_type
run_single_bench(
runnum,
test_case,
files_type,
source,
target,
)
json.dump(RESULTS, open("results.json", "w"))