By Brandon Mahdavi
This project implements and tests three load-balancing strategies in Python:
- Round Robin
- Weighted Round Robin
- Consistent Hashing (with virtual nodes / replicas)
load_balancer.py: CoreLoadBalancerclass and strategy routing logic.server.py:Servermodel withid,weight, and request counter.consistent_hash.py: Hash-ring implementation (add_node,remove_node,get_node).simulation.py: End-to-end simulation over 10,000 requests.analysis.md: Required analysis for resilience, stability, and replica distribution.tests/test_lb.py: Unit tests for all strategies and edge cases.
- Python 3.12+ (Python 3.x works for this codebase)
Run all unit tests:
python3 -m unittest discover testsRun the simulation:
python3 simulation.pyOr use the Makefile shortcuts:
make test
make run- Unit tests passing:
21/21 - Simulation scenarios completed:
- Round Robin
- Weighted Round Robin
- Consistent Hashing
- Replica comparison (
1,3,50,150replicas) - Resilience test after server removal
- Consistent hashing distribution with only 3 replicas is intentionally uneven.
- Increasing replica count improves load balance significantly.
Built for the load-balancing unit of SDSU's CS496 (cloud computing). The module and test stubs were provided by the course; the strategy implementations, hash ring, tests, simulation scenarios and analysis are mine.