Skip to content

About

Round robin, weighted round robin and consistent hashing (virtual-node hash ring) load balancer in Python, with simulation and analysis of resilience, stability and replica distribution.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Load Balancing and Consistent Hashing Project

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)

Project Files

  • load_balancer.py: Core LoadBalancer class and strategy routing logic.
  • server.py: Server model with id, 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.

Requirements

  • Python 3.12+ (Python 3.x works for this codebase)

How To Run

Run all unit tests:

python3 -m unittest discover tests

Run the simulation:

python3 simulation.py

Or use the Makefile shortcuts:

make test
make run

Current Verification Status

  • Unit tests passing: 21/21
  • Simulation scenarios completed:
    • Round Robin
    • Weighted Round Robin
    • Consistent Hashing
    • Replica comparison (1, 3, 50, 150 replicas)
    • Resilience test after server removal

Notes

  • Consistent hashing distribution with only 3 replicas is intentionally uneven.
  • Increasing replica count improves load balance significantly.

Background

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.

About

Round robin, weighted round robin and consistent hashing (virtual-node hash ring) load balancer in Python, with simulation and analysis of resilience, stability and replica distribution.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages