Skip to main content

Tenant-aware request scheduling for LLM inference. Cuts premium-tenant p99 latency 60-70% on a contested GPU at <5% extra cost.

Project description

guarded-hotshard

Tenant-aware request scheduling for LLM inference. On a contested GPU, cuts premium-tenant p99 latency by 60-70% at a small cost premium and ~98% output fidelity vs the no-scheduling baseline.

Drops in front of any OpenAI-compatible backend - vLLM, Ollama, llama.cpp, OpenAI, Together, Anyscale - in one of two ways:

  • wrap() an OpenAI client in two lines. No proxy.
  • ghs serve runs an OpenAI-compatible reverse proxy with priority scheduling and bounded redundancy.
from openai import OpenAI
from guarded_hotshard import wrap

client = wrap(
    OpenAI(base_url="http://localhost:8001/v1", api_key="-"),
    mode="protected_lane",
    critical_users={"acme-prod"},
)

client.chat.completions.create(
    model="Qwen/Qwen2.5-3B-Instruct",
    messages=[{"role": "user", "content": "hi"}],
    user="acme-prod",        # premium tenant -> protected lane
)

That's the integration. Premium traffic flows through a priority lane with optional bounded re-execution; bulk traffic shares the rest of the backend's capacity.

The headline

A real GPU at saturation has a queueing problem. Every request waits behind every earlier request, and a noisy bulk tenant pushes premium traffic's p99 to the same place as everyone else's. guarded-hotshard fixes that with tenant-aware priority scheduling and a per-window redundancy budget for premium traffic.

Real-GPU benchmark - Colab Pro A100 with Qwen2.5-3B-Instruct, 150-request multi-tenant chat workload:

Pareto frontier

baseline (no scheduling)  T0 p99: 22.95 s
protected_lane            T0 p99:  6.77 s   (-70.5%, ~8% cost premium)

The OSS defaults shipped here ship as conservative starting points. Demo results may land closer to 50-65% p99 reduction depending on workload shape; workload-specific tuning is what closes the gap to the headline number above.

Install

pip install guarded-hotshard                # core
pip install 'guarded-hotshard[server]'      # + proxy
pip install 'guarded-hotshard[demo]'        # + Pareto chart
pip install 'guarded-hotshard[all]'         # everything

Requires Python 3.10+.

Run the proxy

ghs serve \
    --backend http://localhost:8001 \
    --port 8000 \
    --mode protected_lane \
    --critical-users acme-prod,bigco-tier1 \
    --concurrency 8

Point your client at port 8000 instead of port 8001 and use the OpenAI user field to identify tenants.

See examples/vllm_proxy.md for vLLM, examples/ollama_proxy.md for Ollama.

Run the demo against your own backend

ghs demo \
    --backend http://localhost:8001 \
    --model Qwen/Qwen2.5-3B-Instruct \
    --requests 150 \
    --concurrency 8

Generates a Zipf-skewed multi-tenant workload, runs every public mode, prints a per-tenant p99 table, and saves a Pareto chart and per-request CSV under demo_results/.

Modes

ghs modes

baseline, eco, balanced, protected_lane, critical. Most users want protected_lane with their premium tenants in --critical-users.

How it behaves

Each request is scored by tenant identity, criticality, and observed load. A small per-window budget caps how many requests are eligible for redundant execution, so worst-case cost is bounded by configuration. The scheduler runs in two flavors: an in-process priority queue used by wrap(), and an async dispatcher used by the proxy. On any failure - timeout, malformed response, network error - it falls back to a direct call. It can't be worse than the backend alone.

What this proves vs what it doesn't

Measured on real hardware:

  • 150 chat requests, 5 tenants, Zipf alpha=1.2, multi-seed.
  • Colab Pro A100-40GB, Qwen/Qwen2.5-3B-Instruct.
  • Modeled $/M tokens at $4/hr GPU. (Modeled, not billed.)

Not yet proven:

  • Multi-GPU scheduling (single A100 only).
  • Larger models (>3B).
  • Long context (>2k tokens).
  • Real cloud billing.
  • Sustained traffic (>1000 reqs).

If any of those are blockers for you, get in touch via Issues.

License

Apache-2.0. See LICENSE and NOTICE.

For commercial support, workload-specific tuning, multi-replica scheduling, or an enterprise build, open an Issue or reach out via the GitHub repository.

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

guarded_hotshard-0.1.0.tar.gz (33.6 kB view details)

Uploaded Source

Built Distribution

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

guarded_hotshard-0.1.0-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: guarded_hotshard-0.1.0.tar.gz
  • Upload date:
  • Size: 33.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for guarded_hotshard-0.1.0.tar.gz
Algorithm Hash digest
SHA256 685a1257d1aff52b56b2c24e338ea1b79fae1ada04a55257d326d3f8836da3ab
MD5 dd1940b818a0d3052ec8700cb429a0ba
BLAKE2b-256 3351de949b32d7394b5b833239ee2477655bc5877bfbabe6d734854f7714f5dc

See more details on using hashes here.

File details

Details for the file guarded_hotshard-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for guarded_hotshard-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c412827e3397e0a4a77b354ded6e72cb20af6653110b1819216c4091d045abb6
MD5 d2f9eaf9adfb9aae1fb15f2a2a013e10
BLAKE2b-256 d0ad51bdd1d251680e2250c92ab00fd993b9762f3937125801e77b4481ba83ed

See more details on using hashes here.

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