简体   繁体   English

尽管堆大小相当一致,但node.js RSS内存会随着时间增长

[英]node.js RSS memory grows over time despite fairly consistent heap sizes

I've got a node.js application where the RSS memory usage seems to keep growing despite the heapUsed/heapTotal staying relatively constant. 我有一个node.js应用程序,尽管heapUsed / heapTotal保持相对恒定,但RSS内存使用似乎仍在增长。

Here's a graph of the three memory measurements taken over a week (from process.memoryUsage() ): 这是一周中进行的三个内存测量的图表(来自process.memoryUsage() ):

记忆图

You may note that there's a somewhat cyclical pattern - this corresponds with the application's activity throughout each day. 您可能会注意到存在某种周期性的模式-这与应用程序每天的活动相对应。

There actually does seem to be a slight growth in the heap, although it's nowhere near that of the RSS growth. 实际上,堆似乎确实有小幅增长,​​尽管与RSS增长相去甚远。 So I've been taking heap dumps every now and then (using node-heapdump), and using Chrome's heap compare feature to find leaks. 因此,我一直不时进行堆转储(使用node-heapdump),并使用Chrome的堆比较功能查找泄漏。
One such comparison might look like the following (sorted by size delta in descending order): 一个这样的比较可能如下所示(按大小增量按降序排列):

堆转储

What actually shows up does depend on when the snapshot was taken (eg sometimes more Buffer objects are allocated etc) - here I've tried to take a sample which demonstrates the issue best. 实际显示的内容取决于拍摄快照的时间(例如,有时分配了更多的Buffer对象,等等)-在这里,我尝试使用一个样本来最好地说明问题。

First thing to note is that the sizes on the left side (203MB vs 345MB) are much higher than heap sizes shown in the graph. 首先要注意的是,左侧的大小(203MB与345MB)比图中所示的堆大小高得多。 Secondly, the size deltas clearly don't match up with the 142MB difference. 其次,大小差异显然与142MB的差异不匹配。 In fact, sorting by size delta in ascending order, many objects have be deallocated , which means that the heap should be smaller! 实际上,按大小增量按升序排序,已经释放了许多对象,这意味着堆应该更小!

Does anyone have any idea on: 是否有人对以下内容有任何想法:

  • why is this the case? 为什么会这样呢? (RSS constantly growing with stable heap size) (RSS以稳定的堆大小不断增长)
  • how can I stop this from happening, short of restarting the server every now and then? 我如何才能阻止这种情况的发生,而又不时地重新启动服务器呢?

Other details: 其他详情:
Node version: 0.10.28 节点版本:0.10.28
OS: Ubuntu 12.04, 64-bit 操作系统:Ubuntu 12.04,64-bit

Update: list of modules being used: 更新:正在使用的模块列表:

Thanks for reading. 谢谢阅读。

The difference you see between RSS usage and heap usage are buffers. 您看到的RSS使用率和堆使用率之间的区别是缓冲区。

"A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap" https://nodejs.org/api/buffer.html#buffer_buffer “缓冲区类似于整数数组,但对应于V8堆之外的原始内存分配” https://nodejs.org/api/buffer.html#buffer_buffer

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

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