Skip to content

Instantly share code, notes, and snippets.

@devarajchidambaram
Created November 28, 2018 11:40
Show Gist options
  • Save devarajchidambaram/e737eaa4ad147e0aee805ca62419e892 to your computer and use it in GitHub Desktop.
Save devarajchidambaram/e737eaa4ad147e0aee805ca62419e892 to your computer and use it in GitHub Desktop.
Memory and cpu stopping
/**
* Created by prmadi on 8/20/2015.
*/
var http = require('http');
var port = process.env.PORT || '3000';
// Memory Leak
function LeakingClass() {
}
var leaks = [];
setInterval(function() {
for (var i = 0; i < 100; i++) {
leaks.push(new LeakingClass);
}
console.error('Leaks: %d', leaks.length);
}, 1000);
http.createServer(function (req, res) {
// CPU intensive work
var fibonacci = function(n){
if(n < 1){return 0;}
else if(n == 1 || n == 2){return 1;}
else if(n > 2){return fibonacci(n - 1) + fibonacci(n-2);}
};
fibonacci(40);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n'+ fibonaccif(40));
}).listen(port, '127.0.0.1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment