Node.js Application Troubleshooting Manual — Correctly Enabling Chrome DevTools

Intro

High CPU Usage

1. Export the JS Code Running Status

npm install v8-profiler --save
'use strict';const v8Profiler = require('v8-profiler');
const title = 'test';
v8Profiler.startProfiling(title, true);
setTimeout(() => {
const profiler = v8Profiler.stopProfiling(title);
profiler.delete();
console.log(profiler);
}, 5000);

2. Analyze the CPU Profile

  • Self Time: the time when the code segment of this function is executed (excluding any calls)
  • Total Time: the total execution time of this function and other functions it calls
  • Aggregated self time: the total execution time of the code segment of the function itself after aggregation during CPU sampling (excluding other calls)
  • Aggregated total time: the total execution time of this function and other functions it calls after aggregation during CPU sampling

Memory Leakage

1. Determining Whether Memory is Leaking

2. Export the JS Heap Memory Snapshot

npm install heapdump --save
'use sytrict';const heapdump = require('heapdump');
heapdump.writeSnapshot('./test' + '.heapsnapshot');

3. Analyze the Heap Snapshot

  • Object 1 dominates object 2
  • Objects 2 dominates object 3, 4, and 5
  • Object 4 dominates object 6
  • Object 5 dominates object 7
  • Object 6 dominates object 8
  • The Retained Size of object 3: RZ_3 = SZ_3
  • The Retained Size of object 7: RZ_7 = SZ_7
  • The Retained Size of object 8: RZ_8 = SZ_8
  • The Retained Size of object 6: RZ_6 = SZ_6 + RZ_8 = SZ_6 + SZ_8
  • The Retained Size of object 5: RZ_5 = SZ_5 + RZ_7 = SZ_5 + SZ_7
  • The Retained Size of object 4: RZ_4 = SZ_4 + RZ_6 = SZ_4 + SZ_6 + SZ_8
  • The Retained Size of object 2: RZ_2 = SZ_2 + RZ_3 + RZ_4 + RZ_5 = SZ_2 + SZ_3 + SZ_4 + SZ_5 + SZ_6 + SZ_7 + SZ_8
  • The Retained Size of GC root 1: RZ_1 = SZ_1 + RZ_2 = SZ_1 + SZ_2 + RZ_3 + RZ_4 + RZ_5 = SZ_2 + SZ_3 + SZ_4 + SZ_5 + SZ_6 + SZ_7 + SZ_8

Conclusion

Original Source

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Now we will create Angular application and connect with NodeJS.

ReactJS Props

Add Flair to Your React Projects with Imported Images and Gifs

Deploy node application and postgreSql database to heroku

Creating A React App

Node.js Application Troubleshooting Manual - Comprehensive GC Problems and Optimization

How to hire and vet Angular developers in 2020

React.js — Ways to Bind Events

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

How to detect memory leak using BPF

How To Store And Retrieve RedisJSON on Redis Cloud using Node.js

Using Cypress Intercept to Fix a Cross-Domain Test

Build a Reliable Node API with TypeORM using Transactions