Benchmarking Node.js Journaling Systems - Am I Not Enough About This?

Yesterday, I realized that most registration libraries for Node.js seem to use blocking / synchronous calls. Usually registration is an I / O operation, and with Node.js we should use non-blocking / asynchronous I / O everywhere.

console.log (process.stdout.write) is a synchronous operation since Node.js 0.6, TMK

It occurred to me that for servers that follow many logging instructions, using blocking I / O for them can be a big penalty for performance.

I ran the “logging” instructions with Redis, fs, Bunyan and Winston, and I get these results on a Macbook Pro:

redis: 16ms

fs-write-stream: 90ms

bunyan: 414ms

winston: 491ms

, Redis - - Node.js.

:

    // fs
    var fs = require('fs');

    // redis
    var redis = require('redis');
    var client = redis.createClient();  //connect to local redis db

    // bunyan
    var bunyan = require('bunyan');

    var bunyanLogger = bunyan.createLogger({
        name: 'benchmark',
        streams: [
            {
                level: 'info',
                path: '../bunyan_log.txt'  // log ERROR and above to this file
            }
        ]
    });

    // winston
    var winston = require('winston');

    var winstonLogger = new (winston.Logger)({
        transports: [
            new (winston.transports.File)({ filename: '../winston_log.txt' })
        ]
    });


    ////////////////////////////////////////////////////////////////////////////

    console.time('redis-time');

    for (var i = 0; i < 12000; i++) {

        client.set('key' + i, 'value' + i + 'aegeggaiojigfeijoagreoiraegioagrijogerawijogerwijogerijoegwoijegwijoegwjio');

    }

    console.timeEnd('redis-time');

    ////////////////////////////////////////////////////////////////////


    console.time('fs-write-stream-time');

    var wstream = fs.createWriteStream('../fs_log.txt');

    for (var i = 0; i < 12000; i++) {

        wstream.write('key' + i + 'value' + i + 'aegeggaiojigfeijoagreoiraegioagrijogerawijogerwijogerijoegwoijegwijoegwjio' + '\n');

    }

    wstream.end();

    console.timeEnd('fs-write-stream-time');


    ///////////////////////////////////////////////////////////////


    console.time('bunyan-time');

    for (var i = 0; i < 12000; i++) {

        bunyanLogger.info('bunyan' + i);

    }

    console.timeEnd('bunyan-time');


    /////////////////////////////////////////////////////////////


    console.time('winston-time');

    for (var i = 0; i < 12000; i++) {

        winstonLogger.info('bunyan' + i);

    }

    console.timeEnd('winston-time');


////////////////////////////////////////////////////////////////

- - ?

, Node.js Redis -, .

+4
1

, - Redis "", :

client.on('ready',function(){

    console.time('redis-time');

    for (var i = 0; i < 12000; i++) {

        client.set('key' + i, 'value' + i + 'aegeggaiojigfeijoagreoiraegioagrijogerawijogerwijogerijoegwoijegwijoegwjio');

    }

    console.timeEnd('redis-time');

});

Redis , fs.createWriteStream, , Bunyan Winston, , , JSON.stringify .

, fs.createWriteStream , Bunyan Winston... , -.

0

Source: https://habr.com/ru/post/1614343/


All Articles