Tokio runtime: CPUs get maxed when serving many requests #2915
-
Version Platform
Description A basic TCP-based web server, using tokio, when serving many requests, causes one or more CPUs to start running at 100% and never stop running. The repro might be hard, sorry about that. To repro, run the program below, and spam GET requests at it (holding down F5 on a web browser usually triggered it within a few seconds, or you can write a script that spams GETs). In Task Manager, you can see the CPU usage of the program jump to 100/n % (where n is the number of CPUs). Sometimes it's k * 100/n % (where k is 1-4), but usually 100/n. Once the problem has been triggered, the CPU usage will never drop, even when you stop sending requests, and the program should be idle. When I ran this program with a custom single-threaded tokio runtime, the program completely hung when the problem was triggered. When I ran the program in Visual Studio with profiling turned on, after the problem was triggered, the profiler showed (in descending order of Total CPU):
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Have you verified that it isn't stuck in an infinite loop in |
Beta Was this translation helpful? Give feedback.
Have you verified that it isn't stuck in an infinite loop in
parse_method
? That will happen if the stream is closed before that function returns.