[Node.js] Identify memory leaks with nodejs-dashboard
2023-09-14 09:00:52 时间
In this lesson, I introduce a memory leak into our node.js application and show you how to identify it using the Formidable nodejs-dashboard. Once identified, we will add garbage collection stats to the error console allowing us to correlate garbage collection with the increased memory usage.
Install:
npm i -D gc-profiler nodejs-dashboard
let express = require('express'); let router = express.Router(); let faker = require('faker'); let words = []; let profiler = require('gc-profiler'); profiler.on('gc', (info) => { console.error(info); }); router.get('/', function(req, res, next) { let num = Math.floor(Math.random() * 1000) + 1; let searchterm = faker.lorem.words(num); let arr = searchterm.split(' '); arr.forEach(word => { words.push(word); // cause memory leak }); console.log(`Generating ${num} words`); res.send(searchterm); }); module.exports = router;
In the code, we can use 'gc-profiler' to monitor the gb collection in order to see the memory leak in dashboard.
相关文章
- 这些js手写题你能回答上来几道
- php 中js跳转页面跳转页面,js跳转代码_PHP页面跳转 Js页面跳转代码[通俗易懂]
- linux如何安装node.js_centos安装nodejs
- Node.JS 学习记录(01)
- js中settimeout()的用法详解_低噪放工作原理
- JS设置定时器_js设置定时器
- js 数组去除重复数据-当WPS开始像支持VBA一样支持JS语言时,微软又该何去何从?
- 【JS 逆向百例】猿人学系列 web 比赛第五题:js 混淆 - 乱码增强,详细剖析
- 【源码】PDF.js批注注释插件库(纯JS). 创建和保存PDF批注(PDF 高亮/签名/插图/截屏/文本框/画笔/多边形)-pdf.js
- 快速在Linux平台上安装Node.js(node安装linux)
- Node.js与MongoDB:联手打造高效应用(node与mongodb)
- Linux上的JS压缩工具(js压缩工具linux)
- Node.js与MySQL:构建高效的后端应用程序(nodejs与mysql)
- nodejs使用Node.js优雅地整合MongoDB(mongodb整合)
- 利用 JS 实现 Redis 的连接(js连接redis)
- Node.js连接MSSQL数据库的操作指南(node 链接mssql)
- Node.js和MSSQL数据库的完美结合:使用node mssql模块(node mssql模块)
- 数据JS技术实现实时获取Oracle数据(js实时获取oracle)
- JS实时链接Oracle让数据库访问更便捷(js实时连接oracle)
- 用JavaScript获取网页中的js、css、Flash等文件
- JS函数验证总结(方便js客户端输入验证)
- js对象之JS入门之Array对象操作小结
- 跟我学Nodejs(三)---Node.js模块