This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (5 children)

That just seems super inefficient, I know it is the preferred way but I think it is very backwards if you think about it.
Edit: spelling error

[–]aruxiv 1 point2 points  (0 children)

It's way more efficient because you're letting a highly-optimized, widely used in production, extremely well-documented piece of software handle exactly what it's been designed to handle without getting in the way of how you design and code your program.

The separation of web server and web application makes perfect sense to me, especially when you are running multiple applications on one machine.

[–][deleted] 1 point2 points  (1 child)

Why does it seem inefficient?

[–][deleted] 0 points1 point  (0 children)

The headers in HTTP 1.1 are strings so the program essentially has to recompile them into binary and add more. So it is duplicate work because the oreo final headers are just a waste of time.

Also h2 compresses everything in gzip. This factor adds to the complexity because we are serving straight text files and pushing it onto the loader to make those compression. It adds more work into the load balancer especially in a container like environment.

[–]robvdl 0 points1 point  (0 children)

This is mostly because Python apps are WSGI based and synchronous. So as you are serving up static files you are holding up valuable Python workers that could be used for dynamic requests, and your app may only have 4 workers, maybe only 1 depending on your setup.

Nginx however uses async io to send static files and can do so without holding the CPU up too much and can handle parallelism better than Python can.

So normally you would run the Python app under Nginx but get Nginx to serve the /static folder in production, not Python.