2

When doing some tests with flask-socketio (on uwsgi with gevent) we noticed that when adding more clients, cpu usage on the socketio process quickly goes to 85%. The weird thing is that it doesn't seem to matter if the clients are in active communication or just all idly waiting.

I used pyflame to analyze what is happening and it seems over 50% of the time is spend in server.py:_service_task most of which is in sleep() and the other part in check_ping_timeout. I was able to find some stackoverflow posts describing the same behavior for idle-wait loops, but the described solution there was to introduce sleep(), which _service_task already does.

This happened with 150 clients on a ec2 t3.small instance. Weird thing is though that it does not happen with 50 clients. (similar behaviour on larger instance type with around 300 clients)

Is this normal? My main issue is that it makes it hard to determine if the server is overloaded or not.

Michielvv
  • 336
  • 4
  • 13
  • 1
    Definitely not normal. This is the problem that happened on Python 2.7 but not on 3, correct? – Miguel Grinberg Oct 05 '19 at 19:05
  • We are on python 2.7, will definitely try with 3 then as we are already working on that upgrade anyway. – Michielvv Oct 06 '19 at 09:10
  • 1
    There is a PR that I just merged that addresses this issue for Python 2.7, I believe. You need to test the master branch of the python-engineio package if you want to see if that helps. – Miguel Grinberg Oct 07 '19 at 10:02
  • Thanks, took me some time to benchmark it again but that fix seems to work great. – Michielvv Oct 23 '19 at 13:09

0 Answers0