简体   繁体   中英

How to debug Nodejs causing 100% CPU usage

I have a node app that uses express and get data from mongodb and elastic search. 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.

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. 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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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