简体   繁体   English

node.js memwatch追逐内存泄漏

[英]node.js memwatch chasing a memory leak

I've been chasing a pretty bad memory leak in a node program. 我一直在节点程序中追逐非常糟糕的内存泄漏。

I'm using the memwatch module HeapDiff() to try to identify the offending objects. 我正在使用memwatch模块HeapDiff()尝试识别有问题的对象。

HeapDiff's report shows two suspect elements in the details array, ("Array" and "String", each of which have grown considerably. HeapDiff的报告显示了detail数组中的两个可疑元素(“ Array”和“ String”),每个元素的增长都很大。

I'm officially lost and have no idea how to narrow down the possible culprits. 我正式迷路了,不知道如何缩小可能的罪魁祸首。 There are dozens of google-able howtos but none of them make any sense to me. Google提供了数十种方法,但是对我来说都没有任何意义。 The program in question uses quite a few 3rd party modules including carrier, dequeue and mqtt. 该程序使用了很多第三方模块,包括运营商,出队和mqtt。 It's 318 lines of code so I've not posted it. 它是318行代码,所以我还没有发布。

I'd appreciate any pointers as to what my next step should be... 对于下一步应该做什么,我将不胜感激。

Here's an extract of the memwatch HeapDiff dump: 这是memwatch HeapDiff转储的摘录:

   {
    "before": {
        "nodes": 25312,
        "time": "2014-09-01T10:59:24.000Z",
        "size_bytes": 3596320,
        "size": "3.43 mb"
    },
    "after": {
        "nodes": 125705,
        "time": "2014-09-01T11:14:24.000Z",
        "size_bytes": 20255728,
        "size": "19.32 mb"
    },
    "change": {
        "size_bytes": 16659408,
        "size": "15.89 mb",
        "freed_nodes": 674,
        "allocated_nodes": 101067,
        "details": [
           {
                "what": "Array",
                "size_bytes": 348440,
                "size": "340.27 kb",
                "+": 1592,
                "-": 295
            },
            {
                "what": "String",
                "size_bytes": 12580056,
                "size": "12 mb",
                "+": 50329,
                "-": 20
            }
        ] 

Without code samples, it's hard to get into detail, but at a high level... 没有代码示例,很难详细介绍,但是要从总体上讲...

What I did was look not just at the categories that were biggest (because mine were also Array and String[1]) but looked for object types I could track down; 我所做的不仅是查看最大的类别(因为我的类别也是Array和String [1]),而是寻找可以追踪的对象类型; find rows that have any notable growth at all and unique looking "what" entries, then find where those are in your code. 找到根本没有明显增长的行和唯一看起来“什么”的条目,然后找到这些行在代码中的位置。 Make new diffs around your usage of those, and narrow in or spread out until you find your growth points. 围绕这些用法进行新的区分,然后缩小或扩展直到找到增长点。

If you can't find suspect-looking object names, just divide your main execution path into two or three parts and run HeapDiffs for each of those. 如果找不到看起来可疑的对象名称,只需将主执行路径分为两部分或三部分,然后为每个对象运行HeapDiffs。 (what are you currently using to trigger your HeapDiff? startup and .on('leak')?) (您当前使用什么来触发HeapDiff?启动和.on('leak')?)

  1. By the way, that's not saying there's a single string that's 12mb. 顺便说一句,这并不是说有一个12mb的字符串。 It's saying there are 12mb worth of strings -- actually, 12mb more of strings than there were at the front end of the diff. 据说有12mb的字符串-实际上,比diff前端 12mb的字符串。 Those 12mb are spread out over the 50329 new strings. 那些12mb分布在50329个新字符串上。 So, still, they're reasonably large. 因此,它们仍然很大。

May I suggest you to try the IDDE tools and see if this will help you to track down the leak? 我可以建议您尝试使用IDDE工具,看看这是否有助于您跟踪泄漏吗? please see this [link]:( What diagnostic tools are available for Node.js applications? ) for some information. 请参阅此[link] :( Node.js应用程序可使用哪些诊断工具? )以获取一些信息。 If you need more information to get started, I am more than happy to help. 如果您需要更多信息以开始使用,我们非常乐意为您提供帮助。

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

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