简体   繁体   English

在Node.js / Express.js应用程序中查找内存泄漏

[英]Find Memory Leak on Node.js / Express.js Application

I have an Express.js web app which is constantly breaking because of memory problems: 我有一个Express.js网络应用程序,由于内存问题不断打破:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap
out of memory

When I start the service, the memory usage is about 170Mb (reported by htop as RES memory). 当我启动服务时,内存使用量约为170Mb(由htop报告为RES内存)。 Then I start throwing request at it, and the memory start rising. 然后我开始向它发出请求,内存开始上升。 I'm using memwatch to try to track the problem in what looks like a memory leak, but a memwatch.HeapDiff() reports something like: 我正在使用memwatch尝试跟踪看起来像内存泄漏的问题,但是memwatch.HeapDiff()报告的内容如下:

{ before: { nodes: 2093729, size_bytes: 197165296, size: '188.03 mb' },
  after: { nodes: 2491264, size_bytes: 232097040, size: '221.34 mb' },
  ...

... where I understand that the app is using 221.34mb for the heap; ...我明白应用程序正在使用221.34mb的堆; but with htop the memory usage is about 2GB when it breaks. 但是使用htop ,内存使用量在中断时大约为2GB。

The question is, if my assumptions are right, what could be using non-heap memory that is still reported by htop as RES memory? 问题是,如果我的假设是正确的,那么什么可以使用仍然由htop报告的非堆内存作为RES内存?

I've seen this before , where memory reported in used was much smaller that memory as seen by htop. 我以前见过这个,其中使用的内存比htop看到的内存要小得多。

In our case it was a memory leak in JavaScript that looked small, but when was fixed resolved the memory issue. 在我们的例子中,JavaScript中的内存泄漏看起来很小,但是当修复时解决了内存问题。

I wrote a post detailing the steps I took to diagnose it, it's too long to post in here. 我写了一篇文章,详细说明了我诊断它的步骤,这里发布的时间太长了。

https://www.alexkras.com/simple-guide-to-finding-a-javascript-memory-leak-in-node-js/ https://www.alexkras.com/simple-guide-to-finding-a-javascript-memory-leak-in-node-js/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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