pipe, large fs, capture mem usage

This commit is contained in:
Jean-Francois 2013-11-22 13:08:26 +01:00
parent 5163e2c11e
commit f37bf9e65f
3 changed files with 67 additions and 1 deletions

View File

@ -26,6 +26,24 @@
var filename = __filename;
var fs = require('fs');
var path = require('path');
if(process.argv[2] === '-large') {
var tmpDir = require("../../../../test/common.js").tmpDir;
filename = path.join(tmpDir, 'fs-leak1.txt');
print('building large content...');
var content;
for (var i = 0; i < 1024 * 1024; i++) {
content += 'hello worldçoié\uD83D\uDC4D\n';
}
print('done building content');
var fd = fs.openSync(filename, 'w+');
var buff = new Buffer(content);
fs.writeSync(fd, buff, 0, buff.length, 0)
process.on('exit', function() {
require('fs').unlinkSync(filename);
})
}
var perf = require("../perf/common-perf");
perf.startPerf(readFile, 100);

View File

@ -29,7 +29,16 @@ var perf = require("../perf/common-perf");
var net = require('net');
var body = 'hello world\n';
var PORT = 9999;
var PORT;
if (process.argv[2] === '-pipe') {
PORT = require("../../../../test/common.js").PIPE;
process.on('exit', function() {
require('fs').unlinkSync(PORT);
})
} else {
PORT = 9999;
}
var server = net.createServer(function(res) {
res.end(body);

View File

@ -25,6 +25,8 @@
var start = 0;
var count = 0;
var go = true;
var util = require('util');
var memStart;
function startPerf(fstart, time) {
start = process.hrtime();
setTimeout(function() {
@ -37,7 +39,33 @@ exports.startPerf = startPerf;
function round(n) {
return Math.floor(n * 100) / 100;
}
function memToString(mem) {
if (java) {
return mem.toString();
} else {
return util.inspect(mem)
}
}
function captureMemory() {
if (java) {
return java.lang.management.ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()
} else {
return process.memoryUsage();
}
}
function diffMemory(start, end) {
if (java) {
return end.used - start.used;
} else {
return end.heapUsed - start.heapUsed;
}
}
function forceGC() {
for (var i = 0; i < 10; i++) {
global.gc();
}
}
function dumpResults() {
var end = process.hrtime();
process.stdout.write('\n');
@ -53,12 +81,23 @@ exports.dumpResults = dumpResults;
function canContinue() {
if (!go) {
dumpResults();
console.log("Ending...");
forceGC();
var memEnd = captureMemory();
console.log("Memory after gc \n" + memToString(memEnd));
console.log("Heap Diff " + diffMemory(memStart, memEnd));
process.exit(0);
}
return true;
}
exports.canContinue = canContinue;
function actionStart() {
if(count == 5) {
console.log("Capturing mem...")
forceGC();
memStart = captureMemory()
console.log("mem " + memToString(memStart));
}
count++;
if (!(count % 1000)) {
process.stdout.write('.');