Multi-client websocket handler overload

154 views
Skip to first unread message

Alena Kazakova

unread,
Dec 3, 2020, 8:37:05 PM12/3/20
to Tornado Web Server
Hello,

I'm using tornado server as a middle-man between multiple web clients and worker clients. Those clients are mapped to each other and tornado websocket handlers forward messages between them. When multiple connections are opened and each client sends frequent messages, and so do the workers, and tornado also pings connections, it freezes. As far as I understood, that's because tornado is single-threaded. How could I solve this problem? 

Thanks,

Alena Kazakova

Ben Darnell

unread,
Dec 6, 2020, 10:09:02 PM12/6/20
to Tornado Mailing List
What is your CPU utilization like when this happens? If it's less than 100% of one CPU thread, then the most likely answer is that you're not actually overloaded but you're doing something to block the event loop. Set the environment variable PYTHONASYNCIODEBUG=1 and see if that points out any blocking operations.

If your CPU reaches 100% of one CPU thread, then you are actually reaching the capacity of one python process and need to run more. Note that you must run more *processes*, not just more threads - the python global interpreter lock (GIL) means that adding more threads to a python program won't help you use more CPUs effectively. This traditionally means introducing a load balancer to direct requests across your multiple processes, although the relatively recent (erm, 2013, so not so recent now) introduction of the SO_REUSEPORT option should simplify this (assuming your multi-process workload fits within one machine).

Tornado has a built-in multi-process mode (see the `bind` and `start` methods of `HTTPServer`: https://www.tornadoweb.org/en/stable/httpserver.html), although I don't really recommend it these days - try SO_REUSEPORT first.

-Ben


--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-tornado/5f1dbb81-06ed-4b75-abd3-d4431c6046c5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages