简体   繁体   English

如何调试Nodejs导致100%的CPU使用率

[英]How to debug Nodejs causing 100% CPU usage

I have a node app that uses express and get data from mongodb and elastic search. 我有一个节点应用程序,使用快递和从mongodb和弹性搜索获取数据。 On our production server, after some time, it starts to use CPU 100%, which makes the app unresponsive and we had to kill the process to make system idle. 在我们的生产服务器上,一段时间后,它开始使用CPU 100%,这使得应用程序无响应,我们不得不终止进程以使系统空闲。

I think there is a certain query (code) which is causing this issue. 我认为有一个查询(代码)导致了这个问题。 What are the latest practises to debug this kind of issue? 调试此类问题的最新做法是什么?

Start your app using: 使用以下方式启动应用

node --prof app.js

It will dump a tick file in the current directory. 它会将tick文件转储到当前目录中。 Use the app, so the profiler can collect some data. 使用该应用程序,以便探查器可以收集一些数据。 Then stop the app, and analyse the tick file: 然后停止应用程序,并分析刻度文件:

node --prof-process tick_file.log

This will give you breakdown of all calls, and you can find out which functions are hogging up the process. 这将为您提供所有呼叫的细分,并且您可以找出哪些功能正在占用该过程。 (Note that this second command might take a bit of time.) (请注意,第二个命令可能需要一些时间。)

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

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