def plot(dfs, filters, plot_name, custom): if custom == "locust": for df in dfs: sns.lineplot(data=df, x="Latency (ms)", y="Percent") plt.legend(labels=filters) plt.xlim(0, 1000) plt.title(plot_name) elif custom == "fortio": for df in dfs: sns.lineplot(data=df, x="Latency (ms)", y="Percent") plt.legend(labels=filters) plt.title(plot_name) elif custom == "loadgen": fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(18, 6)) dplot = sns.ecdfplot(dfs, ax=ax1) dplot.set(xlabel="Latency (ms)", ylabel="Percentiles") dplot.set_title(plot_name) hplot = sns.histplot(dfs, ax=ax2) hplot.set(xlabel="Latency (ms)", ylabel="Count") else: log.info("No valid load generator supplied!") return util.EXIT_FAILURE util.check_dir(GRAPHS_DIR) plt.savefig(f"{GRAPHS_DIR}/{plot_name}.png") log.info("Finished plotting. Check out the graphs directory!") return util.EXIT_SUCCESS
def generate_testfolder(results_dir): n_folders = 0 if os.path.isdir(results_dir): f_list = os.listdir(results_dir) n_folders = len(f_list) testfolder = results_dir.joinpath(f"run_{n_folders}") util.check_dir(testfolder) return testfolder
def run_fortio(url, platform, threads, qps, run_time, file_name): util.check_dir(DATA_DIR) output_file = str(DATA_DIR.joinpath(f"{file_name}.json")) fortio_dir = str(FORTIO_DIR) cmd = f"{fortio_dir} " cmd += f"load -c {threads} -qps {qps} -jitter -t {run_time}s -json {output_file} " cmd += f"{url}" with open(output_file, "w") as f: fortio_res = util.exec_process(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return fortio_res
def run_fortio(url, platform, threads, qps, run_time, command_args, filename): util.check_dir(DATA_DIR) output_file = str(DATA_DIR.joinpath(f"{filename}.json")) fortio_dir = str(FORTIO_DIR) cmd = f"{fortio_dir} load " cmd += f"-c {threads} -qps {qps} -timeout 50s -t {run_time}s -json {output_file} " cmd += " {command_args} " cmd += f"{url}" with open(output_file, "w") as f: res = util.exec_process(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return res
def plot(dfs, filters, title, fortio=True): timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(time.time())) plot_name = "-".join(filters) + timestamp if fortio: for df in dfs: sns.lineplot(data=df, x="Latency (ms)", y="Percent") plt.legend(labels=filters) plt.title(f"Fortio: {title}") else: plot = sns.displot(dfs, kind="ecdf") plot.set(title=plot_name) util.check_dir(GRAPHS_DIR) plt.savefig(f"{GRAPHS_DIR}/{plot_name}.png") log.info("Finished plotting. Check out the graphs directory!") return util.EXIT_SUCCESS
def start_benchmark(filter_dirs, platform, threads, qps, run_time, **kwargs): if kube_env.check_kubernetes_status() != util.EXIT_SUCCESS: log.error("Kubernetes is not set up." " Did you run the deployment script?") return util.EXIT_FAILURE custom = kwargs.get("custom") request = kwargs.get("request") output = kwargs.get("output_file") command_args = " ".join(kwargs.get("command_args")) application = APPLICATIONS.get(kwargs.get("application")) _, _, gateway_url = kube_env.get_gateway_info(platform) path = kwargs.get("subpath") url = f"http://{gateway_url}/{path}" log.info("Gateway URL: %s", url) results = [] filters = [] if kwargs.get("no_filter") == "ON": filter_dirs.insert(0, "no_filter") filters.insert(0, "no_filter") for f in DATA_DIR.glob("*"): if f.is_file(): f.unlink() for (idx, filter_dir) in enumerate(filter_dirs): log.info("Benchmarking %s", filter_dir) fname = Path(filter_dir).name if filter_dir != "no_filter": res = build_and_deploy_filter(filter_dir) if res != util.EXIT_SUCCESS: return util.EXIT_FAILURE filters.append(fname) log.info("Warming up...") for i in range(10): requests.get(url) if custom == "locust": if not application: log.error("Provided application does not exists") return util.EXIT_FAILURE log.info("Running locust...") res = run_locust(f"http://{gateway_url}", platform, command_args, application, fname, run_time, kwargs.get("num_users"), kwargs.get("spawn_rate")) if res != util.EXIT_SUCCESS: log.error("Error benchmarking %s application", application) return util.EXIT_FAILURE elif custom == "fortio": log.info("Running fortio...") fortio_res = run_fortio(url, platform, threads, qps, run_time, command_args, fname) if fortio_res != util.EXIT_SUCCESS: log.error("Error benchmarking for %s", fd) return util.EXIT_FAILURE elif custom == "loadgen": log.info("Generating load...") burst_res = run_loadgen(url, platform, threads, qps, run_time, request) results.append(burst_res) else: log.error("Invalid load generator") return util.EXIT_FAILURE # Plot functions timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) npy_file = f"{custom} {application} {timestamp}" npy_file_dir = str(NPY_DIR.joinpath(npy_file)) graph_output = f"{custom} {application} {timestamp}" util.check_dir(NPY_DIR) if custom == "locust": locust_df = transform_locust_data(filters, application) np.save(npy_file_dir, locust_df) return plot(locust_df, filters, graph_output, custom) elif custom == "fortio": fortio_df, title = transform_fortio_data(filters) np.save(npy_file_dir, fortio_df) return plot(fortio_df, filters, graph_output, custom) elif custom == "loadgen": loadgen_df = transform_loadgen_data(filters, results) np.save(npy_file_dir, loadgen_df) return plot(loadgen_df, filters, graph_output, custom)