nodejs 内存泄漏

监控nodejs的土方法

console.log("Server PID", process.pid)
sudo node --inspect app.jsnode

while true; do curl "http://localhost:1337/"; done数组

cb -n 1000 -c 100 http://127:0:0:1:8999/
top -pid 2322app

几种nodejs内存泄漏缘由

无限制增加的数组dom

无限制设置属性和值curl

任何模块内的私有变量和方法均是永驻内存的ide

大循环,无GC机会ui

function LeakingClass() {
    
}

var leaks = []

var http = require('http')

http.createServer((req, res) => {
    leaks.push(new LeakingClass());
    res.writeHead(200);
    res.end('Hello world');
}).listen(9000)

console.log('Server Pid', process.pid)
_.memoize = function(func, hasher) {
    var memo = {}
    hasher || (hasher = _.identity)
    return function() {
        var key = hasher.apply(this, arguments);
        return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
    }
}
((exports, require, module, __filename, __dirname) => {
    var circle = require('./circle.js')
    console.log('The area of a ' + circle.area(4))
    exports.get = () => circle()
})


for (var i = 0; i < 10000000; i++) {
    var user = {}
    user.name = 'outman'
}

for (var i = 0; i < 1000000; i ++) {
    setTimeout(() => {
        var user = {}
        user.name = 'outman'
    }, 1)
}
var http = require('http');
var crypto = require('crypto');
http.createServer((req, res) => {
    var password = 'ear';
    var salt = crypto.randomBytes(128).toString('base64');
    var hash = crypto.pbkdf2Sync(password, salt, 10000, 512);
    res.writeHead(200);
    res.end('wrwer')
}).listen(1337)

console.log('Server Pid', process.pid)
var http = require('http');
var crypto = require('crypto');
http.createServer((req, res) => {
    var password = 'ear';
    var salt = crypto.randomBytes(128).toString('base64');
    crypto.pbkdf2(password, salt, 10000, 512, () => {
        res.writeHead(200);
        res.end('wrwer')
    })
}).listen(1327)

console.log('Server Pid', process.pid)
相关文章
相关标签/搜索