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)
相關文章
相關標籤/搜索