nodejs websocket client performance

83 Views Asked by At

I run pretty simple nodejs script - websocket client which handles messages accordingly, my question is, how could I possibly make this client run faster? Would it make more sense to host it on larger server? (16/32+ cores) or is that pointless? My code parses the event.data to json, does that cost me more performance than the server CPUs? How could I improve the parsing of the data then? I attach simple code example:

let socket

function connectWSS(){
    socket = new WebSocket("wss://example.com");
    socket.onopen = function() {
        // ONOPEN
    }
    socket.onmessage = function (event){
            // JSON PARSING THE DATA
            // PROCESSING THE DATA
        }
    socket.onerror = function(error) {
      //RECONNECT
    }
    socket.onclose = function(event){
        //RECONNECT
    }
}```
0

There are 0 best solutions below