Skip to content

Commit

Permalink
misc: add image-size for benchmark
Browse files Browse the repository at this point in the history
Signed-off-by: Desiki-high <ding_yadong@foxmail.com>
  • Loading branch information
Desiki-high committed Apr 24, 2023
1 parent 47280ab commit b12a3d9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
9 changes: 6 additions & 3 deletions misc/benchmark/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down Expand Up @@ -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()
4 changes: 1 addition & 3 deletions misc/benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
17 changes: 8 additions & 9 deletions misc/benchmark/benchmark_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]


Expand All @@ -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:
Expand Down Expand Up @@ -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():
Expand Down
41 changes: 40 additions & 1 deletion misc/benchmark/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

0 comments on commit b12a3d9

Please sign in to comment.