8

Major web frameworks (such as Django, Pyramid, Rails, etc) are often run as persistent servers, with a separate web server like nginx serving as a frontend. The web server connects via a protocol like FastCGI or SCGI:

browser --[http]--> nginx --[fastcgi]--> flup -> django

This seems convoluted to me; why is the request converted to an entirely different protocol, when the backend could just run its own HTTP server?

browser --[http]--> nginx --[http]--> wsgiref -> django

This approach appears to be both simpler and more flexible, since there's only one transport protocol and it's an RFC.

However, I don't think I've ever seen a web framework encourage the http-only design, so I assume there must be a reason for it.

What are the advantages of using a protocol like FastCGI/SCGI here?

John Millikin
  • 197,344
  • 39
  • 212
  • 226
  • 2
    C++/C probably outperforms those debugging servers any day. Most (all?) of those web frameworks are coded in Python or Ruby, which are interpreted languages. – Blender Jan 19 '12 at 05:23
  • @Blender: While true, that's probably not relevant. I wouldn't expect Django serving via FastCGI to be faster or slower than Django serving via HTTP. Also, neither Python nor Ruby are interpreted. They use bytecode VMs, in a manner similar to Java. – John Millikin Jan 19 '12 at 05:25
  • 1
    Good point. I'm beating my head against a wall getting Flask to work with Lighty... Also, nitpicking, but on the Python homepage it states `... an interpreted, interactive, object-oriented...` – Blender Jan 19 '12 at 05:26
  • Yeah; that description probably dates from when it *was* interpreted. I know 2.x compiles to bytecode, but maybe 1.x was different. – John Millikin Jan 19 '12 at 05:29
  • I seem to remember the Pylons/Pyramid "standard" recommended setup at least being HTTP-only with Apache or nginx as a reverse proxy as you describe here. Django's documentation, too, seems to treat the *CGIs as second-class citizens: "many people use shared hosting, on which protocols such as FastCGI, SCGI or AJP are the only viable options." – John Flatness Jan 19 '12 at 06:36
  • \*CGI *is* a second-class citizen in Django; it is written to WSGI, and everything else requires an adapter. – Ignacio Vazquez-Abrams Jan 20 '12 at 00:11

1 Answers1

8

HTTP is a large, complex protocol. Paring the interface down to the capabilities provided by FastCGI or WSGI allows the framework to handle requests faster than if it had to deal with the original.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358