5

I have an Express.js web app which is constantly breaking because of memory problems:

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). 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:

{ 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; but with htop the memory usage is about 2GB when it breaks.

The question is, if my assumptions are right, what could be using non-heap memory that is still reported by htop as RES memory?

4

1 回答 1

4

我以前见过这种情况,其中报告的已使用内存比 htop 看到的内存要小得多。

在我们的案例中,它是 JavaScript 中的内存泄漏,看起来很小,但修复后解决了内存问题。

我写了一篇文章,详细说明了我诊断它所采取的步骤,在这里发帖太长了。

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

于 2016-10-14T15:15:35.767 回答