Permalink
Browse files

Compression level options, bench update

  • Loading branch information...
1 parent 694961b commit 2ae114cc3266b3cfb39a7ab6563feb6300d7b1a9 @sdolard committed Nov 14, 2011
Showing with 37 additions and 22 deletions.
  1. +16 −12 README.md
  2. +9 −2 lib/log-to-file.js
  3. +12 −8 test/log-to-file-bench.js
View
@@ -68,6 +68,7 @@ Returns a LogToFile instance.
* @params [config.fileMaxSize] {number} Max file size (default 5MB)
* @params [config.maxBackupFileNumber] {number} Max backup file number (default 10)
* @params [config.gzipBackupFile] {boolean} gzip backup files (default false)
+* @params [config.compressionLevel] {number} [1-9] 1: BEST_SPEED, 9: BEST_COMPRESSION, default to 1
* @event error({object} exception)
* @event writting({string} filePath): starting to write everything
* @event written({string} filePath): everything is written
@@ -91,22 +92,25 @@ Just run test/log-to-file-bench.js
```
Bench on my MacBook Pro 10.6.8, 2.53GHz Intel Core 2 Duo, 7200 HDD) with node 0.6.0:
Running bench 0. fileMaxSize: 5.00MB, maxBackupFileNumber: 0, gzipBackupFile: 0
-................Total:1.00GB in 14224ms: 71.99MB/s
+................Total:1.00GB in 12704ms: 80.60MB/s
Running bench 1. fileMaxSize: 5.00MB, maxBackupFileNumber: 0, gzipBackupFile: 1
-................Total:1.00GB in 14026ms: 73.01MB/s
+................Total:1.00GB in 13965ms: 73.33MB/s
Running bench 2. fileMaxSize: 5.00MB, maxBackupFileNumber: 5, gzipBackupFile: 0
-................Total:1.00GB in 11164ms: 91.72MB/s
-Running bench 3. fileMaxSize: 5.00MB, maxBackupFileNumber: 10, gzipBackupFile: 0
-................Total:1.00GB in 10869ms: 94.21MB/s
-Running bench 4. fileMaxSize: 10.00MB, maxBackupFileNumber: 10, gzipBackupFile: 0
-................Total:1.00GB in 11778ms: 86.94MB/s
-Running bench 5. fileMaxSize: 5.00MB, maxBackupFileNumber: 5, gzipBackupFile: 1
-................Total:1.00GB in 25461ms: 40.22MB/s
-Running bench 6. fileMaxSize: 5.00MB, maxBackupFileNumber: 10, gzipBackupFile: 1
-................Total:1.00GB in 34820ms: 29.41MB/s
+................Total:1.00GB in 11047ms: 92.69MB/s
+Running bench 3. fileMaxSize: 5.00MB, maxBackupFileNumber: 5, gzipBackupFile: 1
+................Total:1.00GB in 19520ms: 52.46MB/s
+Running bench 4. fileMaxSize: 5.00MB, maxBackupFileNumber: 10, gzipBackupFile: 0
+................Total:1.00GB in 11074ms: 92.47MB/s
+Running bench 5. fileMaxSize: 5.00MB, maxBackupFileNumber: 10, gzipBackupFile: 1
+................Total:1.00GB in 22329ms: 45.86MB/s
+Running bench 6. fileMaxSize: 10.00MB, maxBackupFileNumber: 10, gzipBackupFile: 0
+................Total:1.00GB in 10976ms: 93.29MB/s
Running bench 7. fileMaxSize: 10.00MB, maxBackupFileNumber: 10, gzipBackupFile: 1
-................Total:1.00GB in 42160ms: 24.29MB/s
+................Total:1.00GB in 24251ms: 42.23MB/s
+Running bench 8. fileMaxSize: 10.00MB, maxBackupFileNumber: 10, gzipBackupFile: 1
+................Total:1.00GB in 24677ms: 41.50MB/s
All done
+
```
## License
View
@@ -87,6 +87,7 @@ function formatIndex(index, length) {
* @params [config.fileMaxSize] {number} Max file size (default 5MB)
* @params [config.maxBackupFileNumber] {number} Max backup file number (default 10)
* @params [config.gzipBackupFile] {boolean} gzip backup files (default false)
+* @params [config.compressionLevel] {number} [1-9] 1: BEST_SPEED, 9: BEST_COMPRESSION, default to 1
* @event error({object} exception)
* @event writting({string} filePath): starting to write everything
* @event written({string} filePath): everything is written
@@ -140,9 +141,12 @@ var LogToFile = function (config){ // ctor
}
}
this.gzipBackupFile = config.gzipBackupFile || false;
+ this.compressionLevel = config.compressionLevel || 1;
+ if (this.compressionLevel < 1 || this.compressionLevel > 9){
+ this.compressionLevel = 1;
+ }
this.verbose = config.verbose || false;
-
this._buffers = []; // Array of buffer to write
this._timeoutId = -1; // write timer
this._waitDrain = false; // Drain flag
@@ -327,7 +331,10 @@ LogToFile.prototype._doFileRotation = function() {
me._createWriteStream.call(me, 1);
});
});
- gzip = zlib.createGzip();
+ gzip = zlib.createGzip({
+ chunkSize: me.bufferSize,
+ level: me.compressionLevel
+ });
compressReadStream.pipe(gzip).pipe(compressWriteStream);
},
renameCurrent = function() {
View
@@ -11,8 +11,7 @@ i, tmp = '',
benchParams = [
{
fileMaxSize: ONE_M * 5,
- maxBackupFileNumber: 0,
- gzipBackupFile: false
+ maxBackupFileNumber: 0
},
{
fileMaxSize: ONE_M * 5,
@@ -25,19 +24,24 @@ benchParams = [
},
{
fileMaxSize: ONE_M * 5,
- maxBackupFileNumber: 10
+ maxBackupFileNumber: 5,
+ gzipBackupFile: true
},
- {
- fileMaxSize: ONE_M * 10,
+ {
+ fileMaxSize: ONE_M * 5,
maxBackupFileNumber: 10
},
{
fileMaxSize: ONE_M * 5,
- maxBackupFileNumber: 5,
+ maxBackupFileNumber: 10,
gzipBackupFile: true
},
- {
- fileMaxSize: ONE_M * 5,
+ {
+ fileMaxSize: ONE_M * 10,
+ maxBackupFileNumber: 10
+ },
+ {
+ fileMaxSize: ONE_M * 10,
maxBackupFileNumber: 10,
gzipBackupFile: true
},

0 comments on commit 2ae114c

Please sign in to comment.