LoginSignup
193
191

More than 5 years have passed since last update.

Redisを使う時は見積の二倍の容量必要だよね、という話

Posted at

ある日Redisのログを眺めるとこんな子が大量に現れてて焦った。

redis.log
[15487] 04 Aug 21:02:37.523 * 1 changes in 900 seconds. Saving...
[15487] 04 Aug 21:02:37.523 # Can't save in background: fork: Cannot allocate memory

redis-cli infoしても、使用してるメモリは全体の半分ちょっとだったし、空きは十分にある…

答えは
Redis Administration
http://redis.io/topics/admin
に書いてありました。

原因と解決策

redisのバックアップが走る際、おそらく現状使用している量と同じだけのallocateを要求しているために、redis自体はメモリ使用が50%強だとしても、バックアッププロセスが落ちてしまう模様。

解決は簡単で、Redis Administrationに書いてあるとおり、応急処置的に

sysctl vm.overcommit_memory=1

を設定して、allocateを許可してあげればいい。

あとは、/etc/sysctl.confへ以下を追記。

vm.overcommit_memory = 1

見積の2倍は用意しよう

結論として、Redisを運用する際は見積もりして必要だと思われた容量の2倍は出来るだけ用意しといたほうが安定運用できますよ、という話。

193
191
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
193
191