Re:Granian – a Rust HTTP server for Python applications
by laurencerowe on Monday January 16, 2023 @09:19PM
(#34408398)
Forking can be quite slow (milliseconds), though there are techniques to speed it up: https://www.cs.purdue.edu/homes/pfonseca/papers/eurosys21-od...
I believe wasmtime can be faster as it doesn’t need to create as many new OS resources and just resets some memory maps.
Only really meaningful for simple request handlers taking a few milliseconds.
Theoretically one could produce ready-to-run, guaranteed clean Python request handlers very quickly. Run all the startup and imports stuff in a Python process, then freeze it. Fork a copy of it on a new request (with COW it's definitely fast), and terminate it normally after that. This would require some care, e.g. to not open sockets before the fork, so that handlers won't share it.
I bet it has been tried, but I'm too lazy to actually search for that.