Lets say I have the following processes declared in my Procfile
web: newrelic-admin run-program python manage.py run_gunicorn -b 0.0.0.0:$PORT -w 9 -k gevent --max-requests 250 --preload --timeout 240
scheduler: python manage.py celery worker -B -E --maxtasksperchild=1000
worker: python manage.py celery worker -E --maxtasksperchild=1000
celerymon: python manage.py celerymon -B 0.0.0.0 -P $PORT
I basically have to run a few dynos of my primary web process. Run a scheduler. Run a few workers. Monitor celery. Separately use a hosted AMQP broker.
I have tried the alternative of running multiple processes on a single dyno but it doesn't seem to work reliably and anyways is not something I would like to use in production.
I find the cost of running all this to be a bit prohibitive especially when I think I could club together some processes on a single dyno. Maybe combining the scheduler with monitoring or run the scheduler and worker together.
Added to this is the fact that only 80 and 443 ports are exposed by Heroku and there is no way to run services on multiple ports on the same dyno.
What would be a good strategy to go about optimizing process and dyno usage?
Alternatively how does one go about monitoring celery tasks on heroku if running celerycam adds another dyno to your cost?
Celery is fully supported on Heroku and just requires using one of our add-on providers to implement the message broker and result store.
The "shared_task" decorator allows creation of Celery tasks for reusable apps as it doesn't need the instance of the Celery app. It is also easier way to define a task as you don't need to import the Celery app instance.
celery beat is a scheduler; It kicks off tasks at regular intervals, that are then executed by available worker nodes in the cluster. By default the entries are taken from the beat_schedule setting, but custom stores can also be used, like storing the entries in a SQL database.
You can look at using eventlet to scale your worker pool without increasing the number of dynos.
Unfortunately eventlet based workers don't support scheduling/beats (-B switch). Therefore you'll still need an extra process for the scheduler.
As for monitoring, I'd suggest just running the monitor from your local machine or another server on an ad-hoc basis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With