Live data from Hacker News

I recommend CGI instead of web frameworks

halestrom.net

11–20 of 89 posts

Re: I recommend CGI instead of web frameworks

#11
post #3

Earlier quoted context omitted.

How about FCGI?

It's a bit better but one process can only process one request at a time. You need a lot more processes compared to a http framework processing http requests in parallel.

How do those web frameworks gain the ability to process things in parallel? What prevents a ‘single process’ from adopting those same methods?

Re: I recommend CGI instead of web frameworks

#12
The reason most Python folks moved away from CGI more than two decades ago now is that the performance is terrible. The interpreter startup time (plus any time executing module imports) has to run per request. This is much less of an issue for shell scripts which startup very quickly.

The programming model does have its advantages though. Persistent servers risk leaking information across requests (seems to be a particular risk in async programming systems where requests execute concurrently in the same thread) so there's a definite advantage to isolation between requests. I'd love to see a server that used per-request v8 isolates (with snapshots for fast startup time.)

Re: I recommend CGI instead of web frameworks

#13
This text seems like it is stuck in time. I wouldn't be able to do most of the stuff I am doing without libraries and frameworks. It would simply take so much time redoing the same shit that others have done before so I couldn't finish my task at hand and solve the problems I actually care about.

Plus, just look at this dudes website. Sure it works just fine but it's nearly impossible to read on my large screen. It feels like it was designed for an older CRT screen and has never been updated since.

I wonder how people like this can survive in todays world with the requirements people have on web software. You will sooner or later be out competed by a guy using a web framework.

Re: I recommend CGI instead of web frameworks

#14
The only downside of CGI that I know about is the fact it starts a new process to handle each user request.

When you're saying it's preferable to serverside web frameworks you probably ought to point out that it does far less for you. I started out in web dev working on Perl CGI scripts and they were great (once you got your FTP app to use the right CRLF encoding), but you really had to do everything yourself. Some devs might see that as a benefit but I don't.

Re: I recommend CGI instead of web frameworks

#15
I’m all for simplicity, but I don’t understand why the author treats CGI as a beacon of simplicity. In the example of teaching students, I wouldn’t start with dynamic websites at all. You can introduce requests, pages, urls, etc., in the context of static sites or front end development. Then it should be fairly easy to see the patterns that flask is abstracting away.

Most websites are either primarily static, with no server side code, or they’re fully dynamic, where every page is generated. CGI shines when sites are a mix.

One other alternative to CGI that the author doesn’t mention is reverse-proxying a single page. I find that to have more practical use than CGI.

Re: I recommend CGI instead of web frameworks

#16

The reason most Python folks moved away from CGI more than two decades ago now is that the performance is terrible. The interpreter startup time (plus any time executing module imports) has to run per request. This is much less of an issue for shell scripts which startup very quickly. The programming model does have its advantages though. Persistent servers risk leaking information across requests (seems to be a part…

You'll find that the isolation goes out of the window when you need sessions; they need to be stored somewhere that persists across requests.

Re: I recommend CGI instead of web frameworks

#17
CGI really is a beautiful abstraction.

The reason we stopped using it 15+ years ago was performance: forking a new process for every incoming web request just didn't make sense on ~2000 era hardware.

I wonder how true that is today, given that our machines have vastly more RAM and CPU?

If you squint at them the right way AWS Lambda functions are pretty similar to the CGI model.

Re: I recommend CGI instead of web frameworks

#19
post #3

Earlier quoted context omitted.

How about FCGI?

It's a bit better but one process can only process one request at a time. You need a lot more processes compared to a http framework processing http requests in parallel.

Fcgi apps can handle requests in parallel in a single process just fine, as long your environment supports it.

Re: I recommend CGI instead of web frameworks

#20
A somewhat related naive question: is anyone using FastCGI (or just CGI) to interface directly with a web server like Apache, NGINX, or Caddy for their web apps? What reasons would you choose to not interface with use these web servers directly?

These web servers are battle-tested and feature-rich. If you add another layer like an application server (Puma, Gunicorn etc) that sits between the server and your programming language does the application server end up duplicating some (most?) of the functionality of the web server?

Post reply on HN