Re:Granian – a Rust HTTP server for Python applications
by laurencerowe on Monday January 16, 2023 @07:54PM
(#34407767)
One of the nice things about CGI was that by starting a new process per request it provided isolation between requests. Python's startup overhead obviously makes CGI untenable, but I find the new Web Assembly runtimes interesting because they are able to provide extremely fast startup by reseting state: https://bytecodealliance.org/articles/wasmtime-10-performanc...
[ Parent
| on HN ]
Re:Granian – a Rust HTTP server for Python applications
by nine_k on Monday January 16, 2023 @08:26PM
(#34408029)
PHP was built around this idea for decades %)
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.
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.