websockets / ws

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
MIT License
21.76k stars 2.42k forks source link

perMessageDeflate performance #756

Closed PokemonAshLovesMyTurkeyAndILikeYouTwo closed 8 years ago

PokemonAshLovesMyTurkeyAndILikeYouTwo commented 8 years ago
Messages Per Second: 36573
Messages Per Second: 30378
Messages Per Second: 11427
Messages Per Second: 11300
Messages Per Second: 10564
Messages Per Second: 9807
Messages Per Second: 9691
Messages Per Second: 8967
Messages Per Second: 8638
Messages Per Second: 13129
--------------------------------------
Messages Per Second: 0
Messages Per Second: 6953
Messages Per Second: 19680
Messages Per Second: 40146
Messages Per Second: 78721
Messages Per Second: 79923
Messages Per Second: 78011
Messages Per Second: 79107
Messages Per Second: 69742
Messages Per Second: 81327

Top log: perMessageDeflate: true, second log: perMessageDeflate:false

It's mountains of times faster, why is that?

Code:

var WebSocketServer = require('ws').Server; 
var wss = new WebSocketServer({
    port: 9300,
    perMessageDeflate: false
});

counter = 0;
wss.on('connection', function(ws) {
    ++counter;
    function callback() {
        counter++;
        ws.send('hey')
        setImmediate(callback);
    }
    setImmediate(callback);
    ws.on('message', function(message) {
        //console.log('received: ' + message);
    });
    //ws.send('something');
});

setInterval(function() {
    console.log('Messages Per Second: ' + counter)
    counter = 0;
}, 1000);

Is this a perMessageDeflate issue or my code?

3rd-Eden commented 8 years ago

Of course deflate is going be slower, it's an extra operation per message that you send. It's a gzip operation so it will be CPU heavy depending on the amount messages that you send.

PokemonAshLovesMyTurkeyAndILikeYouTwo commented 8 years ago

@3rd-Eden Stop censoring the benchmarks to continue to defend your code. perMessageDeflate is enabled by default, which causes massive performance degradation.

ws: The fastest RFC-6455 WebSocket implementation for Node.js.

This is simply untrue, you are lying and trying to censor / hide other modules that far surpass this module in performance.

Specifically: https://github.com/alexhultman/uWebSockets/issues/152#issue-160389186

Almost a 7-8x performance degradation even with perMessageDeflate set to FALSE.

Streisand Effect will be in full force.

3rd-Eden commented 8 years ago

I'm not censoring benchmarks, i'm saying that deflate is of course going to be slower that one without it because of the added CPU overhead if that is not the case, then it's bug.. And you don't have to be dick and start calling people out. This is open source and free software. Don't like? Don't use it.

3rd-Eden commented 8 years ago

I closed this topic, if you're ready to have normal and civil conversation about this, feel free to create a new topic.