{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Scenario 1 Results:\n"
]
},
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Scenario | \n",
" Setup | \n",
" Mode | \n",
" Scaling Speed (mins) | \n",
" CPU Utilization (%) | \n",
" Memory Utilization (%) | \n",
" Cost Efficiency | \n",
" Resource Provisioning | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" Scenario 1: IBM | \n",
" Homogenous | \n",
" Cas | \n",
" 30.0 | \n",
" 6.0 | \n",
" 6.0 | \n",
" $X per hour | \n",
" Static | \n",
"
\n",
" \n",
" | 1 | \n",
" Scenario 1: IBM | \n",
" Homogenous | \n",
" Karpenter | \n",
" 30.0 | \n",
" 3.0 | \n",
" 3.0 | \n",
" $X per hour | \n",
" Dynamic | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Scenario Setup Mode Scaling Speed (mins) \\\n",
"0 Scenario 1: IBM Homogenous Cas 30.0 \n",
"1 Scenario 1: IBM Homogenous Karpenter 30.0 \n",
"\n",
" CPU Utilization (%) Memory Utilization (%) Cost Efficiency \\\n",
"0 6.0 6.0 $X per hour \n",
"1 3.0 3.0 $X per hour \n",
"\n",
" Resource Provisioning \n",
"0 Static \n",
"1 Dynamic "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Scenario 2 Results:\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Scenario | \n",
" Setup | \n",
" Mode | \n",
" Scaling Speed (mins) | \n",
" CPU Utilization (%) | \n",
" Memory Utilization (%) | \n",
" Cost Efficiency | \n",
" Resource Provisioning | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" Scenario 2: IBM | \n",
" Homogenous | \n",
" Cas | \n",
" 30.0 | \n",
" 6.0 | \n",
" 6.0 | \n",
" $X per hour | \n",
" Static | \n",
"
\n",
" \n",
" | 1 | \n",
" Scenario 2: IBM | \n",
" Homogenous | \n",
" Karpenter | \n",
" 30.0 | \n",
" 3.0 | \n",
" 3.0 | \n",
" $X per hour | \n",
" Dynamic | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Scenario Setup Mode Scaling Speed (mins) \\\n",
"0 Scenario 2: IBM Homogenous Cas 30.0 \n",
"1 Scenario 2: IBM Homogenous Karpenter 30.0 \n",
"\n",
" CPU Utilization (%) Memory Utilization (%) Cost Efficiency \\\n",
"0 6.0 6.0 $X per hour \n",
"1 3.0 3.0 $X per hour \n",
"\n",
" Resource Provisioning \n",
"0 Static \n",
"1 Dynamic "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Import required libraries\n",
"import os\n",
"import json\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"# Directories for analysis\n",
"providers = [\"aws\", \"ibm\"]\n",
"setups = [\"heterogenous\", \"homogenous\"]\n",
"modes = [\"cas\", \"karpenter\"]\n",
"\n",
"# Initialize results dictionary\n",
"results = {}\n",
"\n",
"# Function to calculate scaling speed\n",
"def calculate_scaling_speed(values):\n",
" timestamps = [val[0] for val in values]\n",
" deltas = np.diff(timestamps)\n",
" return np.mean(deltas)\n",
"\n",
"# Function to calculate average utilization\n",
"def calculate_average_utilization(values):\n",
" utilizations = [float(val[1]) for val in values]\n",
" return np.mean(utilizations)\n",
"# Function to get cost from billing metrics\n",
"def get_cost_from_billing(provider, setup, mode):\n",
" billing_file = os.path.join(provider, setup, mode, f\"{provider}_billing_metrics_{mode}.json\")\n",
" if os.path.exists(billing_file):\n",
" with open(billing_file, \"r\") as file:\n",
" data = json.load(file)\n",
" # Get the most recent time period's cost\n",
" latest_period = data[\"ResultsByTime\"][-1]\n",
" cost = float(latest_period[\"Total\"][\"UnblendedCost\"][\"Amount\"])\n",
" return f\"${cost:.2f} per hour\"\n",
" return \"$X per hour\" # Keep original placeholder if file not found\n",
"# Traverse directories and process files\n",
"for provider in providers:\n",
" results[provider] = {}\n",
" for setup in setups:\n",
" results[provider][setup] = {}\n",
" for mode in modes:\n",
" # Define the path to the JSON file\n",
" json_path = os.path.join(provider, setup, mode, \"NodeCount.json\")\n",
" if os.path.exists(json_path):\n",
" with open(json_path, \"r\") as file:\n",
" data = json.load(file)\n",
" values = data[\"data\"][\"result\"][0][\"values\"]\n",
" # Calculate metrics\n",
" scaling_speed = calculate_scaling_speed(values)\n",
" average_utilization = calculate_average_utilization(values)\n",
" # Store results\n",
" results[provider][setup][mode] = {\n",
" \"Scaling Speed\": scaling_speed,\n",
" \"CPU Utilization\": average_utilization,\n",
" \"Memory Utilization\": average_utilization, # Placeholder for memory\n",
" \"Cost Efficiency\": \"$X per hour\", # Placeholder for cost\n",
" \"Resource Provisioning\": \"Dynamic\" if mode == \"karpenter\" else \"Static\"\n",
" }\n",
"\n",
"# Convert results to DataFrame for display\n",
"def format_results(results, scenario):\n",
" rows = []\n",
" for provider, setups in results.items():\n",
" for setup, modes in setups.items():\n",
" for mode, metrics in modes.items():\n",
" rows.append([\n",
" f\"Scenario {scenario}: {provider.upper()}\",\n",
" setup.capitalize(),\n",
" mode.capitalize(),\n",
" metrics[\"Scaling Speed\"],\n",
" metrics[\"CPU Utilization\"],\n",
" metrics[\"Memory Utilization\"],\n",
" metrics[\"Cost Efficiency\"],\n",
" metrics[\"Resource Provisioning\"]\n",
" ])\n",
" return pd.DataFrame(rows, columns=[\n",
" \"Scenario\", \"Setup\", \"Mode\", \"Scaling Speed (mins)\",\n",
" \"CPU Utilization (%)\", \"Memory Utilization (%)\",\n",
" \"Cost Efficiency\", \"Resource Provisioning\"\n",
" ])\n",
"\n",
"# Format results for Scenario 1 and Scenario 2\n",
"scenario_1_results = format_results(results, 1)\n",
"scenario_2_results = format_results(results, 2)\n",
"\n",
"# Display results as tables\n",
"from IPython.display import display\n",
"print(\"Scenario 1 Results:\")\n",
"display(scenario_1_results)\n",
"print(\"Scenario 2 Results:\")\n",
"display(scenario_2_results)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.20"
}
},
"nbformat": 4,
"nbformat_minor": 4
}