NodeJS can't get memcached values when highloaded

Viewed 30

I have an application on NodeJS that uses Cluster, WS, and memcached-client to manage two memcached-servers During normal times, it works like a charm

But during high load, my application stops working and fetches data from memcached-servers That is, the logs inside client.get callback do not work, and are not written to the console, when the load is high, therefore the client does not receive its cached value (although it is present on the memcached server and sometimes even with high load it works fine). For a while it will look like it's dead and not doing anything

getValue = function(key, callback){
    console.log(`Calculated server for choose: ${strategy(key, client.servers.length)}`) // works with highload
    console.log(`Try to get from cache by key: ${key}.`); // works with highload
    client.get( key, function(err, data) {
        const isError = err || !data // doesn't work with highload
        console.log('Data from cache is: ', data) // callback will be never executed
        if (!isError) {
            console.log(`Found data in cache key-value: ${key} - ${data}`);
        }else{
            console.log(`Not found value from cache by key: ${key}`);
        }
        const parsedData = isError ? null : JSON.parse(data.toString())
        callback(isError, parsedData); // and this won't work also
    });
}

And after some time, socket connection is simply closed (with 1000 code, no errors, looks like user just leaves out)

INFO [ProcessID-100930] Connection close [772003], type [ws], code [1000], message []

Then, after 5-10 seconds, all processes start working again as if nothing had happened and the memcached-client callback starts to execute correctly

I've been trying for so long to catch this moment and understand why this is happening, but I still don't understand. I have changed already several memcached clients(memjs now, memcached, mc) but still get the same behavior under high load When receiving data from memcached-server, the callback simply does not work, and data from the memcached is not returned (although judging by the memcached logs, they were there at that moment)

Can someone suggest please?

0 Answers
Related