简体   繁体   English

Node.js如何检查服务器应用程序中是否有某些代码被阻止

[英]Node.js how to check if some code is blocking in a server application

I've written a server application in node.js which receives inbound error messages from some hardware using socket.io and an RS232 wireless device. 我已经在node.js中编写了一个服务器应用程序,该应用程序使用socket.io和RS232无线设备从某些硬件接收入站错误消息。

My server has been receiving error messages perfectly for the past 2 months, but for the last 2 days the server has been randomly locking up and won't respond to any inbound messages until Ctrl + C is pressed in the terminal. 在过去的两个月中,我的服务器一直在完美地接收错误消息,但是在最近的两天中,服务器一直被随机锁定,并且在终端中按Ctrl + C之前不会响应任何入站消息。 I would normally expect this to shut the server down, but when the server blocks, Ctrl + C has been unblocking the event loop and then processing inbound messages that seemed to be queued whilst the event loop was blocked (this is only a theory). 我通常希望这能关闭服务器,但是当服务器阻塞时, Ctrl + C会一直阻塞事件循环,然后处理事件循环被阻塞时似乎正在排队的入站消息(这只是一个理论)。

I believe my theory to be correct because the console will hang at a message such as waiting for data... and then pressing Ctrl + C later will batch process 15 requests to push data to my back end. 我相信我的理论是正确的,因为控制台将挂在诸如waiting for data...类的消息上,然后稍后按Ctrl + C将批处理15个将数据推送到我的后端的请求。

Initially I can't spot any problems in my code and I'm more baffled due to the application running without problems for 2 months. 最初,我无法在代码中发现任何问题,而且由于该应用程序运行了2个月没有出现问题,我感到更加困惑。 My question here is, are there any easy to use profiling tools to see where exactly my server application is freezing? 我的问题是,是否有任何易于使用的分析工具来查看我的服务器应用程序在哪里冻结?

Maybe you can find the problem using flamegraphs http://www.brendangregg.com/flamegraphs.html . 也许您可以使用火焰图http://www.brendangregg.com/flamegraphs.html找到问题。 You can find more information here 您可以在这里找到更多信息

Aditionally i recommend you to memory profile your application because problems appearing after some time is a common sign of that issue. 另外,我建议您对应用程序进行内存配置,因为一段时间后出现问题是该问题的常见征兆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM