Hyperspeed Python Web Framework
Project description
Velocem
This is a Work-In-Progress experimental Python extension. It aims to provide a stupid-fast, pointlessly low-latency, web development framework.
If you use this code in production you get what you deserve.
Motivation
All of the fast Python server-providing web frameworks work off the same basic theory, take fast native IO and HTTP components and bind them to Python. They use slightly different optimization tricks and shortcuts along the way, but that's the shape of things.
A quick survery of the field is presented below.
Framework | IO Library | HTTP Library | Notes |
---|---|---|---|
Bjoern | libev | http_parser | The OG, surpassed by modern frameworks, pioneered most of the micro-optimizations used by later entrants. Notable especially for being the first to take whatever Node.js was doing at the time and applying it to Python. |
Japronto! | libuv via uvloop | picohttpparser | An early example of saying "Screw WSGI!" Every developer working on fast Python web frameworks quickly realizes WSGI is a deadend, to be supported only for compatibility. |
uWSGI | None | None | Never very fast, but written in C and very popular. Worth mentioning because it pioneered the uwsgi protocol as a replacement for HTTP/1.1 for communicating between load balancers and application servers. |
Socketify.py | µWebSockets | µWebSockets | The current industry standard for speed. Spends a lot of implementation effort to maximize compatibility with PyPy, under which it runs 2-3x faster. Still very fast under CPython, but is the undisputed king for PyPy-based stacks. |
emmet / granian | tokio | hyper | Rust! You knew one of these was going to be in Rust. Here it is. The one that's in Rust. |
FastWSGI | libuv | llhttp | The modern successor to Bjoern, King of the "Do What Node Does" Throne. Screaming fast. Real thorn in the side of projects trying to claim to be the fastest WSGI server. Demolishes micro-benchmarks. All server, no framework. |
Velocem | asio (Docs) | llhttp | The one you're looking at right now. Notable for being the only framework on this list primarily written in C++. Will cross any lines and break any rules of software engineering to shave microseconds off the WSGI "Hello World" app. |
What about FastAPI/Starlette/Blacksheep/apidaora/Falcon/My Favorite Web Framework?
Don't provide a server, or only provide a development server. Benchmarks where these run screaming fast are relying on a server-providing framework such as the ones above, so they don't get credit.
What about CherryPy/Gunicorn/Uvicorn/Tornado/Twisted?
Painfully slow, by a factor of 10x or more than the above frameworks. Most of these rely heavily on pure-Python components which means that their latency skyrockets regardless of what IO strategy they implement. Higher latency, lower req/sec, higher resource usage, means you need more application servers to handle a given load.
What exactly is the motivation?
To be the fastest, at everything. WSGI, ASGI, Routing, Velocem's own custom interface, maybe more.
The goal is to be the anchor statistic, the 1x against which everything else is measured in factors of. And, by demonstrating what is possible, hopefully motivating other more commerical, production-oriented frameworks to adopt more performant techniques as well.
What Works
-
WSGI: A complete PEP 3333 implementation, with only the lightest of shortcuts taken. Marginally more conforming than FastWSGI, and ahead by a fraction of a microsecond on benchmarks. Blows everything else out of the water.
-
HTTP/1.1: We parse it and return valid responses. Yippee.
-
Router: Routing is what massacres most benchmarks. The "Hello World" Flask app is 5x slower than the raw WSGI equivalent. A fast router is essential to a fast, low latency application.
Velocem has a very basic router, but it should still be faster than most other implementations. This needs a lot of expansion.
-
Tests: There are a couple of tests. The current testing strategy is "when she segfaults, write a test so the same segfault doesn't happen again". Obviously more work to come here.
-
PyPI: Velocem is available via PyPI, but as this is pre-alpha software and features and fixes make there way in with every single commit, building from source is recommended for those who want to play with this.
What's On Deck
-
Docs: Yes, obviously.
-
Benchmarks: Need a more complete suite of benchmarks than "Ctrl-R for the last
wrk
command we ran" -
sendfile: The single most obvious WSGI optimization, but needs special handling code
-
ASGI: Will likely only support the latest standard. Going to need to implement our own asyncio loop for this to have any shot of being fast.
-
uwsgi Protocol: HTTP/1.1 is non-ideal as a lingua franca for web application backends, uwsgi is an improvement worth exploring.
License
The Velocem source code (and associated build/test/utility files) is released
into the public domain via CC0-1.0, see License
for details.
I (Vito Gamberini) hold no patents and have no knowledge of any patented
techniques used by Velocem. However, some organizations refuse to incorporate or
distribute public domain code due to patent concerns, for this reason Velocem is
additionally licensed for use under MIT-0, see UsageLicense
for details.
The purpose in using these well known legal texts is that they are widely trusted and understood by the open source community. A bespoke legal text might limit usage by particularly skittish developers or organizations. However, I want to make my intentions clear in plain English as well:
Do what you want with this stuff. There are zero restrictions on the use of this code in any context.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file velocem-0.0.12.tar.gz
.
File metadata
- Download URL: velocem-0.0.12.tar.gz
- Upload date:
- Size: 27.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9ec6299d73932e2068592a2d48111ea37719afb68ff3c8df0c8d3972e7c85e0 |
|
MD5 | b8085c15b07b872afdea88a31db58073 |
|
BLAKE2b-256 | 9f7a511a9711f654c87d51c43a12ad11ab21be1925ce6c6960db89106bfc2f6e |
File details
Details for the file velocem-0.0.12-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: velocem-0.0.12-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 333.4 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dd238693f8b9e09552e012bc9196efcac920685a1c2c960eebf45b79520e84d |
|
MD5 | 034f801b80b6269889f5db53285b0248 |
|
BLAKE2b-256 | 69ca136426a70004b066a5ea2aca1fe705f530db43867dcdb0a37a4a930efc0e |
File details
Details for the file velocem-0.0.12-cp312-cp312-manylinux_2_40_x86_64.whl
.
File metadata
- Download URL: velocem-0.0.12-cp312-cp312-manylinux_2_40_x86_64.whl
- Upload date:
- Size: 186.8 kB
- Tags: CPython 3.12, manylinux: glibc 2.40+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac885fd988ba8ac3a2e2c694ca72223f1ec63f36c1b3f18114813f7790327548 |
|
MD5 | 81079c04082fa7f34c618715a038802c |
|
BLAKE2b-256 | e224718167c26c807735efc4500ebc38d2c986d16d018e55e3f40cd189f6a64e |
File details
Details for the file velocem-0.0.12-cp312-cp312-macosx_13_3_arm64.whl
.
File metadata
- Download URL: velocem-0.0.12-cp312-cp312-macosx_13_3_arm64.whl
- Upload date:
- Size: 148.6 kB
- Tags: CPython 3.12, macOS 13.3+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60dba2570037732b52714c1d4ef87aaac7bfe249a89949a5522990044464d00a |
|
MD5 | fe261adc139e7ab0c887864798da76bb |
|
BLAKE2b-256 | c8991c50b79a8c294fc2f5c392320726461db42f67bdff912e2fc4db17518cdf |