[英]Nancy on Linux is using 100% CPU
My nancy web-apps are using up together 100% CPU without them actually being used. 我的nancy Web应用程序一起消耗了100%的CPU,而实际上并未使用它们。
They are running inside a docker container on mono. 它们在mono上的docker容器内运行。 The only thing I could think about to cause this, would be the endless loop in my main function, something like
我唯一能想到的原因是主函数中的无尽循环,例如
while(Console.ReadLine() != "quit") {}
but I thought, Console.ReadLine()
would be blocking and therefore this loop would only execute, whenever there is some input, which there shouldn't be ever. 但我认为,
Console.ReadLine()
会阻塞,因此,只有在有一些输入(永远都不会存在)时,才会执行此循环。 Amy I missing something? 艾米,我想念什么吗? Are there other reasons for nancy to use up all the CPU in mono?
南希还有其他原因要用完Mono中的所有CPU吗? - In Windows during development it seems to run fine.
-在Windows开发过程中,它似乎运行良好。
Update: 更新:
The application in docker is simply started with mono NancyServer.exe
. mono NancyServer.exe
的应用程序仅由mono NancyServer.exe
启动。 The memory usage is much lower than the previous XPS-base version (50-70MB instead of 160-180MB), but the XPS-based application uses less than 0.1% of CPU (also not really doing anything) 内存使用率比以前的基于XPS的版本要低得多(50-70MB而不是160-180MB),但是基于XPS的应用程序使用的CPU不到0.1%(也没有做任何事情)
I can reproduce the non-blocking behaviour by starting a container in the foreground if none of the -t
or -i
options are used. 如果不使用
-t
或-i
选项,则可以通过在前台启动容器来重现非阻塞行为。 In that particular case then Console.ReadLine()
won't block. 在这种情况下,
Console.ReadLine()
不会被阻止。
If either -i
or -t
is used, then Console.ReadLine
blocks. 如果使用
-i
或-t
,则Console.ReadLine
块。 Also if I run the container in the background (with the -d
option ), Console.ReadLine()
is blocking. 另外,如果我在后台运行容器(使用
-d
选项 ),则Console.ReadLine()
会阻塞。
Make sure to use either -t
or -i
if you run your container in the foreground. 如果在前台运行容器,请确保使用
-t
或-i
。
The high CPU load is caused by that while loop because you don't put the current thread to sleep for a short time. 高CPU负载是由while循环引起的,因为您不会使当前线程短时间进入睡眠状态 。 Like:
喜欢:
while(Console.ReadLine() != "quit") {Thread.Sleep(10);}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.