0
votes

I'm using Heroku to host a django application, and I'm using Waitress as my web server. I run 2 (x2) dynos, And I see in New Relic instance tab that I have 10 instances running.

I was wondering How does Heroku determines the number of web server processes to run on one Dyno when using Waitress?

I know that when using Gunicorn there is a way to set the number of proccess per dyno, but didn't see any way to define it in Waitress.

Thanks!

2

2 Answers

0
votes

In Waitress, there is a master process and (by default) 4 worker threads or processes. You can change this if you wish. Here is the docs for these options for waitress-serve

http://waitress.readthedocs.org/en/latest/runner.html#runner

--threads=INT

Number of threads used to process application logic, default is 4.

So if you have 2 dynos, and 5 (4+1) threads on each, then the total would come to 10 instances for this app in the RPM dashboard.

One can add more processes to the dynos as the maximum supported on Heroku 2x dynos is much higher:

2X dynos support no more than 512

https://devcenter.heroku.com/articles/dynos#process-thread-limits

But, you may want to check out some discussion on tuning this vs Gunicorn:

Waitress differs, in that it has an async master process that buffers the entire client body before passing it onto a sync worker. Thus, the server is resilient to slow clients, but is also guaranteed to process a maximum of (default) 4 requests at once. This saves the database from overload, and makes scaling services much more predictable.

Because waitress has no external dependencies, it also keeps the heroku slug size smaller.

https://discussion.heroku.com/t/waitress-vs-gunicorn-for-docs/33

0
votes

So after talking to the New relic support they clarified the issue. Apparently only processes are counted in the instances tab (threads do not count).

in my Procfile I am also monitoring RabbitMQ workers which add instances to the instance tab, and hence the mismatch. To quote their answer :

I clarified with our developers how exactly we measure instances for the Instances tab. The Python agent views each monitored process as one instance. Threads do not count as additional instances. I noticed that you're monitoring not only your django/waitress app, but also some background tasks. It looks like the background tasks plus the django processes are adding up to that total of 10 processes being monitored.