Hi all, I want to use my Flask applications with nginx, but I have a doubt with the solution for Python. In my choice, what do you propose ? Do you have advices ? * uwsgi ? * gunicorn ? * fast-cgi ? What's the best for RAM, CPU, and request/s ? Thank you, Stéphane
Il giorno 21/feb/2011, alle ore 17.54, Stephane Wirtel ha scritto: > Hi all, > > I want to use my Flask applications with nginx, but I have a doubt with the solution for Python. > > In my choice, what do you propose ? Do you have advices ? > > * uwsgi ? If you want to try uWSGI, here you will find a quick tip: http://uwsgi.it/uwsgi/wiki/Example#Flaskdeploy After uWSGi is started simply point nginx to its socket using uwsgi_pass directive If you want to add concurrency (more workers) to your app simply add -p <n> to the command line. Currently uWSGI exposes more than 170 options but 99% of the time you will end specifiying the WSGI module, the socket and the number of workers to spawn. If you are brave, you can try the current mercurial tip and use threading (simply add --threads <n> to the command line). It works well with Flask (we now use it in production for about 4 months) -- Roberto De Ioris http://unbit.it
Built this app for music hackday in nyc last week. It's running flask+uwsgi+nginx on a small ec2 instance and hasnt blinked (even with a few thousand visits a day after some press) http://findyousomevinyl.com/ If you want to check out the source, it's up on github https://github.com/imlucas/findyousomevinyl If you're looking for an actual comparison between the three options, found this post pretty helpful as well as more info on the effects of a few config tweaks http://www.peterbe.com/plog/fcgi-vs-gunicorn-vs-uwsgi Like Sebastien said, gunicorn is slightly easier to set up, however, you can now install uwsgi via pip http://projects.unbit.it/uwsgi/wiki/Install. Uwsgi is also a lot more powerful and you'll have access to useful things like Roberto's upcoming control center http://flask.pocoo.org/mailinglist/archive/2011/1/27/flask-choosen-for-uwsgi-control-center/ On Mon, Feb 21, 2011 at 1:15 PM, Roberto De Ioris <roberto@unbit.it> wrote: > > Il giorno 21/feb/2011, alle ore 17.54, Stephane Wirtel ha scritto: > > > Hi all, > > > > I want to use my Flask applications with nginx, but I have a doubt with > the solution for Python. > > > > In my choice, what do you propose ? Do you have advices ? > > > > * uwsgi ? > > If you want to try uWSGI, here you will find a quick tip: > > http://uwsgi.it/uwsgi/wiki/Example#Flaskdeploy > > After uWSGi is started simply point nginx to its socket using > > uwsgi_pass > > directive > > If you want to add concurrency (more workers) to your app simply add -p <n> > to the command line. > > Currently uWSGI exposes more than 170 options but 99% of the time you will > end specifiying > the WSGI module, the socket and the number of workers to spawn. > > If you are brave, you can try the current mercurial tip and use threading > (simply add --threads <n> to the command line). > It works well with Flask (we now use it in production for about 4 months) > > -- > Roberto De Ioris > http://unbit.it > >
I've just tidied up my own notes on how to do nginx and uwsgi at http://cols-code-snippets.blogspot.com/2010/12/python-uwsgi-with-nginx-deploy-python.html. Hope it helps. Col On Mon, Feb 21, 2011 at 7:52 PM, Lucas Hrabovsky <hrabovsky.lucas@gmail.com>wrote: > Built this app for music hackday in nyc last week. It's running > flask+uwsgi+nginx on a small ec2 instance and hasnt blinked (even with a few > thousand visits a day after some press) http://findyousomevinyl.com/ If > you want to check out the source, it's up on github > https://github.com/imlucas/findyousomevinyl > > If you're looking for an actual comparison between the three options, found > this post pretty helpful as well as more info on the effects of a few config > tweaks http://www.peterbe.com/plog/fcgi-vs-gunicorn-vs-uwsgi > > Like Sebastien said, gunicorn is slightly easier to set up, however, you > can now install uwsgi via pip http://projects.unbit.it/uwsgi/wiki/Install. > Uwsgi is also a lot more powerful and you'll have access to useful things > like Roberto's upcoming control center > http://flask.pocoo.org/mailinglist/archive/2011/1/27/flask-choosen-for-uwsgi-control-center/ > > On Mon, Feb 21, 2011 at 1:15 PM, Roberto De Ioris <roberto@unbit.it>wrote: > >> >> Il giorno 21/feb/2011, alle ore 17.54, Stephane Wirtel ha scritto: >> >> > Hi all, >> > >> > I want to use my Flask applications with nginx, but I have a doubt with >> the solution for Python. >> > >> > In my choice, what do you propose ? Do you have advices ? >> > >> > * uwsgi ? >> >> If you want to try uWSGI, here you will find a quick tip: >> >> http://uwsgi.it/uwsgi/wiki/Example#Flaskdeploy >> >> After uWSGi is started simply point nginx to its socket using >> >> uwsgi_pass >> >> directive >> >> If you want to add concurrency (more workers) to your app simply add -p >> <n> to the command line. >> >> Currently uWSGI exposes more than 170 options but 99% of the time you will >> end specifiying >> the WSGI module, the socket and the number of workers to spawn. >> >> If you are brave, you can try the current mercurial tip and use threading >> (simply add --threads <n> to the command line). >> It works well with Flask (we now use it in production for about 4 months) >> >> -- >> Roberto De Ioris >> http://unbit.it >> >> >
Thanks All ;-) On 02/21/2011 09:02 PM, Col Wilson wrote: > I've just tidied up my own notes on how to do nginx and uwsgi at http://cols-code-snippets.blogspot.com/2010/12/python-uwsgi-with-nginx-deploy-python.html. Hope it helps. > > Col > > On Mon, Feb 21, 2011 at 7:52 PM, Lucas Hrabovsky <hrabovsky.lucas@gmail.com <mailto:hrabovsky.lucas@gmail.com>> wrote: > > Built this app for music hackday in nyc last week. It's running flask+uwsgi+nginx on a small ec2 instance and hasnt blinked (even with a few thousand visits a day after some press) > http://findyousomevinyl.com/ If you want to check out the source, it's up on github https://github.com/imlucas/findyousomevinyl > > If you're looking for an actual comparison between the three options, found this post pretty helpful as well as more info on the effects of a few config > tweaks http://www.peterbe.com/plog/fcgi-vs-gunicorn-vs-uwsgi > > Like Sebastien said, gunicorn is slightly easier to set up, however, you can now install uwsgi via pip http://projects.unbit.it/uwsgi/wiki/Install. Uwsgi is also a lot more powerful and you'll > have access to useful things like Roberto's upcoming control center http://flask.pocoo.org/mailinglist/archive/2011/1/27/flask-choosen-for-uwsgi-control-center/ > > On Mon, Feb 21, 2011 at 1:15 PM, Roberto De Ioris <roberto@unbit.it <mailto:roberto@unbit.it>> wrote: > > > Il giorno 21/feb/2011, alle ore 17.54, Stephane Wirtel ha scritto: > > > Hi all, > > > > I want to use my Flask applications with nginx, but I have a doubt with the solution for Python. > > > > In my choice, what do you propose ? Do you have advices ? > > > > * uwsgi ? > > If you want to try uWSGI, here you will find a quick tip: > > http://uwsgi.it/uwsgi/wiki/Example#Flaskdeploy > > After uWSGi is started simply point nginx to its socket using > > uwsgi_pass > > directive > > If you want to add concurrency (more workers) to your app simply add -p <n> to the command line. > > Currently uWSGI exposes more than 170 options but 99% of the time you will end specifiying > the WSGI module, the socket and the number of workers to spawn. > > If you are brave, you can try the current mercurial tip and use threading (simply add --threads <n> to the command line). > It works well with Flask (we now use it in production for about 4 months) > > -- > Roberto De Ioris > http://unbit.it > > >
is there anybody implement gevent for production?? http://nichol.as/asynchronous-servers-in-python said that gevent has good performance... 2011/2/22 Stephane Wirtel <stephane@wirtel.be> > Thanks All > > ;-) > On 02/21/2011 09:02 PM, Col Wilson wrote: > > I've just tidied up my own notes on how to do nginx and uwsgi at > http://cols-code-snippets.blogspot.com/2010/12/python-uwsgi-with-nginx-deploy-python.html. > Hope it helps. > > > > Col > > > > On Mon, Feb 21, 2011 at 7:52 PM, Lucas Hrabovsky < > hrabovsky.lucas@gmail.com <mailto:hrabovsky.lucas@gmail.com>> wrote: > > > > Built this app for music hackday in nyc last week. It's running > flask+uwsgi+nginx on a small ec2 instance and hasnt blinked (even with a few > thousand visits a day after some press) > > http://findyousomevinyl.com/ If you want to check out the source, > it's up on github https://github.com/imlucas/findyousomevinyl > > > > If you're looking for an actual comparison between the three options, > found this post pretty helpful as well as more info on the effects of a few > config > > tweaks http://www.peterbe.com/plog/fcgi-vs-gunicorn-vs-uwsgi > > > > Like Sebastien said, gunicorn is slightly easier to set up, however, > you can now install uwsgi via pip > http://projects.unbit.it/uwsgi/wiki/Install. Uwsgi is also a lot more > powerful and you'll > > have access to useful things like Roberto's upcoming control center > http://flask.pocoo.org/mailinglist/archive/2011/1/27/flask-choosen-for-uwsgi-control-center/ > > > > On Mon, Feb 21, 2011 at 1:15 PM, Roberto De Ioris <roberto@unbit.it<mailto: > roberto@unbit.it>> wrote: > > > > > > Il giorno 21/feb/2011, alle ore 17.54, Stephane Wirtel ha > scritto: > > > > > Hi all, > > > > > > I want to use my Flask applications with nginx, but I have a > doubt with the solution for Python. > > > > > > In my choice, what do you propose ? Do you have advices ? > > > > > > * uwsgi ? > > > > If you want to try uWSGI, here you will find a quick tip: > > > > http://uwsgi.it/uwsgi/wiki/Example#Flaskdeploy > > > > After uWSGi is started simply point nginx to its socket using > > > > uwsgi_pass > > > > directive > > > > If you want to add concurrency (more workers) to your app simply > add -p <n> to the command line. > > > > Currently uWSGI exposes more than 170 options but 99% of the time > you will end specifiying > > the WSGI module, the socket and the number of workers to spawn. > > > > If you are brave, you can try the current mercurial tip and use > threading (simply add --threads <n> to the command line). > > It works well with Flask (we now use it in production for about 4 > months) > > > > -- > > Roberto De Ioris > > http://unbit.it > > > > > > > >
Sorry, no, but I'd be interested to know how you get on, in fact has anyone seen a comparative report on the various wsgi server options? On Wed, Feb 23, 2011 at 5:21 AM, arief nur andono <ariefnurandono@gmail.com>wrote: > is there anybody implement gevent for production?? > http://nichol.as/asynchronous-servers-in-python said that gevent has good > performance... > > 2011/2/22 Stephane Wirtel <stephane@wirtel.be> > > Thanks All >> >> ;-) >> On 02/21/2011 09:02 PM, Col Wilson wrote: >> > I've just tidied up my own notes on how to do nginx and uwsgi at >> http://cols-code-snippets.blogspot.com/2010/12/python-uwsgi-with-nginx-deploy-python.html. >> Hope it helps. >> > >> > Col >> > >> > On Mon, Feb 21, 2011 at 7:52 PM, Lucas Hrabovsky < >> hrabovsky.lucas@gmail.com <mailto:hrabovsky.lucas@gmail.com>> wrote: >> > >> > Built this app for music hackday in nyc last week. It's running >> flask+uwsgi+nginx on a small ec2 instance and hasnt blinked (even with a few >> thousand visits a day after some press) >> > http://findyousomevinyl.com/ If you want to check out the source, >> it's up on github https://github.com/imlucas/findyousomevinyl >> > >> > If you're looking for an actual comparison between the three >> options, found this post pretty helpful as well as more info on the effects >> of a few config >> > tweaks http://www.peterbe.com/plog/fcgi-vs-gunicorn-vs-uwsgi >> > >> > Like Sebastien said, gunicorn is slightly easier to set up, however, >> you can now install uwsgi via pip >> http://projects.unbit.it/uwsgi/wiki/Install. Uwsgi is also a lot more >> powerful and you'll >> > have access to useful things like Roberto's upcoming control center >> http://flask.pocoo.org/mailinglist/archive/2011/1/27/flask-choosen-for-uwsgi-control-center/ >> > >> > On Mon, Feb 21, 2011 at 1:15 PM, Roberto De Ioris <roberto@unbit.it<mailto: >> roberto@unbit.it>> wrote: >> > >> > >> > Il giorno 21/feb/2011, alle ore 17.54, Stephane Wirtel ha >> scritto: >> > >> > > Hi all, >> > > >> > > I want to use my Flask applications with nginx, but I have a >> doubt with the solution for Python. >> > > >> > > In my choice, what do you propose ? Do you have advices ? >> > > >> > > * uwsgi ? >> > >> > If you want to try uWSGI, here you will find a quick tip: >> > >> > http://uwsgi.it/uwsgi/wiki/Example#Flaskdeploy >> > >> > After uWSGi is started simply point nginx to its socket using >> > >> > uwsgi_pass >> > >> > directive >> > >> > If you want to add concurrency (more workers) to your app simply >> add -p <n> to the command line. >> > >> > Currently uWSGI exposes more than 170 options but 99% of the >> time you will end specifiying >> > the WSGI module, the socket and the number of workers to spawn. >> > >> > If you are brave, you can try the current mercurial tip and use >> threading (simply add --threads <n> to the command line). >> > It works well with Flask (we now use it in production for about >> 4 months) >> > >> > -- >> > Roberto De Ioris >> > http://unbit.it >> > >> > >> > >> >> >
I had an experience of setting up Flask with Nginx an uWSGI. I've tried different methods. What worked fine for me is described in this blog post: http://blog.zelid.com/system-administration/installing-and-configuring-nginx-with-python-and-uwsgi-on-ubuntu.html Note that both Nginx and uWSGI will be running as system services. uWSGI service will be used as virtual site service. It means no need run separate uWSGI service for each application. One service will be able to run several flask application - just point to the right application inside Nginx config and that's all. The configuration described in the blog post is the best from all what I tried, what do you think?
Gunicorn is really simple to setup and use. WRT to RAM/Cpu and req/s, i think that all these servers would be more than enough. If you use Gunicorn the number of workers should be around 2x the number of CPU core. I've implemented a CDN director with nginx + gunicorn + flask and we have around 1500 req/s with less than 4ms per request for a concurrency of about 50 clients. The hardware is a bi Xeon dual core 2.6 Ghz with 8Go of ram. Uwsgi is also a nice option but it's less easier to setup than gunicorn. Sebastien Estienne On Mon, Feb 21, 2011 at 17:54, Stephane Wirtel <stephane@wirtel.be> wrote: > Hi all, > > I want to use my Flask applications with nginx, but I have a doubt with the solution for Python. > > In my choice, what do you propose ? Do you have advices ? > > * uwsgi ? > * gunicorn ? > * fast-cgi ? > > What's the best for RAM, CPU, and request/s ? > > Thank you, > > Stéphane > >