Heroku request timeout when Memcachier reaches cac

2019-06-17 07:23发布

I have a Rails app deployed to Heroku using Memcachier (Dalli as client). I'm using the free add-on (which offers a 25 MB cache).

We started to receive request timeouts from heroku and, after debugging, we found out that manually flushing Memcachier solved the problem.

Timeouts occur when Memcachier reaches levels near its limit, like 20 MB (when limit is 25 MB).

Why Memcachier doesn't free cache space with time? Is there any missing configuration to tell Memcachier to flush when cache reach certain size?

My conf:

application.rb

config.cache_store = :dalli_store

production.rb

client = Dalli::Client.new
config.action_dispatch.rack_cache = {
    :metastore    => client,
    :entitystore  => client,
    :allow_reload => false
}

1条回答
该账号已被封号
2楼-- · 2019-06-17 08:02

Perhaps try updating your production.rb to include socket_timeout and socket_failure_delay options.

require 'dalli'
cache = Dalli::Client.new((ENV["MEMCACHIER_SERVERS"] || "").split(","),
                    {:username => ENV["MEMCACHIER_USERNAME"],
                     :password => ENV["MEMCACHIER_PASSWORD"],
                     :failover => true,
                     :socket_timeout => 1.5,
                     :socket_failure_delay => 0.2
                    })

-- OR --

If you are using Puma, you need to have the connection_pool gem installed.

Gemfile

gem 'connection_pool'

And this configuration in your production.rb

config.cache_store = :dalli_store,
                    (ENV["MEMCACHIER_SERVERS"] || "").split(","),
                    {:username => ENV["MEMCACHIER_USERNAME"],
                     :password => ENV["MEMCACHIER_PASSWORD"],
                     :failover => true,
                     :socket_timeout => 1.5,
                     :socket_failure_delay => 0.2,
                     :pool_size => 5
                    }
查看更多
登录 后发表回答