Node.JS 进程使用了​​ 1.4 GB 的内存,但是 heapdump 只有 300 MB [英] Node.JS process uses 1.4 GB of memory, but heapdump is only 300 MB

查看:25
本文介绍了Node.JS 进程使用了​​ 1.4 GB 的内存,但是 heapdump 只有 300 MB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个带有 Node.JS 的 Socket.IO 服务器,它通常使用大约 400 MB 的内存,因为有很多数据被缓存发送到客户端.然而,几个小时后,它突然开始在大约 40 分钟内增长到 1.4 GB.有人告诉我用heapdump来查找是否有内存泄漏.

I'm running a Socket.IO server with Node.JS, which normally uses about 400 MB of memory, because there's a lot of data being cached to send to clients. However, after a couple of hours it suddenly starts growing to 1.4 GB of usage over about 40 minutes. Someone told me to use heapdump to find if there is a memory leak.

问题是 heapdump 结果只有 317 MB,里面没有任何异常,所以我一直在调试.我也用 nodetime 运行过它,它说 V8 堆使用量约为 400 MB,但 V8 堆总大小为 1.4 GB.

The problem is that the heapdump only turned out to be 317 MB and nothing in it looks out of the ordinary, so I'm stuck with debugging. I've also run it with nodetime, which says that the V8 heap usage is around 400 MB, but the total V8 heap size is 1.4 GB.

如何找出剩余的 1 GB 来自哪里?

How do I find out where the remaining 1 GB comes from?

推荐答案

也许 node-memwatch 可以帮到你?

Maybe node-memwatch could help you?

https://github.com/lloyd/node-memwatch

来自自述文件:

node-memwatch 可帮助您检测和查找内存泄漏Node.JS 代码.它提供:

node-memwatch is here to help you detect and find memory leaks in Node.JS code. It provides:

泄漏事件,当您的代码出现内存泄漏时发出.

A leak event, emitted when it appears your code is leaking memory.

一个 stats 事件,偶尔发出,为您提供描述您的数据的数据堆使用情况和随时间变化的趋势.

A stats event, emitted occasionally, giving you data describing your heap usage and trends over time.

一个 HeapDiff 类,可让您比较堆的状态两个时间点,告诉你什么已经分配,​​什么已经分配已发布.

A HeapDiff class that lets you compare the state of your heap between two points in time, telling you what has been allocated, and what has been released.

这篇关于Node.JS 进程使用了​​ 1.4 GB 的内存,但是 heapdump 只有 300 MB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆