Skip to main content

Load Balancer

Simple FastAPI load balancer

pip install load-balancer

Usage

from multiprocessing import Process
from fastapi import FastAPI
import uvicorn
from load_balancer import session_affinity, # or round_robin

myapp = FastAPI()
# ...

NUM_WORKERS = 4
UDP_PATHS = [f'udp-{i}.sock' for i in range(NUM_WORKERS)]
balancer = session_affinity(UDP_PATHS)

procs = [Process(target=uvicorn.run, args=(balancer,))] + [
  Process(target=uvicorn.run, args=(myapp, path))
  for path in UDP_PATHS
]

for proc in procs:
  proc.start()

for proc in procs:
  proc.join()

Download files

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

Source Distribution

load_balancer-0.1.1.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

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

load_balancer-0.1.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file load_balancer-0.1.1.tar.gz.

File metadata

  • Download URL: load_balancer-0.1.1.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for load_balancer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a6ac86771d082c944a4d77bdd1c788621dcb01bed1c93ddca23f7da26bcb2acb
MD5 7fc905389c579e3fb7832f1d0cbf793d
BLAKE2b-256 52bccefe1efaad7c73c3969cb1d47c7ec8c2a3c7d4d7fec1083ba1ab8a4f8235

See more details on using hashes here.

File details

Details for the file load_balancer-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: load_balancer-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for load_balancer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a0262aa236bb8dc2c4a43e631fae67ef2ae469becc22601177c2715179a8279a
MD5 a23946ebbf613954bcfb8da46d6ebc24
BLAKE2b-256 c8c7d255cd4aabc48e0d554d5bfbd1e135ba213168c549c09b32f8e0f413c41b

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

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