[英]Node.js memory leak, despite constant Heap + RSS sizes
According to my server monitoring, my memory usage is creeping up over time: 根据我的服务器监控,我的内存使用量随着时间的推移逐渐增加:
After ~4 weeks of uptime, it ends up causing problems / crashing (which makes sense, given that I'm on EC2 with m1.large instances => 8GB RAM, and RAM seems to be increasing at about 1.5 GB / week). 在正常运行约4周后,它最终导致问题/崩溃(这是有道理的,因为我在EC2上使用m1.large实例=> 8GB RAM,并且RAM似乎以每周约1.5 GB的速度增加)。
If I restart my node.js app, the memory usage resets. 如果我重新启动我的node.js应用程序,内存使用情况将重置。 Yet... I'm keeping track of my memory usage via process.memoryUsage()
, and even after ~1 week, I'm seeing 然而......我通过process.memoryUsage()
跟踪我的内存使用情况,甚至在大约1周后,我看到了
{"rss":"693 Mb","heapTotal":"120 Mb","heapUsed":"79 Mb"}
What am I missing? 我错过了什么? Clearly the leak is in node, yet the process seems to not be aware of it... 显然泄漏是在节点中,但过程似乎没有意识到它......
You can try node-memwatch module, which helps with leak detection and heap diffing in Node. 您可以尝试node-memwatch模块,它有助于在Node中进行泄漏检测和堆差异。
Heap diff would look similar to: 堆差异看起来类似于:
{
"before": { "nodes": 11625, "size_bytes": 1869904, "size": "1.78 mb" },
"after": { "nodes": 21435, "size_bytes": 2119136, "size": "2.02 mb" },
"change": { "size_bytes": 249232, "size": "243.39 kb", "freed_nodes": 197,
"allocated_nodes": 10007,
"details": [
{ "what": "String",
"size_bytes": -2120, "size": "-2.07 kb", "+": 3, "-": 62
},
{ "what": "Array",
"size_bytes": 66687, "size": "65.13 kb", "+": 4, "-": 78
},
{ "what": "LeakingClass",
"size_bytes": 239952, "size": "234.33 kb", "+": 9998, "-": 0
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.