def run( self, system: str, mnt: str, stats: Dict[str, List], extra_env: Dict[str, str] = {}, mode: Mode = Mode.NORMAL, ) -> None: mysql = nix_build("mysql") command = [] if mode == Mode.PERF: command = [ "perf", "record", "-e", "intel_pt/cyc=1/u", "--" ] command += [ f"{mysql}/bin/mysqld", f"--datadir={mnt}/var/lib/mysql", "--socket=/tmp/mysql.sock", ] if os.geteuid() == 0: command += ["--user=nobody"] subprocess.run(["chown", "-R", "nobody", f"{mnt}/var/lib/mysql"]) with spawn(*command, cwd=mnt) as proc: if mode == Mode.TRACE: record = trace_with_pt(proc.pid, Path(mnt)) try: self.run_sysbench(system, stats) finally: if mode == Mode.TRACE: record.result()
def _run( self, local_iperf: str, direction: str, system: str, stats: Dict[str, List[int]], extra_env: Dict[str, str] = {}) -> None: env = extra_env.copy() env.update(flamegraph_env(f"iperf-{direction}-{system}-{NOW}")) iperf = f"{self.iperf_client.nix_path}/bin/iperf3" fast_ssl = dict(OPENSSL_ia32cap="0x5640020247880000:0x40128") env.update(fast_ssl) if check_port(nc_command, self.settings): print("There is already an iperf instance running", file=sys.stderr) sys.exit(1) with spawn(local_iperf, "bin/iperf3", "1", extra_env=env) as iperf_server: for i in range(60): if check_port(nc_command, self.settings): break status = iperf_server.poll() if status is not None: raise OSError(f"iperf exiteded with {status}") time.sleep(1) if i == 59: stop_process(iperf_server) raise OSError(f"Could not connect to iperf after 1 min") iperf_args = ["client", "-c", self.settings.local_dpdk_ip, "--json", "-t", "10"] if direction == "send": iperf_args += ["-R"] parallel_iperf = self.parallel_iperf.run("bin/parallel-iperf", ["1", iperf] + iperf_args, extra_env=fast_ssl) _postprocess_iperf(json.loads(parallel_iperf.stdout), direction, system, stats) stop_process(iperf_server)
def run(self, system: str, db_dir: str, stats: Dict[str, List], trace: bool = False) -> None: args = ["--dir", db_dir, "--requirepass", "snakeoil"] redis_server = nix_build("redis") with spawn(f"{redis_server}/bin/redis-server", *args) as proc: if trace: record = trace_with_pt(proc.pid, Path(db_dir)) try: self.run_ycsb(proc, system, stats) finally: if trace: record.result()
def test_nginx(settings: Settings) -> None: nginx = nix_build("nginx") remote_curl = settings.remote_command(nix_build("curl-remote")) with spawn(nginx.strip()): for _ in range(10): try: curl_args = ["curl", "-s", settings.local_dpdk_ip + "/test/file-3mb"] proc = remote_curl.run("bin/curl", curl_args) sha256 = hashlib.sha256(proc.stdout).hexdigest() expected = ( "259da4e49b1d0932c5a16a9809113cf3ea6c7292e827298827e020aa7361f98d" ) assert sha256 == expected, f"{hash} == {expected}" break except subprocess.CalledProcessError: pass
def run( self, attr: str, system: str, mnt: str, stats: Dict[str, List], extra_env: Dict[str, str] = {}, ) -> None: env = dict(SGXLKL_CWD=mnt) env.update(flamegraph_env(f"{os.getcwd()}/mysql-{system}")) env.update(extra_env) mysql = nix_build(attr) sysbench = sysbench_command(self.storage.settings) with spawn( mysql, "bin/mysqld", f"--datadir={mnt}/var/lib/mysql", "--socket=/tmp/mysql.sock", extra_env=env, ): common_flags = [ f"--mysql-host={self.settings.local_dpdk_ip}", "--mysql-db=root", "--mysql-user=root", "--mysql-password=root", "--mysql-ssl=on", "--table-size=500000", f"{sysbench.nix_path}/share/sysbench/oltp_read_write.lua", ] while True: try: proc = nc_command(self.settings).run( "bin/nc", ["-z", "-v", self.settings.local_dpdk_ip, "3306"]) break except subprocess.CalledProcessError: print(".") pass sysbench.run("bin/sysbench", common_flags + ["prepare"]) proc = sysbench.run("bin/sysbench", common_flags + ["run"]) process_sysbench(proc.stdout, system, stats) sysbench.run("bin/sysbench", common_flags + ["cleanup"])
def run( self, system: str, mnt: str, stats: Dict[str, List], trace: bool = False, ) -> None: nginx_server = nix_build("nginx") with spawn(f"{nginx_server}/bin/nginx", "-c", f"{mnt}/nginx/nginx.conf", cwd=mnt) as proc: if trace: record = trace_with_pt(proc.pid, Path(mnt)) try: self.run_wrk(proc, system, stats) finally: if trace: record.result()
def run( self, attr: str, system: str, mnt: str, stats: Dict[str, List], extra_env: Dict[str, str] = {}, ) -> None: env = extra_env.copy() env.update(flamegraph_env(f"{os.getcwd()}/nginx-{system}")) env.update(dict(SGXLKL_CWD=mnt)) nginx_server = nix_build(attr) host = self.settings.local_dpdk_ip with spawn(nginx_server, "bin/nginx", "-c", f"{mnt}/nginx/nginx.conf", extra_env=env) as proc: while True: try: self.remote_nc.run( "bin/nc", ["-z", self.settings.local_dpdk_ip, "9000"]) break except subprocess.CalledProcessError: status = proc.poll() if status is not None: raise OSError(f"nginx exiteded with {status}") time.sleep(1) pass wrk_connections = 100 wrk_proc = self.remote_wrk.run("bin/wrk", [ "-t", "16", "-c", f"{wrk_connections}", "-d", "30s", f"https://{host}:9000/test/file" ]) process_wrk_output(wrk_proc.stdout, system, stats, wrk_connections)
def run( self, system: str, redis_server: str, db_dir: str, stats: Dict[str, List], extra_env: Dict[str, str], ) -> None: args = [ "bin/redis-server", "--dir", db_dir, "--tls-port", "6379", "--port", "0", "--tls-cert-file", f"{db_dir}/server.cert", "--tls-key-file", f"{db_dir}/server.key", "--tls-ca-cert-file", f"{db_dir}/ca.crt", "--requirepass", "snakeoil", "--tls-auth-clients", "no" ] env = extra_env.copy() env.update(flamegraph_env(f"{os.getcwd()}/redis-{system}")) with spawn(redis_server, *args, extra_env=env) as proc: print(f"waiting for redis for {system} benchmark...", end="") while True: try: self.nc_command.run( "bin/nc", ["-z", "-v", self.settings.local_dpdk_ip, "6379"]) break except subprocess.CalledProcessError: status = proc.poll() if status is not None: raise OSError(f"redis-server exiteded with {status}") time.sleep(1) pass load_proc = self.remote_ycsb.run( "bin/ycsb", [ "load", "redis", "-s", "-P", f"{self.remote_ycsb.nix_path}/share/ycsb/workloads/workloada", "-p", f"redis.host={self.settings.local_dpdk_ip}", "-p", "redis.port=6379", "-p", "redis.timeout=600000", "-p", f"recordcount={self.record_count}", "-p", f"operationcount={self.operation_count}", "-p", "redis.password=snakeoil", ], ) run_proc = self.remote_ycsb.run( "bin/ycsb", [ "run", "redis", "-s", "-P", f"{self.remote_ycsb.nix_path}/share/ycsb/workloads/workloada", "-threads", "16", "-p", f"redis.host={self.settings.local_dpdk_ip}", "-p", "redis.port=6379", "-p", "redis.timeout=600000", "-p", f"recordcount={self.record_count}", "-p", f"operationcount={self.operation_count}", "-p", "redis.password=snakeoil", ], ) process_ycsb_out(run_proc.stdout, system, stats)
def run( self, attr: str, system: str, stats: Dict[str, List], extra_env: Dict[str, str] = {}, ) -> None: env = os.environ.copy() env.update(extra_env) network_test = nix_build(attr) server_ip = self.settings.remote_dpdk_ip num_bytes = str(1 * 1024 * 1024 * 1024) # 1 GiB batch_size = [4, 8, 16, 32, 64, 128, 256, 512] # in KiB #batch_size = [4, 8] # in KiB helper_run([ "nix", "copy", self.local_nc, "--to", f"ssh://{self.settings.remote_ssh_host}" ]) nc_cmds = [["while", "true"], [ "do", f"{self.local_nc}/bin/nc", "-l", "8888", ">", "/dev/null", "2>&1" ], ["done"]] nc_command = "; ".join(map(lambda cmd: " ".join(cmd), nc_cmds)) with spawn("ssh", self.settings.remote_ssh_host, "--", nc_command) as remote_nc_proc: for bs in batch_size: #while True: # try: # nc_cmd = [ # f"{self.local_nc}/bin/nc", # "-z", "-v", # f"{server_ip}", # "8888" # ] # nc_proc = subprocess.run(nc_cmd) # break # except subprocess.CalledProcessError: # #status = remote_nc_proc.poll() # #if status is not None: # # raise OSError(f"netcat-server exiteded with {status}") # #time.sleep(1) # pass local_proc = subprocess.Popen( [ network_test, "bin/network-test", "write", f"{server_ip}", num_bytes, str(bs), ], stdout=subprocess.PIPE, text=True, env=env, ) try: local_proc.wait() #breakpoint() assert local_proc.stdout for line in local_proc.stdout: data = json.loads(line) stats["system"].append(system) stats["batch_size"].append(bs) for i in data: stats[i].append(data[i]) print(local_proc.stdout.read()) except Exception as e: print(f"{local_proc.stdout} not in json format") print(stats)