Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fork interface poc pending

  • Loading branch information...
commit ad981b5159a5e00c15e08161905a67169c109023 1 parent dbb1b17
sebastien authored
View
73 lib/log-to-file-fork.js
@@ -28,16 +28,16 @@ cp = require('child_process'),
logToFile = require(__dirname + '/log-to-file.js');
function mergeObjects(){
- var
- i = 0,
- prop,
- out = {};
- for(i = 0; i < arguments.length; ++i) {
- for (prop in arguments[i]) {
- out[prop] = arguments[i][prop];
- }
- }
- return out;
+ var
+ i = 0,
+ prop,
+ out = {};
+ for(i = 0; i < arguments.length; ++i) {
+ for (prop in arguments[i]) {
+ out[prop] = arguments[i][prop];
+ }
+ }
+ return out;
}
/**
@@ -68,6 +68,14 @@ var LogToFileForker = function (config, callback){ // ctor
case logToFile.FE_CTOR:
me._fileHandle = m._handle;
+ me.fileName = m.fileName;
+ me.directory = m.directory;
+ me.writeDelay = m.writeDelay;
+ me.bufferSize = m.bufferSize;
+ me.fileMaxSize = m.fileMaxSize;
+ me.maxBackupFileNumber = m.maxBackupFileNumber;
+ me.gzipBackupFile = m.gzipBackupFile;
+ me.compressionLevel = m.compressionLevel;
me.emit(m._event, m);
break;
@@ -80,7 +88,7 @@ var LogToFileForker = function (config, callback){ // ctor
case logToFile.E_ERROR:
me.emit(m._event, m);
break;
-
+
case logToFile.E_WRITTING:
case logToFile.E_WRITE:
case logToFile.E_WRITTEN:
@@ -90,7 +98,7 @@ var LogToFileForker = function (config, callback){ // ctor
case logToFile.E_BACKUPED:
me.emit(m._event, m.oldFilePath, ms.filePath);
break;
-
+
case logToFile.E_GZIPPING:
case logToFile.E_GZIPPED:
me.emit(m._event, m.filePath, m.gzipFilePath);
@@ -139,25 +147,46 @@ LogToFileForker.prototype.log = function() {
* @param {string} string
*/
LogToFileForker.prototype.write = function(string) {
- this.log('Parent send event: ', logToFile.E_WRITE);
// TODO: a test to check if process is alive?
- this._fork.send({
- _event: logToFile.E_WRITE,
- _handle: this._fileHandle,
- string: string
- });
+ var sent, me = this;
+
+ try {
+ sent = this._fork.send({
+ _event: logToFile.E_WRITE,
+ _handle: this._fileHandle,
+ string: string
+ });
+ if (!sent) {
+ setTimeout(function() {
+ me.write({
+ _event: logToFile.E_WRITE,
+ _handle: me._fileHandle,
+ string: string
+ });
+ }, 1);
+ } else {
+ this.log('Parent send event: ', logToFile.E_WRITE);
+ }
+ } catch(err) {
+ this.log('LogToFileForker.prototype.write:', err);
+ }
};
/**
* @public
*/
LogToFileForker.prototype.terminate = function() {
+ // TODO: a test to check if process is alive?
this.log('Parent send event: ', logToFile.FE_TERMINATE);
// TODO: a test to check if process is alive?
- this._fork.send({
- _event: logToFile.FE_TERMINATE,
- _handle: this._fileHandle
- });
+ try {
+ this._fork.send({
+ _event: logToFile.FE_TERMINATE,
+ _handle: this._fileHandle
+ });
+ } catch(err) {
+ this.log('LogToFileForker.prototype.terminate:', err);
+ }
};
View
10 lib/log-to-file.js
@@ -172,7 +172,7 @@ var LogToFile = function (config){ // ctor
this._writtenSize = 0; // Quantity of data written. Initialized in _createWriteStream
this._rotationPending = false; // File rotation flag
this._maxBackupFileNumberLength = String(this.maxBackupFileNumber).length;
-
+
this._createWriteStream(); // We create first stream
};
@@ -581,7 +581,13 @@ process.on('message', function(m) {
_event: FE_CTOR,
_handle: forkHandle,
fileName: m.fileName,
- directory: m.directory
+ directory: m.directory,
+ writeDelay: m.writeDelay,
+ bufferSize: m.bufferSize,
+ fileMaxSize: m.fileMaxSize,
+ maxBackupFileNumber: m.maxBackupFileNumber,
+ gzipBackupFile: m.gzipBackupFile,
+ compressionLevel: m.compressionLevel
});
}catch(err) {
if (verbose) {
View
62 test/log-to-file-bench.js
@@ -12,44 +12,49 @@ ONE_T = ONE_G * 1024,
i, tmp = '',
benchParams = [
{
+ //verbose: true,
fileMaxSize: ONE_M * 5,
maxBackupFileNumber: 0
}/*,
{
- fileMaxSize: ONE_M * 5,
- maxBackupFileNumber: 0,
- gzipBackupFile: true
+ fileMaxSize: ONE_M * 5,
+ maxBackupFileNumber: 1
+ },
+ {
+ fileMaxSize: ONE_M * 5,
+ maxBackupFileNumber: 1,
+ 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
+ fileMaxSize: ONE_M * 10,
+ maxBackupFileNumber: 10,
+ gzipBackupFile: true
}*/], bi = 0;
for ( i = 0; i < 1024; ++i) {
- tmp += dataTest;
+ tmp += dataTest; // 1Ko
}
dataTest = tmp;
@@ -84,11 +89,10 @@ function cleanup() {
}
function runTestFork() {
-
var
size = 0,
log,
- elements = 1024 * 1024,
+ elements = 1024 * 5,// 5Mo * 1024,
start, end, writtingEventCount = 0,
wcount = 0,
config = benchParams[bi];
@@ -110,16 +114,18 @@ function runTestFork() {
gzipBackupFile: config.gzipBackupFile || false,
verbose: config.verbose || false
}, function() {
+ console.log('Running fork bench %d . fileMaxSize: %s, maxBackupFileNumber: %d, gzipBackupFile: %d', bi,
+ octetToHuman(log.fileMaxSize),
+ log.maxBackupFileNumber,
+ log.gzipBackupFile);
+ bi++;
+
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();
@@ -143,7 +149,7 @@ function runTestFork() {
duration,
octetToHuman(size * 1000 / duration));
- setTimeout(cleanup, 10);
+ //setTimeout(cleanup, 10);
setTimeout(runTestFork, 10);
log.terminate();
@@ -166,7 +172,7 @@ function runTest() {
if (benchParams.length === bi) {
bi = 0;
- setTimeout(runTestFork, 10);
+ //setTimeout(runTestFork, 10);
return;
}
if (bi === 0) {
Please sign in to comment.
Something went wrong with that request. Please try again.