Skip to main content

High-performance intelligent routing algorithms for optimizing request distribution across accelerators (GPUs, TPUs)

Project description

Intelligent Routing

PyPI version License: MIT

A high-performance Rust library implementing intelligent routing algorithms for optimizing request distribution across thousands of accelerators (GPUs, TPUs, or other compute units).

Overview

This project provides a flexible and efficient load balancing system designed to distribute computational workloads across large clusters of hardware accelerators. It implements multiple routing strategies that can be easily swapped based on workload characteristics and performance requirements.

Features

  • Multiple Load Balancing Strategies

    • Round Robin with failover
    • Least Connections
    • Power of Two Choices (P2C)
  • Scalable Architecture

    • Designed to handle thousands of accelerators
    • Efficient O(1) or O(log n) routing decisions
    • Thread-safe implementations using atomic operations
  • Flexible Configuration

    • Pluggable strategy pattern for easy algorithm switching
    • Configurable accelerator capacity
    • Request priority support
  • Simulation & Benchmarking

    • Built-in simulation framework
    • Load distribution statistics
    • Performance metrics (throughput, latency)

Installation

Python Package (Recommended)

Install directly from PyPI:

pip install intelligent-routing

From Source (Development)

# Clone the repository
git clone https://github.com/yourusername/intelligent_routing.git
cd intelligent_routing

# Create virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install maturin and build
pip install maturin
maturin develop

Rust Library

Add to your Cargo.toml:

[dependencies]
intelligent_routing = { git = "https://github.com/yourusername/intelligent_routing.git" }

Or clone and build locally:

git clone https://github.com/yourusername/intelligent_routing.git
cd intelligent_routing
cargo build --release

Quick Start

Python Usage

import intelligent_routing

# Create accelerators
acc1 = intelligent_routing.Accelerator(1, 100)
acc2 = intelligent_routing.Accelerator(2, 100)

# Initialize router with a strategy ("round_robin", "least_connections", "p2c")
router = intelligent_routing.Router("p2c")
router.add_accelerator(acc1)
router.add_accelerator(acc2)

# Route a request
req = intelligent_routing.Request(1, 10, 1)
acc_id = router.route_request(req)

if acc_id is not None:
    print(f"Routed to accelerator {acc_id}")

Rust Usage

use intelligent_routing::accelerator::Accelerator;
use intelligent_routing::request::Request;
use intelligent_routing::router::Router;
use intelligent_routing::strategies::p2c::PowerOfTwoChoices;

fn main() {
    // Create accelerators
    let mut accelerators = Vec::new();
    for i in 0..1000 {
        accelerators.push(Accelerator::new(i, 100)); // 100 capacity units each
    }

    // Create router with Power of Two Choices strategy
    let strategy = Box::new(PowerOfTwoChoices::new());
    let mut router = Router::new(strategy);
    
    for acc in accelerators {
        router.add_accelerator(acc);
    }

    // Route a request
    let request = Request::new(1, 5, 1); // id=1, cost=5, priority=1
    match router.route_request(&request) {
        Some(acc_id) => println!("Request routed to accelerator {}", acc_id),
        None => println!("No available accelerator"),
    }
}

Run Rust Simulation

cargo run --release

Choosing a Strategy

// Round Robin - Simple sequential distribution
let strategy = Box::new(RoundRobin::new());

// Least Connections - Route to least loaded accelerator
let strategy = Box::new(LeastConnections::new());

// Power of Two Choices - Optimal balance of performance and distribution
let strategy = Box::new(PowerOfTwoChoices::new());

Architecture

intelligent_routing/
├── src/
│   ├── lib.rs              # Library exports
│   ├── main.rs             # Simulation entry point
│   ├── accelerator.rs      # Accelerator (compute unit) model
│   ├── request.rs          # Request model
│   ├── router.rs           # Core router and strategy trait
│   ├── bindings.rs         # Python bindings (PyO3)
│   └── strategies/
│       ├── mod.rs          # Strategy module exports
│       ├── round_robin.rs  # Round Robin implementation
│       ├── least_connections.rs  # Least Connections implementation
│       └── p2c.rs          # Power of Two Choices implementation
├── tests/
│   ├── test_routing.py     # Python unit tests
│   └── scale_test.py       # Performance benchmarks
├── doc/
│   ├── architecture.md     # System architecture documentation
│   ├── strategies.md       # Load balancing strategies guide
│   └── api.md              # API reference
├── Cargo.toml              # Rust dependencies
└── pyproject.toml          # Python package configuration

Performance

Benchmark results with 10,000 accelerators and 100,000 requests (Python Wrapper):

Strategy Throughput Success Rate
Power of Two Choices ~550,000 req/s 100%
Round Robin ~800,000 req/s 100%

Note: Results may vary based on hardware and configuration. P2C provides better load balancing at the cost of slightly lower throughput compared to Round Robin.

Load Balancing Strategies

Round Robin

Distributes requests sequentially across all accelerators. Simple and fast, but doesn't consider current load.

Least Connections

Always routes to the accelerator with the lowest current load. Optimal distribution but O(n) complexity per request.

Power of Two Choices (P2C)

Randomly samples two accelerators and picks the less loaded one. Provides near-optimal load distribution with O(1) complexity. This is the recommended strategy for most use cases.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup

# Clone the repository
git clone https://github.com/yourusername/intelligent_routing.git
cd intelligent_routing

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install development dependencies
pip install maturin pytest

# Build and install in development mode
maturin develop

# Run tests
pytest tests/ -v

# Run scale benchmarks
python tests/scale_test.py

Building Wheels

# Build wheel for current platform
maturin build --release

# Build wheels for multiple platforms (requires appropriate setup)
maturin build --release --target x86_64-unknown-linux-gnu

Publishing to PyPI

# Build release wheel
maturin build --release

# Upload to PyPI (requires PyPI credentials)
maturin publish

# Or upload to TestPyPI first
maturin publish --repository testpypi

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

For detailed documentation, see the doc/ folder:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

intelligent_routing-0.1.0.tar.gz (21.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

intelligent_routing-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (242.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

intelligent_routing-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (229.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

intelligent_routing-0.1.0-cp311-cp311-win_amd64.whl (136.2 kB view details)

Uploaded CPython 3.11Windows x86-64

intelligent_routing-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (241.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

intelligent_routing-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (228.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

intelligent_routing-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (210.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

intelligent_routing-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl (218.2 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

intelligent_routing-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (241.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

intelligent_routing-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (228.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

intelligent_routing-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (241.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

intelligent_routing-0.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (229.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

intelligent_routing-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (241.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

intelligent_routing-0.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (228.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

File details

Details for the file intelligent_routing-0.1.0.tar.gz.

File metadata

  • Download URL: intelligent_routing-0.1.0.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for intelligent_routing-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8d23c6ff6869af60969f7d3d723c72f286e68c713dcfcce675843d6f61e37cbd
MD5 93e1428888bbcea864d71487279c5bea
BLAKE2b-256 1cf7335f40bcc8e418a51c1877f0eadba130f538a2e946aa0877763d2b697b60

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0.tar.gz:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c5ebed7eac8302784f2a502eac06c3f32bdd594a5093b02dfb996eec6ecd8798
MD5 ccef405a3dd1a0d11b996eb20d44f449
BLAKE2b-256 06c648a277056b7c3d23bf53901141f96baa1d07ca413e54910f0ce016996ad7

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8677330e17010e894b1a672002c93c5ebb99af31b58bd50503fe18659d98d78c
MD5 ce7f10fcaaf6a951cd1d770c7b95042e
BLAKE2b-256 1b6e3c323030f9bfabacb51b3d2cedf45fca4323590afa5d65ae9a2fa4f1d3e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 43a125c4b47f03dd72dd036e1142cdb409b27e14084ae60d77d4be8286f06b63
MD5 06a99aef5ffd1d6b1503eb039c881631
BLAKE2b-256 ad4e8e25945d564c3bda3cabd4588518b7f068b00d26f1297a0d76aa379cb497

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef872d48bee790e015f9e63b243e64184e3a975ba545c1278700ff0bae63ebd3
MD5 9a21df4ac5b73c3af6d85c4084e5b14f
BLAKE2b-256 b66ccd77f1c8b442b4431f8f6dc34d927dab1d2f5e07e7f07b48d01901bc7837

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 313330b32741413b88714fb275e259dd4d877f3db6858e01abf4e852661ae669
MD5 384a0dd3abf188a7df9bc687b1dff946
BLAKE2b-256 0c466bb5bee2be5036012e6208783371bcc8a1c204d3bfd5ade12ec4b7d67eff

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af2d522209958a5ae7b0a3071245750c37bde200d22cee8ee0ae23ef267a701a
MD5 e86bbce66ee33687176adf15fd998092
BLAKE2b-256 6118e1391d1c2a9eae7cf001ec5d606d0c1b546ca93b8f4680c0bf6913d0c0df

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1c904471e03ef10747195b108911627a5e540eb47c86ba213a854cd5b7e11518
MD5 fbe3ae31b7b03405cf41490c6ee4ad56
BLAKE2b-256 c7537c6fff4fafb51ed4cd58e71de3ac94aa648728ce861b8760831bf45c1e82

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3a41a1fea5918c6693299966bf15679ec12ab8caad68299d4e85fa90c9892571
MD5 b7d4d57bcf935f9a1e572497ed36fd69
BLAKE2b-256 a90bb4a9592cc612c573e756b24dc2e85f1a152e54830f1f0726be499ae15840

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 72a98849f2865de16512efcfaea4fbed945352e745cac7835fbcf889840d19a4
MD5 c3b8dcc2e5798d691465b5bf42a7d25e
BLAKE2b-256 5f871bd78e2d6cbce605d364315fa6014fe2ab99762fe15705584ae331722a62

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d3d60788ac679ad714b6301c2dcf7b0650b51fe9a783642a7cedac2e66f7c80d
MD5 dc953b8e7b4882f0e20ba670e614be0f
BLAKE2b-256 5c4698456fe738edd4c5ae28510bfe6ec945fba469da9b18c7e2eb142f90f1cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ed6324c437bdbe57c29d73054c1a7dbe767201c0c2a939fd997710b3044bac7c
MD5 5253ee471315a797dacbb207c52a5657
BLAKE2b-256 6e5451fc34926b7056755f88b2b9a30f2f1f61f4e16ecbbd587453793be5d36b

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d4f0dfe411197c7e9a244135a6849e8f4cc27176778d3cbe724370c91b07a172
MD5 2a8d30a6176d2d8d97dc1250596e9227
BLAKE2b-256 cd1f16bb634ba01cb32716a8a0d289569f219fd5494f3254113b1c4249c221c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file intelligent_routing-0.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for intelligent_routing-0.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 813333116674da1b4747c6aee76007b15eefa6ccfeb9ee9de44909bd2b0f7ed6
MD5 601bdfabd59eb5e1673c7467bc4bccb8
BLAKE2b-256 3059836490fadd8d6d57dfa5a7f1e228662a1bbf6bc699d0931bc9e95f9304b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for intelligent_routing-0.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on DevJadhav/intelligent_routing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page