accessing Memcached through mcrouter from Rails in Kubenetes

1/8/2020

I have a Rails 6 app running in Google Kubernetes Engine, and I'm trying to enabled distributed caching with Memcached.

I followed exactly these instructions for deploying Memcached into the Kubernetes cluster with mcrouter. Nothing at all went wrong and the final test using a Python script works fine.

Then in my Rails app I think I just need to add the "dalli" gem and use the MemCacheStore like this:

cache = ActiveSupport::Cache::MemCacheStore.new("#{ENV['NODE_NAME']}:5000")
cache.write('key', 'value')

This code is supposed to connect to the mcrouter on the local node at port 5000 and write to the cache (The NODE_NAME environment variable holds the name of the local node).

The cache.write command returns false and prints this to the log:

D, [2020-01-08T18:02:30.233119 #215] DEBUG -- : Dalli::Server#connect gke-rev79-cluster-phat-pool-41a53de4-rfz3:5000
W, [2020-01-08T18:02:30.258514 #215]  WARN -- : gke-rev79-cluster-phat-pool-41a53de4-rfz3:5000 failed (count: 0) EOFError: end of file reached

"gke-rev79-cluster-phat-pool-41a53de4-rfz3" is the local node name

This is what I get from cache.inspect:

"#<ActiveSupport::Cache::MemCacheStore:0x0000000004087cb8 @options={}, @data=#<Dalli::Client:0x0000000004087498 @servers=[\"gke-rev79-cluster-phat-pool-41a53de4-rfz3:5000\"], @options={}, @ring=nil>>"

How can I make a connection to the cache? Perhaps I need to puts some things in the options of the Rails cache store?

-- Toby 1 Kenobi
kubernetes
memcached
ruby-on-rails
ruby-on-rails-6

1 Answer

2/12/2020

It looks like Dalli doesn't support Mcrouter since it uses the Memcached binary protocol which Mcrouter doesn't support.

https://github.com/facebook/mcrouter/issues/56

-- Toby 1 Kenobi
Source: StackOverflow