Back before serverless, we called it shared hosting.
Of course, fork() is not especially fast, so people came up with Fastcgi: persist the process and let it handle multiple requests. Then people started writing java where the startup time was prohibitive, and "application servers" like Tomcat came into being.
fork itself is pretty fast, relatively speaking (unless you have a large virtual address space and 4K pages or similar). fork+execve+process-runtime-initialization is much slower.
On my X201 (anno 2010), with 10000 iterations, sequential fork+exit(0)-in-child+wait takes:
$ /usr/bin/time ./forkfest
2,49 real 0,38 user 2,19 sys
while sequential fork+execve("/usr/bin/true",...)-in-child+wait takes: $ /usr/bin/time ./forkfest2
10,99 real 3,10 user 7,94 sys
EDIT: also, My X201 is clocked at 1199 MHz (50%) for power saving reasonsYou're right, but Windows was different. In Windows/Asp.Net land (which was a good chunk of shared hosting in the early 2000s), Shared Hosting providers were using AppDomains to isolate sites. IIRC, AppDomains were isolated by the .Net runtime rather than more robust process isolation.
FastCGI is a classic example of second-system syndrome. I once looked at the spec. It was ridiculously overdesigned. SCGI (Simple CGI) solves the same problem (reusing a server process for multiple requests), but its spec literally fits on two pages: http://www.python.ca/scgi/protocol.txt - It's also supported by nginx by default. (Don't know about Apache etc.)
CGI was abandoned because of the slowness of process forking, but with modern kernels, new compiled languages, and better reverse proxy servers, I believe that the speed difference is trivial in regards to the advantages:
- Deployment can be done by simple file upload.
- Process isolation adds security and reliability.
- CGI scripts/binaries are vendor agnostic and can be run/tested locally
- CGI scripts can use any language, are stateless, promote hyper modular design (aka functions) and are generally minimalistic in nature.
[1] https://bigcgi.com/ [2] https://github.com/bmsauer/bigcgi
Are you thinking something like "FastCGI, except over stdin/out instead of a listening socket"? Since that sounds like it could work pretty efficiently if (unlike nginx's fcgi implementation) it supported multiplexing.
I like the idea of communication via stdin/stdout though, I'll add that to my notes.
I actually was going to remove that from the roadmap entirely, because lately I really like the process isolation and statelessness of regular CGI.
Thanks for your comment!
Shared state and locks are evil.
https://en.wikipedia.org/wiki/2017_block_of_Wikipedia_in_Tur...
But actually, Lambda can keep your server open to serve multiple requests without spawning new processes all the time.
I realized that the key feature is not having the server open all the time, only when necessary. So I took systemd's socket activation idea and added socket deactivation, i.e. sending SIGTERM to the server after a period of inactivity: https://github.com/myfreeweb/soad
Plus, one of the things that really deserves more hype and popularity is CloudABI https://nuxi.nl an ABI that lets you have one binary that runs on multiple operating systems as is and always runs sandboxed.
The serverless runtime of my dreams just takes CloudABI binaries (packed with files in a tarball) that listen for HTTP on a given socket, and does the activation-deactivation thing to only run on demand :)
In that regard, it's closer to FastCGI than CGI itself.