Skip to content

Instantly share code, notes, and snippets.

@fforbeck
Last active December 17, 2015 13:19
Show Gist options
  • Save fforbeck/5615984 to your computer and use it in GitHub Desktop.
Save fforbeck/5615984 to your computer and use it in GitHub Desktop.
setup redis overcommit_memory
1 - Make sure to set the Linux kernel overcommit memory setting to 1. Add vm.overcommit_memory = 1 to /etc/sysctl.conf and then reboot or run the command sysctl vm.overcommit_memory=1 for this to take effect immediately.
2 - 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.
3 - Connector Configs
final int numClients = 150;
final JedisPoolConfig config = new JedisPoolConfig();
// Tests whether connection is dead when connection retrieval method is called
config.setTestOnBorrow(true);
// Tests whether connection is dead when returning a connection to the pool
config.setTestOnReturn(true);
// Tests whether connections are dead during idle periods
config.setTestWhileIdle(true);
// Maximum active connections to Redis instance
config.setMaxActive(numClients < 100 ? 100 : numClients);
// Minimum number of idle connections to Redis - these can be seen as always open and ready to serve
config.setMinIdle(1);
// Number of connections to Redis that just sit there and do nothing
config.setMaxIdle(30);
// Maximum number of connections to test in each idle check
config.setNumTestsPerEvictionRun(10);
// Idle connection checking period
config.setTimeBetweenEvictionRunsMillis(60000);
// Fail-fast behaviour, we don't like to keep the kids waiting :)
config.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment