Skip to content

Use Gunicorn on Heroku instead of runserver #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
natea opened this issue Feb 8, 2013 · 8 comments
Open

Use Gunicorn on Heroku instead of runserver #2

natea opened this issue Feb 8, 2013 · 8 comments

Comments

@natea
Copy link
Contributor

natea commented Feb 8, 2013

https://devcenter.heroku.com/articles/django#using-a-different-wsgi-server

@ghost ghost assigned briandant Feb 8, 2013
@briandant
Copy link

Mezzanine threw a bit of a curveball with the deploy/gunicorn.conf.py file, so I'll have to look into that before I move forward with this. It's a bit different than the way I've done it in the past.

@natea
Copy link
Contributor Author

natea commented Feb 9, 2013

This answer on Stackoverflow suggests putting this in the Procfile: http://stackoverflow.com/a/12862684

web: python manage.py run_gunicorn -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload

And this blog post (https://mike.tig.as/blog/2012/02/13/deploying-django-on-heroku/) recommends doing it this way:

# Unlike the gunicorn defined in Heroku's Django example, we're going
# to use one of the async worker classes, "gevent". Using an async worker class
# is recommended when serving traffic directly to gunicorn (which is what
# happens under the Heroku Cedar stack).
web: gunicorn_django -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload src/$PYTHON_APP_NAME/settings.py"

The only difference is that the first one uses manage.py run_gunicorn and the second one uses gunicorn_django. Not sure which is better/preferred.

@briandant
Copy link

Another example Gunicorn setup:
https://github.com/BrianHicks/funding/blob/master/gunicorn.py.ini

"""gunicorn WSGI server configuration."""


from multiprocessing import cpu_count
from os import environ


def max_workers():
    return cpu_count()


bind = '0.0.0.0:' + environ.get('PORT', '8000')
max_requests = 1000
worker_class = 'gevent'
workers = max_workers()

And his wsgi.py:
https://github.com/BrianHicks/funding/blob/master/wsgi.py

The Procfile has different stuff too:
web: newrelic-admin run-program gunicorn -c gunicorn.py.ini wsgi:application

@natea
Copy link
Contributor Author

natea commented Feb 10, 2013

yeah, there seems to be more than one way to skin a cat when it comes to
configuring gunicorn on Heroku. ;) it would be nice if Heroku would
actually document the best practices in their doc center.

On Sun, Feb 10, 2013 at 1:17 PM, Brian Dant [email protected]:

Another example Gunicorn setup:
https://github.com/BrianHicks/funding/blob/master/gunicorn.py.ini


Reply to this email directly or view it on GitHubhttps://github.com//issues/2#issuecomment-13357952..

[email protected]
+1 (617) 517-4953
http://twitter.com/natea | http://linkedin.com/in/natea

@briandant
Copy link

Went with
web: python manage.py run_gunicorn -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload
as the SO question was more recent

@briandant
Copy link

My earlier comment: "Mezzanine threw a bit of a curveball with the deploy/gunicorn.conf.py file, so I'll have to look into that before I move forward with this. It's a bit different than the way I've done it in the past."

Assuming that these files are only used if running Fabric, and by the looks of the settings file, we're not.

esoergel referenced this issue in esoergel/coderaising May 15, 2013
@vellamike
Copy link

Are you guys still working with web: python manage.py run_gunicorn -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload? How is your experience of doing that?

@briandant
Copy link

@vellamike: Yes, that's exactly what I'm using in production. Haven't had any problems yet, but I don't do any intense profiling or the like, so can't say much more than "seems good" :)

@briandant briandant removed their assignment Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants