Multiprocessing
BustAPI v0.8.0 introduces native multiprocessing for maximum throughput.
Quick Start
Python
from bustapi import BustAPI
app = BustAPI()
@app.route("/")
def hello():
return {"message": "Hello, World!"}
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, workers=4)
With workers=4, BustAPI spawns 4 worker processes that share the same port.
Platform Behavior
| Platform | Mode | Performance | How It Works |
|---|---|---|---|
| π§ Linux | Multiprocessing | 100,000+ RPS | SO_REUSEPORT kernel load balancing |
| π macOS | Single-process | ~35,000 RPS | Actix-web internal threading |
| πͺ Windows | Single-process | ~17,000 RPS | Actix-web internal threading |
Linux: SO_REUSEPORT
On Linux, BustAPI uses SO_REUSEPORT for true multiprocessing:
Text Only
ββββββββββββββββββββββββββββββββββββββββ
β Linux Kernel β
β SO_REUSEPORT Load Balancer β
βββββββββββββββ¬βββββββββββββββββββββββββ
β
βββββββββββΌββββββββββ
βΌ βΌ βΌ
βββββββββ βββββββββ βββββββββ
βWorker1β βWorker2β βWorker3β
β PID:1 β β PID:2 β β PID:3 β
βββββββββ βββββββββ βββββββββ
Each worker is a separate process, eliminating Python's GIL bottleneck.
How It Works
- Parent process calls
app.run(workers=4) - BustAPI
fork()s 4 child processes - Each child binds to the same port with
SO_REUSEPORT - Linux kernel distributes incoming connections across workers
- Signal handlers gracefully shut down all workers on
Ctrl+C
Worker Count Recommendations
| Use Case | Workers | Notes |
|---|---|---|
| Development | 1 | debug=True ignores workers |
| Production (4 cores) | 4 | Match CPU cores |
| Production (8 cores) | 8 | Scale with cores |
| High I/O workloads | 2x cores | If I/O-bound |
Performance Benchmarks
Tested on Python 3.13, Intel i5-8365U (8 cores), Ubuntu Linux:
| Workers | RPS (Root) | RPS (JSON) |
|---|---|---|
| 1 | ~25,000 | ~20,000 |
| 2 | ~50,000 | ~45,000 |
| 4 | ~100,000 | ~90,000 |
| 8 | ~105,000 | ~99,000 |
Performance scales linearly up to CPU core count.
Graceful Shutdown
BustAPI handles SIGINT (Ctrl+C) and SIGTERM gracefully:
Text Only
π Starting 4 worker processes (Linux SO_REUSEPORT)...
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BustAPI v0.8.0 β
β http://0.0.0.0:5000 β
β Handlers ............. 5 Processes ........... 1 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
^C
π Shutting down workers...
All workers receive termination signals and exit cleanly.
macOS / Windows Fallback
On macOS and Windows, workers parameter is still respected but uses Actix-web's internal thread pool:
Text Only
[BustAPI] Starting server on macOS (single process mode)...
[BustAPI] Note: Multi-worker mode requires SO_REUSEPORT (Linux only)
The server still runs efficiently using async I/O and threading, but without separate process isolation.
Best Practices
- Always deploy on Linux for production
- Set workers = CPU cores for optimal performance
- Use
debug=Falsein production - Monitor memory - each worker uses ~25-40MB