当Memcachier达到缓存限制时,Heroku请求超时 [英] Heroku request timeout when Memcachier reaches cache limit

查看:149
本文介绍了当Memcachier达到缓存限制时,Heroku请求超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆