5 ms·
CGI was abandoned due to performance problems, but it is surprising scalable on modern OSs, the kernel does a good job of caching the code so it's not really a
by samwillis 4y ago
CGI was abandoned due to performance problems, but it is surprising scalable on modern OSs, the kernel does a good job of caching the code so it's not really a full round trip to the file system and cold start on each request. Obviously you still have the overhead of an interpreter for many languages, but they also tend to do a fairly good job of caching their byte code. I absolutely wouldn't recommend it for new systems, but for a quick and dirty script it's fine.
The minute you want to do url routing and have middleware, a persistent process makes everything much simpler and keeps everything in one place. I much prefer routing inside a framework than using Mod_Rewrite.
Edit: This article covers what I was thinking of:
"Myths About CGI Scalability"
http://z505.com/cgi-bin/qkcont/qkcont.cgi?p=Myths%20About%20CGI%20Scalability http://z505.com/cgi-bin/qkcont/qkcont.cgi?p=Myths%20About%20...
Previously discussed:
https://news.ycombinator.com/item?id=32699395 https://news.ycombinator.com/item?id=32699395
- geenat 4y agomod_rewrite hasn't been necessary since nginx. 2023 - Use single binary caddy. It's like 2 lines of config total to remove the extension from your CGI url's.
- samwillis 4y agoAbsolutely, and Caddy is brilliant. My point really was when having url routing, such as ids/slugs in the url, it is much easier to implement in your application code than in the web server configuration. It keeps application code in one place.
- liveoneggs 4y agoWhat does nginx have to do with mod_rewrite?
- ptx 4y agonginx hasn't been necessary since mpm_event_module.
- ilyt 4y agoapache haven't been necessary since nginx.
- qbasic_forever 4y agoCaddy doesn't support CGI out of the box. You need to use a module (which requires a custom build of it and the hope the module author continues to maintain it), or you need to run something like fcgiwrap to convert FCGI (what Caddy does support) to CGI (and now you need a process manager to make sure your fcgiwrap and caddy processes are kept running, restarted on failure, etc).
- scotty79 4y ago> a persistent process makes everything much simpler ... I started with PHP and never trusted persistent processes for anything. What if your persistent process hangs or crashes for whatever reason? Is your whole site down then, not just the part with the bug? The only site I ever made in persistent process paradigm was in ASP.NET and it didn't cause too many problems but it was more of an app, not website, with limited number of logged in users and pretty much no anonymous/guest part.
- wizzwizz4 4y ago> What if your persistent process hangs or crashes for whatever reason? You've got the same problem with your web server, and your operating system kernel. Simply write a program that can't hang or crash – at least, not due to an application bug. It takes attention to detail, but this is a lot easier than writing a program that always behaves correctly; if you limit the syscalls you make, use timeouts appropriately, and don't segfault, it's often achievable.
- scotty79 4y agoI don't think any mainstream framework in any mainstream language has these kinds of precautions. Rails? Django? Express? .NET? Do they kill long running requests so they don't affect whole application? Can the application still mostly work despite syntax error in one of the files? Another thing is level of trust. I trust Linux kernel, I trust apache webserver. But some webserver written in scripting language few years ago? Not so much.
- Semaphor 4y ago> .NET? Do they kill long running requests so they don't affect whole application? Not sure about the built-in .net server, but IIS does exactly that. It supports timeout and error/time based restarts for the persistent process.
- alerighi 4y agoWell try in a nodejs server to put a `while(true);` in a request handler. Do you know the answer? The whole process blocks, since nodejs is single process. I trust more the code that I wrote than the code written from others... not because I'm better than others, but because I know what it does, and I know how to fix it if it breaks.