Channels - unbalanced load for threaded workers

53 views
Skip to first unread message

biwa...@gmail.com

unread,
May 17, 2017, 1:08:55 PM5/17/17
to Django users
I am trying to deploy Django project with Channels. After some trial and error I settled on 4 workers with 16 threads each. However as attached screen shows, the processes that are spawned by supervisor have CPU usage at ~15% while threads are around ~1-2%. Number of connections at the moment is less than 100. I tried load testing this setup, and as more messages are coming in the CPU usage is increasing both on processes that were spawned by supervisor and threads of these processes - so there is still disproportion (~50% and ~10%). Is it normal behavior? Any tips to configure it some other way to better balance the load? 
htop.png

Andrew Godwin

unread,
May 18, 2017, 12:18:56 AM5/18/17
to django...@googlegroups.com
Hi - I am not sure what you are saying exactly. That the load only goes to some processes? Python threads are strange, the OS may not show stats correctly and I'd generally advise multiple processes instead.

Andrew

On Wed, May 17, 2017 at 1:53 AM, <biwa...@gmail.com> wrote:
I am trying to deploy Django project with Channels. After some trial and error I settled on 4 workers with 16 threads each. However as attached screen shows, the processes that are spawned by supervisor have CPU usage at ~15% while threads are around ~1-2%. Number of connections at the moment is less than 100. I tried load testing this setup, and as more messages are coming in the CPU usage is increasing both on processes that were spawned by supervisor and threads of these processes - so there is still disproportion (~50% and ~10%). Is it normal behavior? Any tips to configure it some other way to better balance the load? 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b566a9bc-5313-4573-9351-d6dd81915251%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen J. Butler

unread,
May 18, 2017, 12:49:07 AM5/18/17
to django...@googlegroups.com
CPython uses a global interpreter lock, which means that only one thread per process can ever be running Python code. Where threading really helps is if your python project is mostly I/O bound (waiting on database work, network connections, etc). If it's CPU bound then you probably won't see much concurrency with multiple threads.

I'm guessing this is why you're seeing all your work being accounted to a couple processes. You'd get better concurrency moving to a multiprocess/fork model.



On Wed, May 17, 2017 at 3:53 AM, <biwa...@gmail.com> wrote:
I am trying to deploy Django project with Channels. After some trial and error I settled on 4 workers with 16 threads each. However as attached screen shows, the processes that are spawned by supervisor have CPU usage at ~15% while threads are around ~1-2%. Number of connections at the moment is less than 100. I tried load testing this setup, and as more messages are coming in the CPU usage is increasing both on processes that were spawned by supervisor and threads of these processes - so there is still disproportion (~50% and ~10%). Is it normal behavior? Any tips to configure it some other way to better balance the load? 

--

biwa...@gmail.com

unread,
May 18, 2017, 7:36:17 AM5/18/17
to Django users
Yes, that was my concern that only some processes are loaded. So running more 'runworker' commands with less '--threads' should give better results?


W dniu czwartek, 18 maja 2017 02:18:56 UTC+2 użytkownik Andrew Godwin napisał:
Hi - I am not sure what you are saying exactly. That the load only goes to some processes? Python threads are strange, the OS may not show stats correctly and I'd generally advise multiple processes instead.

Andrew
On Wed, May 17, 2017 at 1:53 AM, <biwa...@gmail.com> wrote:
I am trying to deploy Django project with Channels. After some trial and error I settled on 4 workers with 16 threads each. However as attached screen shows, the processes that are spawned by supervisor have CPU usage at ~15% while threads are around ~1-2%. Number of connections at the moment is less than 100. I tried load testing this setup, and as more messages are coming in the CPU usage is increasing both on processes that were spawned by supervisor and threads of these processes - so there is still disproportion (~50% and ~10%). Is it normal behavior? Any tips to configure it some other way to better balance the load? 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Andrew Godwin

unread,
May 18, 2017, 8:50:14 PM5/18/17
to django...@googlegroups.com
Yes. Running with no --threads option will give you the best spread, but result in more RAM usage. Rather than relying on process statistics via htop or similar, I'd suggest benchmarking actual throughput, as that's the thing you want to optimise for at the end of the day; it might be that one way uses less CPU but has higher throughput, for example.

Andrew

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages