Skip to content

Commit

Permalink
misc: benchmark metrics support more images
Browse files Browse the repository at this point in the history
Signed-off-by: Yadong Ding <ding_yadong@foxmail.com>
  • Loading branch information
Desiki-high authored and imeoer committed May 8, 2023
1 parent ad8f870 commit 9d87631
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 44 deletions.
22 changes: 11 additions & 11 deletions misc/benchmark/benchmark_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
from argparse import ArgumentParser

COMMANDS_BENCHMARK = [
"sudo install -m 755 benchmark-oci/wordpress.csv oci.csv",
"sudo install -m 755 benchmark-nydus-all-prefetch/wordpress.csv nydus-all-prefetch.csv",
"sudo install -m 755 benchmark-nydus-no-prefetch/wordpress.csv nydus-no-prefetch.csv",
"sudo install -m 755 benchmark-zran-all-prefetch/wordpress.csv zran-all-prefetch.csv",
"sudo install -m 755 benchmark-zran-no-prefetch/wordpress.csv zran-no-prefetch.csv",
"sudo install -m 755 benchmark-nydus-filelist-prefetch/wordpress.csv nydus-filelist-prefetch.csv"
"sudo install -m 755 benchmark-oci/*.csv oci.csv",
"sudo install -m 755 benchmark-nydus-all-prefetch/*.csv nydus-all-prefetch.csv",
"sudo install -m 755 benchmark-nydus-no-prefetch/*.csv nydus-no-prefetch.csv",
"sudo install -m 755 benchmark-zran-all-prefetch/*.csv zran-all-prefetch.csv",
"sudo install -m 755 benchmark-zran-no-prefetch/*.csv zran-no-prefetch.csv",
"sudo install -m 755 benchmark-nydus-filelist-prefetch/*.csv nydus-filelist-prefetch.csv"
]

COMMANDS_BENCHMARK_COMPARE = [
"sudo install -m 755 benchmark-zran-all-prefetch-master/wordpress.csv zran-all-prefetch-master.csv",
"sudo install -m 755 benchmark-zran-no-prefetch-master/wordpress.csv zran-no-prefetch-master.csv",
"sudo install -m 755 benchmark-nydus-no-prefetch-master/wordpress.csv nydus-no-prefetch-master.csv",
"sudo install -m 755 benchmark-nydus-all-prefetch-master/wordpress.csv nydus-all-prefetch-master.csv",
"sudo install -m 755 benchmark-nydus-filelist-prefetch-master/wordpress.csv nydus-filelist-prefetch-master.csv"
"sudo install -m 755 benchmark-zran-all-prefetch-master/*.csv zran-all-prefetch-master.csv",
"sudo install -m 755 benchmark-zran-no-prefetch-master/*.csv zran-no-prefetch-master.csv",
"sudo install -m 755 benchmark-nydus-no-prefetch-master/*.csv nydus-no-prefetch-master.csv",
"sudo install -m 755 benchmark-nydus-all-prefetch-master/*.csv nydus-all-prefetch-master.csv",
"sudo install -m 755 benchmark-nydus-filelist-prefetch-master/*.csv nydus-filelist-prefetch-master.csv"
]

FILE_LIST = [
Expand Down
1 change: 1 addition & 0 deletions misc/benchmark/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def nydus_convert(self):
convert oci image to nydus image (prefetchfile is optional)
"""
print(self.convert_cmd())
rc = os.system(f"sudo cat {self.prefetch}")
rc = os.system(self.convert_cmd())
assert rc == 0

Expand Down
119 changes: 86 additions & 33 deletions misc/benchmark/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import shutil
import string
import subprocess
import sys
import time
import urllib.request
from typing import Tuple

import bench

"""
define some file path, and sock api url
"""
Expand All @@ -30,24 +33,29 @@ def __init__(self, cfg: dict):
self.insecure_registry = cfg["insecure_registry"]
self.image = cfg["image"]

def start_collet(self, arg="") -> str:
def start_collet(self) -> str:
runner = bench.BenchRunner(
registry=self.registry,
snapshotter="nydus",
insecure_registry=self.insecure_registry,
)
image_ref = self.image_ref(self.image)
container_name = self.image.replace(":", "-") + random_string()
pull_cmd = self.pull_cmd(image_ref)
print(pull_cmd)
print("Pulling image %s ..." % image_ref)
rc = os.system(pull_cmd)
assert rc == 0
create_cmd = self.create_container_cmd(image_ref, container_name, arg)
print(create_cmd)
print("Creating container for image %s ..." % image_ref)
rc = os.system(create_cmd)
assert rc == 0
run_cmd = self.start_container_cmd(container_name)
print(run_cmd)
print("Running container %s ..." % container_name)
rc = os.system(run_cmd)
assert rc == 0
repo = bench.image_repo(self.image)
if repo in bench.BenchRunner.CMD_URL_WAIT:
self.run_cmd_url_wait(runner=runner, runargs=bench.BenchRunner.CMD_URL_WAIT[repo], image_ref=image_ref, container_name=container_name)
elif repo in bench.BenchRunner.CMD_ARG:
self.run_cmd_arg(runner=runner, runargs=bench.BenchRunner.CMD_ARG[repo], image_ref=image_ref, container_name=container_name)
elif repo in bench.BenchRunner.CMD_STDIN:
self.run_cmd_stdin(runner=runner, runargs=bench.BenchRunner.CMD_STDIN[repo], image_ref=image_ref, container_name=container_name)
else:
print("Unknown bench: " + repo)
os.exit(1)
file = self.collect(self.image)
self.clean_up(image_ref, container_name)
return file
Expand All @@ -61,18 +69,76 @@ def pull_cmd(self, image_ref):
f"sudo nerdctl --snapshotter nydus pull {insecure_flag} {image_ref}"
)

def create_container_cmd(self, image_ref, container_id, arg=""):
if arg == "":
return f"sudo nerdctl --snapshotter nydus create --net=host --name={container_id} {image_ref}"
else:
return f"sudo nerdctl --snapshotter nydus create --net=host {arg} --name={container_id} {image_ref}"

def start_container_cmd(self, container_id):
return f"sudo nerdctl --snapshotter nydus start {container_id}"

def stop_container_cmd(self, container_id):
return f"sudo nerdctl --snapshotter nydus stop {container_id}"

def run_cmd_url_wait(self, runner, runargs, image_ref, container_name):

create_cmd = runner.create_cmd_url_wait_cmd(image_ref, container_name, runargs)
print(create_cmd)

print("Creating container for image %s ..." % image_ref)
rc = os.system(create_cmd)
assert rc == 0

run_cmd = runner.task_start_cmd(container_name, iteration=False)
print(run_cmd)

print("Running container %s ..." % container_name)

_ = subprocess.Popen(run_cmd, shell=True)
while True:
try:
req = urllib.request.urlopen(runargs.waitURL)
print(req.status)
req.close()
break
except:
time.sleep(0.01)

def run_cmd_arg(self, runner, runargs, image_ref, container_name):
assert len(runargs.mount) == 0

create_cmd = runner.create_cmd_arg_cmd(image_ref, container_name, runargs)
print(create_cmd)

print("Creating container for image %s ..." % image_ref)
rc = os.system(create_cmd)
assert rc == 0

run_cmd = runner.task_start_cmd(container_name, iteration=False)
print(run_cmd)
rc = os.system(run_cmd)
assert rc == 0

def run_cmd_stdin(self, runner, runargs, image_ref, container_name):

create_cmd = runner.create_cmd_stdin_cmd(image_ref, container_name, runargs)
print(create_cmd)

print("Creating container for image %s ..." % image_ref)
rc = os.system(create_cmd)
assert rc == 0

run_cmd = runner.task_start_cmd(container_name, iteration=True)
print(run_cmd)

print("Running container %s ..." % container_name)

p = subprocess.Popen(
run_cmd,
shell=True,
stdin=subprocess.PIPE,
stdout=sys.stdout,
stderr=sys.stdout,
bufsize=0,
)

print(runargs.stdin)
stdin = runargs.stdin + "\nexit\n"
p.communicate(stdin.encode())
assert p.returncode == 0

def clean_up(self, image_ref, container_id):
print("Cleaning up environment for %s ..." % container_id)
cmd = self.stop_container_cmd(container_id)
Expand All @@ -92,19 +158,6 @@ def collect(self, repo) -> str:
"""
collect the access files
"""
# wait wordpress response in 80 port
if self.image == "wordpress":
while True:
try:
req = urllib.request.urlopen("http://localhost:80")
print(req.status)
req.close()
break
except:
time.sleep(0.01)
# TODO: support more images
else:
time.sleep(10)
socket = search_file(API_DIR, "api.sock")
if socket == None:
print("can't find the api.sock")
Expand Down

0 comments on commit 9d87631

Please sign in to comment.