Permalink
Browse files

Fork bench pending

  • Loading branch information...
1 parent 3999245 commit dbb1b1772f6f9414f66c203ad6280b6014937308 @sdolard committed Dec 16, 2011
Showing with 117 additions and 36 deletions.
  1. +0 −1 lib/log-to-file-fork.js
  2. +117 −35 test/log-to-file-bench.js
View
1 lib/log-to-file-fork.js
@@ -36,7 +36,6 @@ function mergeObjects(){
for (prop in arguments[i]) {
out[prop] = arguments[i][prop];
}
-
}
return out;
}
View
152 test/log-to-file-bench.js
@@ -3,6 +3,7 @@ path = require('path'),
util = require('util'),
fs = require('fs'),
logToFile = require('../lib/log-to-file'),
+logToFileFork = require('../lib/log-to-file-fork'),
dataTest = '0',
ONE_K = 1024,
ONE_M = ONE_K * 1024,
@@ -13,39 +14,39 @@ benchParams = [
{
fileMaxSize: ONE_M * 5,
maxBackupFileNumber: 0
- },
+ }/*,
{
- fileMaxSize: ONE_M * 5,
- maxBackupFileNumber: 0,
- gzipBackupFile: true
+ fileMaxSize: ONE_M * 5,
+ maxBackupFileNumber: 0,
+ gzipBackupFile: true
},
{
- fileMaxSize: ONE_M * 5,
- maxBackupFileNumber: 5
+ fileMaxSize: ONE_M * 5,
+ maxBackupFileNumber: 5
},
{
- fileMaxSize: ONE_M * 5,
- maxBackupFileNumber: 5,
- gzipBackupFile: true
+ fileMaxSize: ONE_M * 5,
+ maxBackupFileNumber: 5,
+ gzipBackupFile: true
},
{
- fileMaxSize: ONE_M * 5,
- maxBackupFileNumber: 10
+ fileMaxSize: ONE_M * 5,
+ maxBackupFileNumber: 10
},
{
- fileMaxSize: ONE_M * 5,
- maxBackupFileNumber: 10,
- gzipBackupFile: true
+ fileMaxSize: ONE_M * 5,
+ maxBackupFileNumber: 10,
+ gzipBackupFile: true
},
{
- fileMaxSize: ONE_M * 10,
- maxBackupFileNumber: 10
+ fileMaxSize: ONE_M * 10,
+ maxBackupFileNumber: 10
},
{
- fileMaxSize: ONE_M * 10,
- maxBackupFileNumber: 10,
- gzipBackupFile: true
-}], bi = 0;
+ fileMaxSize: ONE_M * 10,
+ maxBackupFileNumber: 10,
+ gzipBackupFile: true
+}*/], bi = 0;
for ( i = 0; i < 1024; ++i) {
tmp += dataTest;
@@ -70,6 +71,89 @@ function octetToHuman(o) {
}
+function cleanup() {
+ dirs = fs.readdirSync(__dirname);
+ RE = /benchtest.txt.*/i;
+ for (i = 0; i < dirs.length; i++)
+ {
+ if (!RE.test(dirs[i])){
+ continue;
+ }
+ fs.unlinkSync(path.normalize(__dirname + '/' + dirs[i]));
+ }
+}
+
+function runTestFork() {
+
+ var
+ size = 0,
+ log,
+ elements = 1024 * 1024,
+ start, end, writtingEventCount = 0,
+ wcount = 0,
+ config = benchParams[bi];
+
+ if (benchParams.length === bi) {
+ console.log('All done');
+ return;
+ }
+ if (bi === 0) {
+ console.log('---------------------------------------------------------');
+ console.log('Starting fork interface benchs');
+ console.log('---------------------------------------------------------');
+ }
+ log = logToFileFork.create({
+ directory: __dirname,
+ fileName: 'benchtest.txt',
+ fileMaxSize: config.fileMaxSize,
+ maxBackupFileNumber: config.maxBackupFileNumber,
+ gzipBackupFile: config.gzipBackupFile || false,
+ verbose: config.verbose || false
+ }, function() {
+ for (i = 0; i < elements; i++) {
+ log.write(dataTest);
+ size += dataTest.length;
+ }
+ });
+ console.log('Running fork bench %d . fileMaxSize: %s, maxBackupFileNumber: %d, gzipBackupFile: %d', bi,
+ octetToHuman(log.fileMaxSize),
+ log.maxBackupFileNumber,
+ log.gzipBackupFile);
+ bi++;
+ log.on('writting', function(fileName){
+ if (writtingEventCount === 0) {
+ start = Date.now();
+ }
+ writtingEventCount ++;
+ });
+
+ log.on('write', function(fileName){
+ if (wcount % 1024 === 0) {
+ util.print(".");
+ }
+ wcount++;
+ });
+
+ log.on('written', function(fileName){
+ var duration;
+ end = Date.now();
+ duration = end - start;
+ console.log('Total:%s in %dms: %s/s',
+ octetToHuman(size),
+ duration,
+ octetToHuman(size * 1000 / duration));
+
+ setTimeout(cleanup, 10);
+ setTimeout(runTestFork, 10);
+
+ log.terminate();
+
+ });
+ log.on('error', function(err){
+ console.log(err);
+ });
+}
+
function runTest() {
var
@@ -81,20 +165,15 @@ function runTest() {
config = benchParams[bi];
if (benchParams.length === bi) {
- //clean up
- dirs = fs.readdirSync(__dirname);
- RE = /benchtest.txt.*/i;
- for (i = 0; i < dirs.length; i++)
- {
- if (!RE.test(dirs[i])){
- continue;
- }
- //console.log('unlink: %s', dirs[i]);
- fs.unlinkSync(path.normalize(__dirname + '/' + dirs[i]));
- }
- console.log('All done');
+ bi = 0;
+ setTimeout(runTestFork, 10);
return;
}
+ if (bi === 0) {
+ console.log('---------------------------------------------------------');
+ console.log('Starting standard benchs');
+ console.log('---------------------------------------------------------');
+ }
log = logToFile.create({
directory: __dirname,
@@ -132,8 +211,8 @@ function runTest() {
duration,
octetToHuman(size * 1000 / duration));
- setTimeout(runTest, 10);
-
+ setTimeout(cleanup, 10);
+ setTimeout(runTest, 10);
});
log.on('error', function(err){
console.log(err);
@@ -146,5 +225,8 @@ function runTest() {
}
}
-runTest();
+
+cleanup();
+//runTest();
+runTestFork();

0 comments on commit dbb1b17

Please sign in to comment.