spvn
Rust ASGI bindings for python.
Features
- Drop and go CLI for replacing transport layer handling
- ASGI compliant protocols allowing direct import and use of python through rust
- Fast
Sneak Peek
fastapi before fastapi after
- p99 @ 38x
Rationale & Goals
-
Relieve limits by python in networking applications
-
Safe python threadpooling
-
Uvicorn drops requests & stalls on IO > 7500 concurrent clients
-
Hypercorn drops requests & stalls on IO > 7500 concurrent clients
In both, we must horizontally scale to accomodate these limits in our systems. This is further accompanied by essentially a second layer of IO bound processes, which are evidently unable to maintain highly concurrent environments
What spvn does
Delegation of connection multiplex, stream, and IO processes into Rust, and autoinjection at runtime following standard ASGI protocol.
Performance
Tests performed using ali. See ali for methodology.
spvn @ 1000 reqs/s, 30s sustained
- app: fastapi
- file: dotest.bit:app
spvn @ 5000 reqs/s
- app: custom
- file: dotest.baz:app
spvn @ 10000 reqs/s
- app: custom
- file: dotest.baz:app
uvicorn @ 1000 reqs/s
- app: custom
- file: dotest.baz:app
uvicorn @ 5000 reqs/s (DDOS Success)
- app: custom
- file: dotest.baz:app
hypercorn @ 1000 reqs/s
- app: custom
- file: dotest.baz:app
hypercorn @ 5000 reqs/s (DDOS Success)
- app: custom
- file: dotest.baz:app
Installation
spvn is offered as beta currently, keep in mind it has quirks and some features might be untested. for this reason, we dont recommend it for production use yet. if you find a bug, please submit an issue!
pypi
pip install spvn
crates
Developing
Project Status
Roughly in order of priority
-
[✅] Integrate standard import semantics
-
[✅] PyCaller
- [✅] (rust) Async safe integration
- [✅] Abstract (py fn) async / sync handle
- [✅] Caller pool [this will be revised, its too slow]
-
[✅] Standard asgi traits & structs
- [✅] ASGIScope
- [✅] (rust) Async safe integration
- [✅] Conversion from
tower::Body
->dict
- [✅] ASGIVersion
- [✅] ASGIMessage
- [✅] Lifecycle Scope
- [✅] HTTP Lifecycle Scope
- [🚧] Websockets (msg integration)
- [✅] ASGIScope
-
[✅] App listener
-
[✅] App dispatcher
- [✅] Async threadsafe
- [🚧] Lifecycle activation for caller objects (unstable)
-
[🚧] App scheduler
- [✅] Injectable
awaitables
(rust ptr -> python ptr) - [✅] Async threadsafe
- [✅] Delayed py-fn call
- [🚧] Scheduler into py
- [✅] Injectable
-
[🚧] Live reloader
-
[🚧] Websockets
Pre-requisites
Python >= 3.9
- Use virtualenv / venv
python3.10 -m (venv|virtualenv) env && \
. ./env/bin/activate && \
pip install maturin
- Test bindings by running
maturin develop
Rust >= 1.69.0
- Build CLI
cargo build
- Run CLI
cargo cli serve dotest.foo:app