Multi-client websocket handler overload

Skip to first unread message

Alena Kazakova

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

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? 


Alena Kazakova

Ben Darnell

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`:, although I don't really recommend it these days - try SO_REUSEPORT first.


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
To view this discussion on the web visit
Reply all
Reply to author
0 new messages