in right_size_your_sagemaker_endpoints/load_test_helper.py [0:0]
def generate_latency_plot(endpoints, results_folder):
"""
Generate latency plots for a given list of endpoints
Given a list of endpoints, this function plots the minimum,
maximum and average latency in a box plot.
Inputs:
endpoints: list of endpoint names
results_folder: path where load test results are saved
Output:
Boxplot of latencies per instance type
"""
latency_dict= {}
# for each endpoint get latency from the load test results
for ep in endpoints:
prefix = f"test_{ep}"
df = pd.read_csv(f"{results_folder}/{prefix}/{prefix}_stats.csv")
min_latency = round(df.tail(1)['Min Response Time'].values[0] / 1000, 1)
avg_latency = round(df.tail(1)['Average Response Time'].values[0] / 1000, 1)
max_latency = round(df.tail(1)['Max Response Time'].values[0] / 1000, 1)
latency_dict.update({
ep.split("-", 1)[1].replace("-", "."): [min_latency,
avg_latency,
max_latency]
})
# generate a data frame of the results and plot a box plot
results = pd.DataFrame(latency_dict)
res_plot = results.plot(legend=True, figsize=(12, 7), kind='box',
title="Request Latency Across Instance Types",
xlabel="Instance Type",
ylabel="Latency in Seconds")