0

The main advantage of Nginx is cited as it not needing to spawn separate threads for each request it receives.

Now, if we were to run a python based web application using FastCGI, and this web application has blocking calls, would this create a bottleneck?

Since there is only a limited number of workers running(1 per processor?), wont a blocking call by a python script make it cooperative multiprocessing?

3
  • Why would you run a Python app through nginx with FastCGI? You would use wsgi. Commented Jun 11, 2015 at 20:46
  • 1. Okay, maybe it's not an advantage per se, call it a feature. 2. As I understand WSGI is an interface, and there is a WSGI wrapper over FastCGI. 3. Yes, Apache can spawn processes. But the whole point is not to spawn processes. Commented Jun 11, 2015 at 20:52
  • @DanielRoseman Consider point 2 the reply to your edited comment. And why the down vote? Commented Jun 11, 2015 at 20:55

1 Answer 1

1

Nginx talks to a fastcgi process over a socket connection.

If the fastcgi process blocks, that means that it won't be sending data over the socket.

This won't block nginx as such, because it keeps processing events (data from other connections). It uses non-blocking techniques like select, poll or equivalent OS-dependent functions (with a timeout) to query sockets without blocking.

But it will stall whatever client is waiting for the fastcgi output.

Sign up to request clarification or add additional context in comments.

5 Comments

If a fastcgi process blocks, nginx will keep processing events. Then wont it be starting a new instance? (process or thread or green thread).
Which is why you always create a pool of backend connections and do a simple loadbalance between them, on averidge 10 should be enough.
@Anirudh Nginx connects to fastcgi processes, but it does not start them. Internally, nginx has an event-driven architecture.
@Ronald So when a fastcgi process blocks, nginx switches context to another process till the block is released is it?
@Anirudh No. Re-read the answer. An nginx worker process basically loops over all its sockets for available data and processes the data from each. If there is no data on one socket (because the program generating the data is stuck) nginx will just skip that socket and move on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.