Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache/PHP to Nginx/Tornado/Python [closed]

Our website has developed a need for real-time updates, and we are considering various comet/long-polling solutions. After researching, we have settled on nginx as a reverse proxy to 4 tornado instances (hosted on Amazon EC2). We are currently using the traditional LAMP stack and have written a substantial amount of code in PHP. We are willing to convert our PHP code to Python to better support this solution. Here are my questions:

  1. Assuming a quad-core processor, is it ok for nginx to be running on the same server as the 4 tornado instances, or is it recommended to run two separate servers: one for nginx and one for the 4 tornado processes?

  2. Is there a benefit to using HAProxy in front of Nginx? Doesn't Nginx handle load-balancing very well by itself?

  3. From my research, Nginx doesn't appear to have a great URL redirecting module. Is it preferred to use Redis for redirects? If so, should Redis be in front of Nginx, or behind?

  4. A large portion of our application code will not be involved in real-time updates. This code contains several database queries and filesystem reads, so it clearly isn't suitable for a non-blocking app server. From my research, I've read that the blocking issue is mitigated simply by having multiple Tornado instances, while others suggest using a separate app server (ex. Gunicorn/Django/Flask) for blocking calls. What is the best way to handle blocking calls when using a non-blocking server?

  5. Converting our code from PHP to Python will be a lengthy process. Is it acceptable to simultaneously run Apache/PHP and Tornado behind Nginx, or should we just stick to on language (either tornado with gunicorn/django/flask or tornado by itself)?

like image 831
xxjbmxx Avatar asked Nov 08 '12 22:11

xxjbmxx


1 Answers

I'll go point by point:

  1. Yes. It's ok to run tornado and nginx on one server. You can use nginx as reverse proxy for tornado also.

  2. Haproxy will give you benefit, if you have more than one server instances. Also it will allow you to proxy websockets directly to tornado.

  3. Actually, nginx can be used for redirects, with no problems. I haven't heard about using redis for redirects - it's key/value storage... may be you mean something else?

  4. Again, you can write blocking part in django and non-blocking part in tornado. Also tornado has some non-blocking libs for db queries. Not sure that you need powers of django here.

  5. Yes, it's ok to run apache behind nginx. A lot of projects use nginx in front of apache for serving static files.

Actually question is very basic - answer also. I can be more detailed on any of the point if you wish.

like image 55
Nikolay Fominyh Avatar answered Sep 27 '22 23:09

Nikolay Fominyh