node process exits when redis server returns response: "command not allowed when used memory > 'maxmemory' "
I am logging requests to redis:
'use strict';
var config = require('config'),
redis = require('redis').createClient('6379', config.logstash.redisHost);
redis.on('error', function (err) {
console.log(err);
});
exports.init = function(app) {
app.use(function(req, res, next) {
res.end = function(chunk, encoding) {
var message = { type: 'v1' };
redis.rpush('logstash', JSON.stringify(message));
};
next();
});
};
Last night redis cluster ran out of memory and started rejecting commands as the log message suggests:
Error: OOM command not allowed when used memory > 'maxmemory'.
at ReplyParser.<anonymous> (/var/www/current/node_modules/redis/index.js:317:31)
at ReplyParser.EventEmitter.emit (events.js:95:17)
at ReplyParser.send_error (/var/www/current/node_modules/redis/lib/parser/javascript.js:296:10)
at ReplyParser.execute (/var/www/current/node_modules/redis/lib/parser/javascript.js:181:22)
at RedisClient.on_data (/var/www/current/node_modules/redis/index.js:547:27)
at Socket.<anonymous> (/var/www/current/node_modules/redis/index.js:102:14)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:745:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:407:10)
I thought setting up an error event listener would prevent crashes:
redis.on('error', function (err) {
console.log(err);
});
Am I missing something obvious?
Hi @ArnoldZokas -- probably not. My guess is it may be the parser is choking on whatever redis sent back and for whatever reason that error case isn't being correctly forwarded to the error event. Needs investigation.
I am experiencing the same errors in conjunction with Redis ToGo on Heroku and Kue. Seems to no crash the app but happens very consistently.
I just started seeing this as well. I have maxmemory set to 250MB (on a 4GB MacBook Air), working great until the reported error appears. I checked the following Redis' page: http://redis.io/topics/admin. Note the following statement:
Make sure to setup some swap in your system (we suggest as much as swap as memory). If
Linux does not have swap and your Redis instance accidentally consumes too much memory,
either Redis will crash for out of memory or the Linux kernel OOM killer will kill
the Redis process.
I use a Mac, but my feeling is that the same principle applies. I wonder if 250MB is too aggressive, so that when Redis reaches the limit it cannot do the required housekeeping.
Also, do pay attention to the maxmemory-policy setting. In my case, I have set it to volatile-lru:
volatile-lru: evict keys trying to remove the less recently used (LRU) keys first, but only
among keys that have an expire set, in order to make space for the new data added.
I think this is not the right setting for me because it only evicts keys which have the expire set. I think I'm going to change it to allkeys-lru:
allkeys-lru: evict keys trying to remove the less recently used (LRU) keys first,
in order to make space for the new data added.
There's the following note adding additional info:
Use the allkeys-lru policy when you expect a power-law distribution in the popularity of
your requests, that is, you expect that a subset of elements will be accessed far more often
than the rest. This is a good pick if you are unsure.
I'm going to try the following setup first:
A) use the same maxmemory setting of 250MB and set the maxmemory-policy to allkeys-lru.
If this continues to fail (I doubt it, but...), I'll head to plan B:
B) lower maxmemory to 125MB and set the maxmemory-policy to allkeys-lru.
This may not be your case, but I though it was worth mentioning. I've read the documentation several times, but it seems I misunderstood how volatile-lru works. I hope I can find the solution. I'll report back if it seems to do the trick.
In order to better support this project and its new group of collaborators under a new org we are trying to clean up and close issues older than 6 months. Your issue may have been fixed since the issue was open, however, if you are still experiencing a problem please re-open this issue and we will label it accordingly.
This is fixed in newer versions (v.2.0 if I'm correct). An OOM error won't crash the process anymore.