From 7edea8a0e320fca78d4c494b1a2e2c15824bf2bd Mon Sep 17 00:00:00 2001 From: Desiki-high Date: Mon, 24 Apr 2023 20:03:35 +0800 Subject: [PATCH] misc: add image-size for benchmark Signed-off-by: Desiki-high --- misc/benchmark/bench.py | 9 ++++--- misc/benchmark/benchmark.py | 4 +-- misc/benchmark/benchmark_summary.py | 17 ++++++------ misc/benchmark/metrics.py | 41 ++++++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/misc/benchmark/bench.py b/misc/benchmark/bench.py index 94bf9e1f4d1..a230900a4f7 100644 --- a/misc/benchmark/bench.py +++ b/misc/benchmark/bench.py @@ -184,13 +184,16 @@ def run_cmd_url_wait(self, repo, runargs): run_elapsed = datetime.timestamp(end_run) - datetime.timestamp(start_run) print("Run time: %f s" % run_elapsed) + read_amount, read_count = "-", "-" if self.snapshotter == "nydus": read_amount, read_count = metrics.collect_backend() + image_size = metrics.collect_size(image_repo(repo), image_tag(repo)) + if self.cleanup: self.clean_up(image_ref, container_id) - return pull_elapsed, create_elapsed, run_elapsed, read_amount, read_count + return pull_elapsed, create_elapsed, run_elapsed, image_size, read_amount, read_count def pull_cmd(self, image_ref): insecure_flag = "--insecure-registry" if self.insecure_registry else "" @@ -253,11 +256,11 @@ def bench_image(local_registry, insecure_local_registry, image, f: TextIOWrapper cleanup=True, insecure_registry=insecure_local_registry, ) - pull_elapsed, create_elapsed, run_elapsed, read_amount, read_count = runner.run(bench) + pull_elapsed, create_elapsed, run_elapsed, image_size, read_amount, read_count = runner.run(bench) total_elapsed = f"{pull_elapsed + create_elapsed + run_elapsed: .6f}" pull_elapsed = f"{pull_elapsed: .6f}" create_elapsed = f"{create_elapsed: .6f}" run_elapsed = f"{run_elapsed: .6f}" - line = f"{bench.name},{pull_elapsed},{create_elapsed},{run_elapsed},{total_elapsed},{read_amount},{read_count}" + line = f"{pull_elapsed},{create_elapsed},{run_elapsed},{total_elapsed},{image_size},{read_amount},{read_count}" f.writelines(line + "\n") f.flush() diff --git a/misc/benchmark/benchmark.py b/misc/benchmark/benchmark.py index 080fbde06bb..d021565bd05 100644 --- a/misc/benchmark/benchmark.py +++ b/misc/benchmark/benchmark.py @@ -41,6 +41,7 @@ def main(): # bench start_bench(cfg, cfg["image"], mode) + def collect_metrics(cfg: dict, image: str) -> str: """ collect container access metrics @@ -53,9 +54,6 @@ def start_bench(cfg: dict, image: str, mode: str): bench oci, nydus without prefetch, nydus with all prefetch, nydus witch prefetch file list """ f = open(util.image_repo(image) + ".csv", "w") - csv_headers = "repo,pull_elapsed(s),create_elapsed(s),run_elapsed(s),total_elapsed(s),read_amount(MB),read_count" - f.writelines(csv_headers + "\n") - f.flush() if mode == "oci": util.enable_wondersphaper(cfg["bandwith"]) bench.bench_image(cfg["local_registry"], cfg["insecure_local_registry"], image, f) diff --git a/misc/benchmark/benchmark_summary.py b/misc/benchmark/benchmark_summary.py index 8ea809048b9..5c731babab7 100644 --- a/misc/benchmark/benchmark_summary.py +++ b/misc/benchmark/benchmark_summary.py @@ -37,11 +37,11 @@ "zran-all-prefetch-master.csv", "zran-all-prefetch.csv", "nydus-no-prefetch-master.csv", - "nydus-no-prefetch-master.csv", - "zran-no-prefetch.csv", + "nydus-no-prefetch.csv", "zran-no-prefetch-master.csv", - "nydus-filelist-prefetch.csv", - "nydus-filelist-prefetch-master.csv" + "zran-no-prefetch.csv", + "nydus-filelist-prefetch-master.csv", + "nydus-filelist-prefetch.csv" ] @@ -51,8 +51,8 @@ def __init__(self, mode): def summary(self): self.prepare_csv() - print("| bench-result | pull-elapsed(s) | create-elapsed(s) | run-elapsed(s) | total-elapsed(s) |read-amount(MB) |read-count |") - print("|:-------------|:---------------:|:-----------------:|:--------------:|:----------------:|:--------------:|:---------:|") + print("| bench-result | pull-elapsed(s) | create-elapsed(s) | run-elapsed(s) | total-elapsed(s) | image-size(MB) | read-amount(MB) | read-count |") + print("|:-------------|:---------------:|:-----------------:|:--------------:|:----------------:|:--------------:|:---------------:|:----------:|") if self.mode == "benchmark-result": self.print_csv_result() else: @@ -81,10 +81,9 @@ def print_csv(file: str): with open(file, 'r', newline='') as f: filename = file.rstrip(".csv") rows = csv.reader(f) - next(rows) # we don't need header for row in rows: - _, pull_elapsed, create_elapsed, run_elapsed, total_elapsed, read_amount, read_count = row - print(f"|{filename}|{pull_elapsed}|{create_elapsed}|{run_elapsed}|{total_elapsed}|{read_amount}|{read_count}|") + pull_elapsed, create_elapsed, run_elapsed, total_elapsed, image_size, read_amount, read_count = row + print(f"|{filename}|{pull_elapsed}|{create_elapsed}|{run_elapsed}|{total_elapsed}|{image_size}|{read_amount}|{read_count}|") def main(): diff --git a/misc/benchmark/metrics.py b/misc/benchmark/metrics.py index 763166a80db..200afa8cf42 100755 --- a/misc/benchmark/metrics.py +++ b/misc/benchmark/metrics.py @@ -227,7 +227,6 @@ def send_request(sock_path, url): file_path = random_string() cmd = ["sudo", "curl", "--unix-socket", sock_path] cmd.extend(["-X", "GET", URL_PREFIX + url]) - # caruon with open(TEMP_DIR + "/" + file_path, 'w') as f: _ = run_cmd( cmd, @@ -285,3 +284,43 @@ def collect_backend() -> Tuple[str, str]: backend = get_backend_metrics(socket) shutil.rmtree(TEMP_DIR) return round(backend["read_amount_total"] / 1024 / 1024, 2), backend["read_count"] + + +def collect_size(repo: str, tag: str): + """ + collect image size for benchmark + + return the image size + """ + init() + file_path = random_string() + cmd = ["sudo", "curl", "-H", "'Accept: application/vnd.docker.distribution.manifest.v2+json'"] + cmd.extend([f"localhost:5000/v2/{repo}/manifests/{tag}"]) + with open(TEMP_DIR + "/" + file_path, 'w') as f: + _ = run_cmd( + cmd, + shell=True, + stdout=f, + stderr=subprocess.PIPE + ) + with open(TEMP_DIR + "/" + file_path, 'r') as file: + content = file.read() + if "errors" in content: + file_path_zran = random_string() + cmd = ["sudo", "curl", "-H", "'Accept: application/vnd.oci.image.manifest.v1+json'"] + cmd.extend([f"localhost:5000/v2/{repo}/manifests/{tag}"]) + with open(TEMP_DIR + "/" + file_path_zran, 'w') as f: + _ = run_cmd( + cmd, + shell=True, + stdout=f, + stderr=subprocess.PIPE + ) + with open(TEMP_DIR + "/" + file_path_zran, 'r') as file_zran: + content = file_zran.read() + manifest = json.loads(content) + size = 0 + for item in manifest["layers"]: + size += item["size"] + shutil.rmtree(TEMP_DIR) + return round(size / 1024 / 1024, 2)