ã¯ããã«
ããã«ã¡ã¯ãã¯ã©ã¦ãã¯ã¼ã¯ã¹ (https://crowdworks.jp/) ã§ã¨ã³ã¸ãã¢ããã¦ããBugfireã§ããä»åã¯æå±ãã¦ããã¸ã£ã³ããã¼ã ã¨ãååãã¦ããSREãã¼ã ã«ãããæ´»åããä¼ããã¾ãã
ã¯ã©ã¦ãã¯ã¼ã¯ã¹ã§ã¯ãAWSä¸ã§Railsã¢ããªã±ã¼ã·ã§ã³ãéç¨ãã¦ããã以åã¯Memcachedã¨Redisã®ä¸¡æ¹ãKVSã¨ãã¦å©ç¨ãã¦ãã¾ãããæè¿ãããå¹ççãªéç¨ãç®æãã¦Redisã«çµ±åãã¾ããã
Memcachedã¨Redisã«ã¤ãã¦
Memcachedã¨Redisã¯ã©ã¡ãããã¼ããªã¥ã¼ã¹ãã¢(KVS)ãæä¾ãããã¼ã¿ãã¼ã¹ã·ã¹ãã ã§ãã
Memcachedã¯ã·ã³ãã«ã§é«éãªä¸æ¹ãRedisã¯è±å¯ãªæ©è½ãåãã¦ãã¾ãã詳細ã¯ä»¥ä¸ã®å ¬å¼ãã¼ã¸ããã確èªãã ããã
移è¡ã®èæ¯
å½å㯠Memcached ã®ã¿ãå©ç¨ãã¦ãã¾ããããå¾ã«Redisã追å ãã¾ãããã»ãã·ã§ã³ç®¡çã¨ãã£ãã·ã¥ã« Memcached ãããã®ä»ã®KVSè¦ä»¶ã«ã¯Memcachedã¨Redisãä½µç¨ãã¦ãã¾ãããããããã¤ã³ãã©ã¨ã³ã¼ãã®ç®¡çãåç´åããããã«ãRedisã«ä¸æ¬åãã決å®ããã¾ããã
移è¡ããã»ã¹
ã»ãã·ã§ã³ã¹ãã¢
æåã®ã¹ãããã¨ãã¦ãã»ãã·ã§ã³ã¹ãã¢ãMemcachedããRedisã«åãæ¿ãã¾ãããå ·ä½çã«ã¯ã
ActiveSupport::Cache::MemCacheStore
ãã ActiveSupport::Cache::RedisCacheStore
ã¸ã®åãæ¿ããè¡ãã¾ããããã®å¤æ´ã¯ãã©ãã£ãã¯ã®å°ãªãæé帯ã«å®æ½ãã¾ããã
ã»ãã·ã§ã³ç¨ã«ã¯Eviction*1ãããªããã¨ãæå¾ ããRedisã¤ã³ã¹ã¿ã³ã¹ãå©ç¨ãã¦ãã¾ãã
ãã£ãã·ã¥ã¹ãã¢
次ã«ãRailsã®ãã£ãã·ã¥ã¡ã«ããºã ãMemcachedããRedisã«åãæ¿ãã¾ãããããã¯åç´ã«è¨å®ãã¡ã¤ã«å ã®
config.cache_store
ã®å¤ã :mem_cache_store
ãã :redis_cache_store
ã«å¤æ´ãããã¨ã§å®ç¾ãã¾ããã
ãã¡ãã¯ã»ãã·ã§ã³ã¹ãã¢ã¨éããEvictionã許容ããRedisã¤ã³ã¹ã¿ã³ã¹ãå©ç¨ãã¦ãã¾ãã
Dalliã¨Redis gemã®ã±ã¼ã¹
ç´æ¥KVSã¨ãã¦DalliãRedisã使ç¨ãã¦ãã¦æ®çºãã¦ãæ§ããªããã®ã¯ããã£ãã·ã¥ã¹ãã¢ãå©ç¨ãã Rails.cache
ã«ç½®ãæãã¾ãããããã«ãããå¤ãã®ç´æ¥çãªKVSå©ç¨ãRailsã®ãã£ãã·ã¥æ©è½ã§ã«ãã¼ãã¾ããã
æ®çºã許ãããªããã¼ã¿
æ®çºã許ãããªãããã¯ãã¼ã¿çã«é¢ãã¦ã¯ãEvictionã許容ããªãã¤ã³ã¹ã¿ã³ã¹ã«å¯¾ãã¦Redis gemãç´æ¥å©ç¨ãã¦å®è£ ããããã«å¤æ´ãã¾ããã
CachedCounter
å½ç¤¾ãéçºããCachedCounterã®å©ç¨ããRedis gemãç´æ¥ä½¿ç¨ããå½¢ã«ç½®ãæãã¾ããã
ãã¼ã¿ç§»è¡ãä¼´ãã±ã¼ã¹
ä¸é¨ã®ãã¼ã¿ã¯ä¿æããã¾ã¾ç§»è¡ãããããTTLã«åããã30æ¥ã®ç§»è¡æéãã¨ãã¾ãã
- 30æ¥é
- èªã¿è¾¼ã¿æã«æ§ãã¼ã¿ãèªã¿è¾¼ã
- æ¸ãè¾¼ã¿æã«æ°æ§ã®ä¸¡æ¹ã«ãã¼ã¿ãæ¸ãè¾¼ã
- 30æ¥å¾
- æ°ãã¼ã¿ãèªã¿æ¸ããã
ã¨äºæ®µéã«åãã¦æ´æ°ãã¾ããã
æ» å¤ã«èªã¿æ¸ãããªãã±ã¼ã¹
3ã¶ææ¯ã«å®è¡ãããããã§å©ç¨ãã¦ããã±ã¼ã¹ã§ã¯ã念ã®çºæ¬¡åã®å®è¡ã¿ã¤ãã³ã°ç´åã«ç§»è¡ãã¦ãä¸ãä¸ã®ããã®ãªã«ããªã¼ãã©ã³ãæºåãã¾ããã
ã¾ã¨ã
çæéã§ããã¤ã¤ããåå¹´éãããããã®ç§»è¡ä½æ¥ã¯ãMemcachedã¸ã®ã¢ã¯ã»ã¹æ°ãæ¸å°ããã®ãè¦ãã¨å ±ã«ã大ããªéææãæãã¾ããã
ä»åã®ç§»è¡ã¨ã¯ç¬ç«ãã話ã§ããRedisã®SCANã³ãã³ãããã¡ãã¦ãåå ä¸æã ã£ãTTLæªå®ç¾©ã®Keyãæ¢ãåºãã¦åé¤ã§ããã®ãææã§ããã
We're hiring!
ã¯ã©ã¦ãã¯ã¼ã¯ã¹ã§ã¯ãæ§ã ãªãã¸ã·ã§ã³ã®ã¨ã³ã¸ãã¢ãåéãã¦ããã¾ãã ãèå³ã®ããæ¹ã¯ããã²ãé£çµ¡ãã ããã