12 ms·
Gunicorn
- bartq 5y agoYou can tell how Gunicorn is old by looking at example showing only 4 workers :)
- sgt 5y ago4 highly skilled workers. Imagine how much 4096 workers would cost?
- tgv 5y ago4TB.
- nickjj 5y ago> You can tell how Gunicorn is old by looking at example showing only 4 workers :) I've seen folks run a $90,000 / month business through their SAAS app using gunicorn on a 2 CPU core box (4 workers). Nothing wrong with being efficient!
- dfox 5y ago4 workers is the sweet spot for most wsgi applications. Typically you will scale above that by running additional complete gunicorn instances (managed by some kind of external scaling/load balancing thing). If it makes sense for your application to run more than 4 workers in one gunicorn instance (ie. you have long running requests that only wait on something) then gunicorn (and in fact, "normal" wsgi itself) probably is not the right solution for your application. Edit: somewhat typical issue with scaling python applications is that just throwing additional workers at the problem in the same instance of the wsgi container (including separate uwsgi processes) stops being effective fairly soon and makes the problem worse.
- WesleyJohnson 5y agoWe're running Gunicorn behind Nginx for an internal Django web application. I thought the rule of thumb was to scale workers = (Cores * 2) + 1?
- whouweling 5y agoIn my experience it also depends on the worker type, if you are running sync you might need more workers depending on how much your database can handle. Otherwise the number of workers might limit the total throughput quite severely.
- qeternity 5y agoWe run single worker Uvicorn instances...we just run lots of them (behind an HAProxy sidecar).
- dusted 5y agoI cannot be the only one disappointed by the lack of unicorns with guns.
- deleted 5y ago[deleted]
- causi 5y agoFrankly at first I misread it as Gnunicorn and was just relieved not to see Richard Stallman in a fursuit.
- tm-guimaraes 5y agoI misread it as well, thought "it can't be, or it's a parody", re-read it, "oh, unicorn and gun?". The disappointment....
- bryanrasmussen 5y agowell yeah, things sure would have been more fair https://en.wikipedia.org/wiki/The_Hunt_of_the_Unicorn https://en.wikipedia.org/wiki/The_Hunt_of_the_Unicorn
- mrweasel 5y agohttps://ih1.redbubble.net/image.1433836564.0273/raf,750x1000,075,t,101010:01c5ca27c6.jpg https://ih1.redbubble.net/image.1433836564.0273/raf,750x1000...
- sigmaprimus 5y ago
- tempodox 5y agoI was disappointed not to see an article about a unicorn of guns, like a Star Trek phaser pistol or some such.
- healeycodes 5y agoI really like the clear example at the bottom of the page.
- ethbr0 5y agoOT, but the biggest cultural change disappointment between my previous job and this has been readme.md expectations. Previous: every project org-wide contained enough environment & setup information to get it running. Even if you didn't know anything else about it Current: almost nothing The initial "What magic incantations must I make?" step, before you're able to start really learning by experimenting, is invaluable.
- TekMol 5y agoI love Python. But for web projects, PHP has a massive upside over Python: You don't need to restart your application when you change the code. I know people run monitoring scripts on their development systems that automatically restart Apache or whatever server they use every time they change a line of code. Still this is a cludge. Development in PHP is: - Change a line of code - Alt+Tab to switch to Firefox - F5 and see the result So I still enjoy PHP development more when it comes to the web. Even though PHP's namespaces are crap compared to Python's module system.
- foxfluff 5y agoRight now I have gunicorn running with --reload. Change a line of code, refresh/rerun client and see the result.
- ktpsns 5y agoLive/hot reloading is a thing in various web frameworks and supported by various ecosystems, from Java over Python up to Nodejs. Funnily, development with hot reloading systems is: - Change a line of code - Alt+Tab to switch to Firefox - No need to press F5 because site already updated.
- berkes 5y agoAnd so does Rails and Sinatra in Ruby land. I have encountered very few development servers that lacked hot-reloading in decades. Many such stacks will even inject some JS or headers to automatically refresh the browser for you on detected changes. I think OP may have an outdated or skewed experience of web-development stacks. Where PHP through apache+mod_php had "instant code refresh" back in early 2000s, and other stacks (Beans, CGI, etc) required a manual reboot everytime you'd want to check your changes in a browser. But this hasn't been true since Rails was released in 2004~5. Ironically the most difficult one I recently encoutered was a PHP-FPM with APC, that required a "manually" restart of nginx and php-fpm in the right order after every code change. But this really is not suited as "development" server, as shown in this anecdotal issue.
- 5y ago
- sparkling 5y agoI have tried many WSGI servers for serving Python web applications (using both Django and Flask). Gunicorn may not be the fastest or have the most features, but its super solid and the documentation is superb. Everything else that i tried hat some sort of quirks und hickups that made it unsuitable for production environments.
- kkirsche 5y ago100% this. I started off working with uwsgi and I had problem after problem while gunicorn has always been rock solid for me. In hindsight I wonder if it’s just experience in the experience that has led to this differing experience or if the products are actually meaningfully different in their configuration and behavior that this is consistent for others. Thanks for sharing, this made me feel better that I had so many issues with alternatives.
- samwillis 5y agoI wish Gunicorn with Gevent had won the “async vs. coroutine Python” battle. The Developer UX is so much better with coroutines and just as scalable as asyncio (async/await). Many people misunderstand asyncio thinking it will make your code faster, when what it does do is make it more scalable (if you have allot of IO for example). But at the expense of developer UX. Mixing async and sync code within Python is a nightmare. I am completely unconvinced by the move to asyncio everywhere in Python. I have been using Gunicorn with Gevent for nearly 10 years and never had a problem with it. Languages like JavaScript that have been async from the start work well as you (mostly) only have an async api. https://docs.gunicorn.org/en/latest/design.html#async-workers https://docs.gunicorn.org/en/latest/design.html#async-worker... http://www.gevent.org/ http://www.gevent.org/
- sandGorgon 5y agoit kinda has - we use gunicorn with fastapi using the uvicorn asgi workers https://fastapi.tiangolo.com/deployment/server-workers/ https://fastapi.tiangolo.com/deployment/server-workers/
- qff 5y agoGreen threads (gunicorn/gevent) allows you to write Python the way you always have and gain many of the benefits of async. Uvicorn and ASGI do not. For those you need to handle async explictly.
- sandGorgon 5y agoi hear you - however the framework captures most of the abstraction entirely. In addition, most of the bottlenecks are actually i/o (db queries, etc) where its entirely worth doing it explicitly versus magic. in a general programming language sense...ur right. But from the POV of what gunicorn/fastapi are actually used for - web frameworks - its actually quite good.
- ramraj07 5y agoThe list of terms in that sentence: Gunicorn Fastapi Uvicorn Asgi I suppose also nginx docker?
- zokier 5y agoFor asyncio side of things there is also Uvicorn (based on libuv/uvloop) https://www.uvicorn.org/ https://www.uvicorn.org/
- pgjones 5y agoOr Hypercorn https://gitlab.com/pgjones/hypercorn https://gitlab.com/pgjones/hypercorn if you want HTTP/1, HTTP/2, and HTTP/3.
- hackandtrip 5y agoNote that Uvicorn still recommends to use Gunicorn for production use, with the Uvicorn worker class implemented for Gunicorn. https://www.uvicorn.org/#running-with-gunicorn https://www.uvicorn.org/#running-with-gunicorn
- TekMol 5y agoHow well is Gunicorn suited for production? Do you need to put another server in front of it for https or has Gunicorn https handling built in?
- foxfluff 5y agoGunicorn does support https. They still seem to recommend using a different server in front of it.
- samwillis 5y agoI think it depends on how your whole stack looks. If you are running on a PAAS such as Heroku, have load balancers or are even using something like ClourFlare I don’t this it’s necessary to have something in front of Gunicorn. I wouldn’t leave Gunicorn “naked” for want of a better word, or use it for static files though.
- TekMol 5y agoIf you put Apache or Nginx in front of it, why not leave out Gunicorn completely?
- deniska 5y agoApache has mod_wsgi, nginx not so much. mod_wsgi is a much less flexible setup when it comes to mixing and matching different python versions
- samwillis 5y agoPython has an interface called WSGI (web server gateway interface), with both Apache and Nginx you need either a none standard module for that interface or to reverse proxy to a second server that does. So same number of moving parts either way.
- TekMol 5y agoHow is libapache2-mod-wsgi-py3 "none standard"?
- danieldevries 5y agoOne main reason I switched away from Python was all the dependencies needed to run a performant webapp. And then throw async into the mix and you start wondering about uvicorn instead or do I need gevent? Go really simplified these decisions and basically all by using the std lib.
- qff 5y agoI haven't switched away from Python (yet). But I agree that Go does look very compelling, and is basically the only performant and mainstream implementation of green threads.
- Lio 5y agoJust for discussion would Erlang/Elixir not count as another performant implementation of green threads or would you not consider them mainstream enough? Erlang has been scaling massively in the telecommunications industry for a very long time now even if it's not as popular as other languages.
- fnord123 5y agoErlang's green threads are considered lightweight processes. They only communicate through message passing. When selling Erlang, don't focus on "telecommunications industry" but sell based on Whatsapp: http://highscalability.com/blog/2022/1/3/designing-whatsapp.html http://highscalability.com/blog/2022/1/3/designing-whatsapp.... More: https://www.erlang-solutions.com/blog/which-companies-are-using-erlang-and-why-mytopdogstatus/ https://www.erlang-solutions.com/blog/which-companies-are-us...
- danieldevries 5y agoI started the switch last summer. Haven't looked back since. Python gives the veneer of simplicity (ie the Flask hello world script, 5 lines of code approx?). On top of that the 5 different ways of doing x, or just wanting concurrency. Quickly Python becomes verbose. My current webapp is one executable that uses the standard net/http server and the autocert package for Letsencrypt.
- tibbetts 5y agoThis post would have benefited from a longer title. As it was I was disappointed to not see a picture of a horse with a gun coming out of its forehead. For anyone similarly disappointed here is an example: https://www.deviantart.com/kirawra/art/gUnicorn-Adopt-OPEN-858514607 https://www.deviantart.com/kirawra/art/gUnicorn-Adopt-OPEN-8...
- spywaregorilla 5y agoOnly $120. Go adopt it.
- nickjj 5y agoGunicorn is one of my favorite app servers. I've been using Gunicorn in production on a bunch of projects (any Flask / Django project I happen to work with) for around 8 years now. It's rock solid and extremely predictable. I also use Gunicorn in development too, it supports code reloading and also lets you enable Flask's debug middleware so you can use the interactive debugger. This is all configured in my Build a SAAS App with Flask course, a code example is here: https://github.com/nickjj/build-a-saas-app-with-flask https://github.com/nickjj/build-a-saas-app-with-flask. A Django example is here: https://github.com/nickjj/docker-django-example https://github.com/nickjj/docker-django-example
- geraldyo 5y ago+1 here, we've been using Gunicorn in production for ~2 years now, once it was set-up I never had to think about it
- deleted 5y ago[deleted]
- piyiotisk 5y agoI've recently deployed an app using Nginx + Gunicorn on a VPS. I wrote a tutorial on how to replicate the setup here: https://costapiy.com/deploy_django_project_linux_server/ https://costapiy.com/deploy_django_project_linux_server/
- jonthepirate 5y agoI've been dealing with Python for 8 years at 2 big tech companies in the Bay Area. The main advantage in Python is that it's easy to learn. It just doesn't scale. Once things start taking off, there's always a migration to something more scalable like Go or Kotlin. Gunicorn is probably the "best" tool for making a Python based website or API for Python users.
- zackkitzmiller 5y agoCan we get a source on that? I've successfully used guniron for APIs getting hundreds of thousands to millions of requests a second. I've also found it's best to question anytime someone suggests a technology "doesn't scale."
- huetius 5y agoI don’t like GP’s phrasing, but the post describes a real phenomenon. Beyond the most trivial examples, concurrency and parallelism in Python are a massive pain, as many examples here attest. Unless you have a very compelling reason to stick with Python (e.g., dependence on its excellent data science libraries), there are almost always better choices if your project has to coordinate many things happening at once.
- elesbao 5y agogunicorn and gevent developer UX is so nice that it prepared me for Go years later.
- Veelox 5y agoReading it as gun-icorn lead to extreme excitement which was crushed to find the link had nothing to do with gun unicorns...
- astolarz 5y agoI was really disappointed that they didn't replace the horn with a gun in the logo.
- mcdermott 5y agoWith Python you have to run a web server in front of your web server... never seemed right to me. Just use Golang, it's all self contained.
- yazmeya 5y agoIn fact, you don't. Your WSGI app is not a web server. It does not run or network by itself and doesn't speak HTTP. You need a compatible web server (e.g. Gunicorn) to do that for you. It's really not that much different from good old CGI. It's simple and flexible enough for a large number of use cases. Of course, that's not the only way to write web apps in Python. Using a library like Pyramid et al, you launch the HTTP endpoint manually from the main program, and attach various handlers/whatnot to it. All "self-contained".
- mcdermott 5y agoI love Python for slicing and dicing data, automating tasks and building tools, but for a web server or web application it's a mess and is a bad choice.
- codethief 5y agoWhat do you base this judgment on? I've built several web applications using Python and things worked very well and were far from being a mess.
- ohmanjjj 5y agoFalcon + Gunicorn + Meinheld is incredibly under appreciated
- tedivm 5y agoThe multi-py project has a cross platform gunicorn container that works with Intel and Arm out of the box. https://github.com/multi-py/python-gunicorn https://github.com/multi-py/python-gunicorn There's also a uvicorn one there for people who want the async features. https://github.com/multi-py/python-uvicorn https://github.com/multi-py/python-uvicorn And a container that combines both (although it's often better to just use uvicorn and add more containers to your API to scale up). https://github.com/multi-py/python-gunicorn-uvicorn https://github.com/multi-py/python-gunicorn-uvicorn
- mulmboy 5y ago> it's often better to just use uvicorn and add more containers to your API to scale up Why is that?
- furyofantares 5y agoI assume it's pronounced gyoonicorn (just unicorn with a g in front) rather than gun-icorn?
- dgritsko 5y agoI'm glad I'm not the only one wondering this. I found this Quora post (https://www.quora.com/How-do-you-pronounce-gunicorn https://www.quora.com/How-do-you-pronounce-gunicorn) as well as this GitHub issue (https://github.com/benoitc/gunicorn/issues/139 https://github.com/benoitc/gunicorn/issues/139), and it's clear as mud now.
- purephase 5y agoI've always pronounced it G-unicorn. As-in, say G first, then unicorn. Like Geeunicorn. That's how I've heard others pronounce it too.
- strzibny 5y agoNice to see Gunicorn here. While it's modelled after Ruby's Unicorn, it's actually bit more capable as it supports the multi-process & multi-thread execution model. It even supports ASGI by specifying a particular Uvicorn worker class and thus can remain one go-to Python application server. This is also the reason I am using Gunicorn for the examples in my book Deployment from Scratch.