Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将mongodb gridstore导出到web响应时Node.js内存泄漏_Node.js_Mongodb_Memory Leaks - Fatal编程技术网

将mongodb gridstore导出到web响应时Node.js内存泄漏

将mongodb gridstore导出到web响应时Node.js内存泄漏,node.js,mongodb,memory-leaks,Node.js,Mongodb,Memory Leaks,当我将一个大型视频文件从MongoDB GridStore对象传输到web响应时,我遇到了内存泄漏的问题。我在用快车。我的代码(为了简洁起见省略了一些内容)如下: // "res" is the response for this Express route. // response header values are set outside this block // gridstore, etc. are define above the part that counts, here

当我将一个大型视频文件从MongoDB GridStore对象传输到web响应时,我遇到了内存泄漏的问题。我在用快车。我的代码(为了简洁起见省略了一些内容)如下:

// "res" is the response for this Express route.
// response header values are set outside this block
// gridstore, etc. are define above the part that counts, here
    gridStore.open(function (err, gs) {

    gs.seek(rangeObj.start, function (err, gs) {
        var current = 0,
            stream = gs.stream(true);

        stream.pipe(res);

        res.on("close", function () {
            console.log("socket closed");
            if(res){
                res.end();
                res = null;
            }
            if(gs){
                gs.close(function(){
                    gs.destroy();
                    gs = null;
                    if(db){
                        db.close(true, function(){
                            db = null;
                            gridStore = null;
                        });
                    }
                });
            }

        });

        stream.on("end", function () {
            console.log("stream ended");
            if(res){
                res.end();
                res = null;
            }
            if(gs){
                gs.close(function(){
                    gs = null;
                    if(db){
                        db.close(true, function(){
                            db = null;
                            gridStore = null;
                        });
                    }
                });
            }
        });

        stream.on("close", function(){
            console.log("stream closed");

            if(res){
                res.end();
                res = null;
            }
            if(gs){
                gs.close(function(){
                    gs = null;
                    if(db){
                        db.close(true, function(){
                            db = null;
                            gridStore = null;
                        });
                    }
                });
            }
        });
    });
});
正如你所看到的,我正在努力清理自己。从我的努力中发现了很多不必要的东西。虽然,也许我错过了什么

视频流很好。然而,这个过程占用了越来越多的内存,似乎没有上限。即使让进程空闲几个小时,它似乎也不会释放内存


我已经尝试公开垃圾收集器并在响应关闭时运行(甚至每隔5秒)。我还尝试使用--always compact标志执行节点进程。我在Windows7和Ubuntu12.04(两者都是节点0.10.4)中遇到了同样的问题

您确定在发送到客户端时没有发生缓冲吗?我想知道流上的TCP背压是否会一直通过您的代码。我怀疑不是,而且响应数据正在某个地方缓冲。我也有这个想法。因此,我添加了一个做同样事情的文件系统实现,即使有10个同步流,它也不会像那样停止(最高300兆字节,而不是12兆字节)。实际上,唯一的区别是,在一种情况下,我从gridStore将其管道化,而在另一种情况下,我从文件系统将其管道化。我想会有更多的开销,但司机似乎有点不对劲。