This project implements a discrete-event simulation (DES) of a three-tier e-commerce web application using SimPy. It is designed as a full course project for studying capacity planning, performance, and cost optimization under variable load.
- Three-tier architecture:
- Web server pool
- Application server pool
- Database + cache layer
- Time-varying, non-homogeneous Poisson arrivals with daily pattern and load multipliers
- Detailed per-request timings across tiers
- Support for multiple scenarios:
- Web/app server scaling
- Cache hit ratio impact
- Load multipliers (1x/2x/3x)
- Combined “optimal configuration” search
- Multiple replications per scenario with random seeds and 95% confidence intervals
- Automatic storage of raw results and aggregated metrics
- Plotting utilities for all major figures required by the report
For development and verification, a reduced test configuration is available:
- 10 req/s (vs 100 req/s baseline)
- 1 hour simulation (vs 24 hours)
- 3 replications (vs 10)
- ~10,800 total requests (vs ~8.64 million)
This runs in ~10 seconds and produces the same metrics as the full simulation.
project/
├── src/
│ ├── simulation.py # Core SimPy model
│ ├── metrics.py # Metrics collection and statistics
│ ├── config.py # Baseline and scenario configurations
│ ├── experiments.py # Scenario definitions and experiment runner
│ └── visualization.py # Plotting and figure generation
├── data/
│ ├── raw_results/ # Raw per-run outputs
│ └── processed/ # Aggregated metrics
├── figures/ # Generated plots for the report
├── notebooks/
│ └── analysis.ipynb # Interactive analysis (optional)
├── requirements.txt # Python dependencies
├── run_all_experiments.py # Master script to run all scenarios
└── README.md
- Create and activate a virtual environment (recommended).
- Install requirements:
pip install -r requirements.txt-
First, test the simulation (runs in ~10 seconds):
python run_all_experiments.py --test
-
Run baseline configuration only:
python run_all_experiments.py --baseline
-
Generate figures with real + synthetic data (recommended):
python generate_figures.py --combined
This uses your simulation results for available scenarios and fills in synthetic data for others.
-
Run all predefined experiments (~30+ minutes):
python run_all_experiments.py
-
After runs complete:
- Raw CSVs will be under
data/raw_results/ - Aggregated summaries under
data/processed/ - Figures under
figures/
- Raw CSVs will be under
-
Open
notebooks/analysis.ipynbin Jupyter for further exploration and to support the 15+ page report.
- The code is structured to map directly to the report sections:
- Conceptual Model / Simulation Design →
simulation.py,config.py - Data & Input Analysis → traffic and service-time utilities in
config.pyand plots invisualization.py - Experimentation & Results →
experiments.py,run_all_experiments.py,metrics.py
- Conceptual Model / Simulation Design →
- Use the generated CSVs and figures as the basis for tables, charts, and analysis described in the project prompt.