当Memcachier达到缓存限制时,Heroku请求超时 [英] Heroku request timeout when Memcachier reaches cache limit
问题描述
我使用Memcachier(Dalli作为客户端)部署到Heroku的Rails应用程序。我使用免费的附加组件(它提供了25 MB缓存)。
我们开始接收来自heroku的请求超时,并在调试后发现手动冲洗Memcachier解决了这个问题。
$ b
超时发生在Memcachier达到接近极限的水平时,例如20 MB(限制为25 MB时)。
为什么Memcachier不能随时间释放缓存空间?是否有任何缺少配置告诉Memcachier在缓存达到一定大小时刷新?
My conf: p>
application.rb
config.cache_store =:dalli_store
production.rb
client = Dalli :: Client.new
config.action_dispatch.rack_cache = {
:metastore =>客户端,
:entitystore =>客户端,
:allow_reload =>假
}
code> production.rb 包含 socket_timeout
和 socket_failure_delay
选项。
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
})
- 或 -
如果您使用的是 Puma ,则需要 connection_pool
gem已安装。
Gemfile
gem'connection_pool'
code>
并且在你的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
}
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
}
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
}
这篇关于当Memcachier达到缓存限制时,Heroku请求超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!