|
| 1 | +import seaborn as sns |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +import pandas as pd |
| 4 | +import numpy as np |
| 5 | + |
| 6 | +sns.set_theme(style="whitegrid", palette="colorblind") |
| 7 | + |
| 8 | + |
| 9 | +def save_plot(ax, plot_name: str) -> None: |
| 10 | + figure = ax.get_figure() |
| 11 | + figure.savefig(f"plots/{plot_name}.png") |
| 12 | + plt.close(figure) |
| 13 | + |
| 14 | + |
| 15 | +def print_and_plot_init_duration_by_language(data: pd.DataFrame) -> None: |
| 16 | + cold_starts = data[data["cold_start"] == True] |
| 17 | + |
| 18 | + print("Cold start times per language - p50, p95, p99") |
| 19 | + print( |
| 20 | + cold_starts.groupby("name")["init_duration_ms"] |
| 21 | + .quantile(q=np.array([0.50, 0.95, 0.99])) |
| 22 | + .unstack() |
| 23 | + ) |
| 24 | + print("-" * 10) |
| 25 | + |
| 26 | + ax = sns.histplot(x="init_duration_ms", hue="name", binwidth=20, data=data) |
| 27 | + ax.set_title("Cold start times by language") |
| 28 | + ax.set_xlabel("Init duration (ms)") |
| 29 | + ax.set_ylabel("Count") |
| 30 | + ax.set_xlim(0) |
| 31 | + sns.despine() |
| 32 | + save_plot(ax, "init_duration_by_language") |
| 33 | + |
| 34 | + |
| 35 | +def print_and_plot_run_time_by_language(data: pd.DataFrame) -> None: |
| 36 | + print("Execution times per language - p50, p95, p99") |
| 37 | + print( |
| 38 | + data.groupby(["name", "cold_start"])["execution_time_ms"] |
| 39 | + .quantile(q=np.array([0.50, 0.95, 0.99])) |
| 40 | + .unstack() |
| 41 | + ) |
| 42 | + print("-" * 10) |
| 43 | + |
| 44 | + ax = sns.histplot(x="execution_time_ms", hue="name", binwidth=5, data=data) |
| 45 | + ax.set_title("Execution times by language") |
| 46 | + ax.set_xlabel("Execution time (ms)") |
| 47 | + ax.set_ylabel("Count") |
| 48 | + ax.set_xlim(0, 500) |
| 49 | + sns.despine() |
| 50 | + save_plot(ax, "run_time_by_language") |
| 51 | + |
| 52 | + |
| 53 | +def print_total_cost_by_language(data: pd.DataFrame) -> None: |
| 54 | + # From August 1st 2025 AWS will charge for the INIT phase |
| 55 | + # https://aws.amazon.com/blogs/compute/aws-lambda-standardizes-billing-for-init-phase/ |
| 56 | + data["total_time"] = data["execution_time_ms"] + data["init_duration_ms"] |
| 57 | + totals = data.groupby("name")[ |
| 58 | + ["init_duration_ms", "execution_time_ms", "total_time"] |
| 59 | + ].sum() |
| 60 | + totals["init_percentage"] = totals["init_duration_ms"] / totals["total_time"] |
| 61 | + |
| 62 | + print("Total billed time by language") |
| 63 | + print(totals) |
| 64 | + print("-" * 10) |
| 65 | + |
| 66 | + |
| 67 | +if __name__ == "__main__": |
| 68 | + data = pd.read_csv("../data/parsed_cloudwatch_logs.csv") |
| 69 | + print_and_plot_init_duration_by_language(data=data) |
| 70 | + print_and_plot_run_time_by_language(data=data) |
| 71 | + print_total_cost_by_language(data=data) |
0 commit comments