jeudi 4 janvier 2018

How to benchmark Sockets in net module node.js

I want to benchmark the performance of my node.js server built using the net module. In the server, a device is a client which sends data to the server( using its own protocol on top of tcp/ip)

This is what my server file looks like -

const net = require('net');
const emitter = require('./lib/serverEventsEmitter');


const clients = [];
let clientNum=0;


const server = net.createServer(function (socket) {
    socket.name = socket.remoteAddress + ":" + socket.remotePort;
    console.log(++clientNum);
    clients.push(socket);


    socket.on('data', function (data) {
        try {
             console.log("Buffer sent by terminal : ");
             console.log(data);


            let parts = dataParser.parse_data(str, socket);
            console.log(parts);

        } catch (err) {
            console.log("DATA RECEIVING PRODUCED AN ERROR" + err);
        }

    });
    socket.on('end', function () {
        clients.splice(clients.indexOf(socket), 1);
            //broadcast(socket.name + "has left the cartel.\n");
    });

    socket.on('error', function (exc) {
        console.log("ignoring exception: " + exc);
    });


    function broadcast(message, sender) {
        clients.forEach(function (client) {
            if (client === sender) client.write(message + "\nsent\n");
            return;
            client.write(message);
        });
        process.stdout.write(message);
    }
})
// .listen(8080);


process.on('uncaughtException', function (err) {
    console.log('something terrible happened..')
    console.log(err);
})

module.exports = server;

I can't use ab benchmarking tool because the data transfer isn't based on HTTP protocol. I want to use my own protocol which is used by the device sending the data. Also, the data goes one way from the device(client) to a server. Handshake is only done when there is a certain data packet from the device wanting to do so(1 in 10 probability)! Would websocket benchmarking be apt here? But the protocol isn't based on websockets. Is there a workaround using the existing benchmarking tools?

Aucun commentaire:

Enregistrer un commentaire