Memcached大小限制与文件系统实体存储所代表的究竟是什么? [英] What exactly does the Memcached size limit represent with file system entitystore?

查看:147
本文介绍了Memcached大小限制与文件系统实体存储所代表的究竟是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好,

我的Memcached在我的Heroku应用程序中联网。 Memcached免费管理计划的限制为5MB,Memcachier为25MB。几乎所有的东西都是新的,我只是希望澄清这代表了什么。



我在配置文件中设置了DalliStore,并且设置了典型的选项Rack :: Cache。我的Metastore位于Memcache中,entitiy商店设置在文件系统中。



问题:


  1. 这是否意味着我的5 / 25MB限制仅被我存储的有关每个缓存碎片的元信息所使用?这意味着我可以在免费计划中存储大量信息吗?
  2. Rack :: Cache和Memcache之间的故障/故事究竟是什么通过Dalli商店吗?)他们有不同的用途吗?他们做同样的事情吗?即以下代码是多余的:
    $ b $ config.cache_store =:dalli_store


  config.action_dispatch.rack_cache = {
:verbose => true,
:metastore => Dalli :: Client.new,
:entitystore => 'file:tmp / cache / rack / body',
:allow_reload =>假
}


解决方案

我一直在摔跤与此类似的问题。



首先,让我们来看看我们的术语。


  • Memcached :在某个服务器上运行的进程(d代表守护进程),它实际上将键值对存储在内存中。
  • cache_store strong>:使用单个API可以配置使用不同的Ruby软件实现的Rails缓存存储( Rails.cache )。一个用于 config.cache_store 的设置是:memory_store 来使用内存中的实现。另一个设置是:dalli_store ,它指定使用dalli gem,它可以与您的memcached服务器建立可能的远程连接。

  • Dalli Store :我假设您的意思是由dalli gem支持的Rails缓存,它将实际值存储在memcached中。 Rack :: Cache :在HTTP响应中插入标题(过期,缓存控制,ETag等)的机架中间件,也可充当反向代理缓存,在请求在可能时触及Rails堆栈之前处理请求。请参阅网站



为了让Rack :: Cache在它们碰到Rails堆栈和其他应用程序之前处理请求,它必须在某处存储响应+元数据。存储事物的位置由 config.action_dispatch.rack_cache = {...} 设置进行配置。



通知,这是从 config.cache_store =:dalli_store 不同的设置。他们不必相关。我认为这是很多混乱来自的地方。但实际上,我们可能希望它们都使用memcached,这意味着使用dalli实现。但是,它们都有自己的 Dalli :: Client 实例。 (另外,你的session_store可能是相关的,但不一定是。)



Heroku雪松堆栈有一个。然而,Heroku自己建议在Rack :: Cache中使用tmp文件存储仅用于 entitystore ,而memcached用于 Metastore



至于实际存储在Rack :: Cache元存储中的内容,这些是来自 rack-cache v1.2 Rack :: Cache :: MetaStore class:

  MetaStore负责存储有关由请求URL锁定的
请求/响应对的元信息。

元存储为每个规范的
请求URL保存一个请求/响应对列表。请求/响应对是以下形式的两个元素数组:
[request,response]

+ request +元素是一个Hash of Rack环境键。只存储协议
密钥(即以HTTP_开头的密钥)。 + response +
元素是配对请求的缓存HTTP响应标头的哈希。

所以要回答你的问题,HTTP请求头和HTTP响应头存储在Rack :: Cache metastore。另一方面,Rack :: Cache实体商店存储整个响应体(即HTML)。



您无法在Heroku上可靠地使用页面缓存,这意味着您可能正在使用动作缓存和片段缓存。动作和片段缓存使用您的Rails缓存存储(不是机架缓存)。但是,如果您已经将它们都设置为物理使用同一个memcached服务器,它们都会贡献内存使用。动作和部分缓存存储实际的HTML。



要更深入地了解实际使用情况,如果您使用的是memcachier,请运行以下命令以打开分析仪表板您的浏览器。

  heroku addons:打开memcachier 

有关获取memcached的更多信息,请参阅此问题统计。


Good afternoon,

I have Memcached hooked up in my app on Heroku. The limit for the free managed plan is 5MB for Memcached and 25MB for Memcachier. Being new to pretty much everything, I was just hoping for clarification of exactly what this represents.

I have the DalliStore set up in my config file, and the typical options set up for Rack::Cache. My metastore is in Memcache and the entitiy store is set up on the filesystem.

Questions:

  1. Does this mean that my 5/25MB limit is only being used by the meta information that I am storing about each cache fragment? This would mean that I'd be able to store a ton of information on just the free plans?
  2. What exactly is the breakdown / story between Rack::Cache and Memcache (via Dalli store?) Do they serve different purposes? Are they doing the same thing? i.e. is the following code redundant

    config.cache_store = :dalli_store

and

config.action_dispatch.rack_cache = {
  :verbose      => true,
  :metastore    => Dalli::Client.new,
  :entitystore  => 'file:tmp/cache/rack/body',
  :allow_reload => false
}

解决方案

I've been wrestling with similar issues.

First of all, let's get our terminology straight.

  • Memcached: a process running on a server somewhere (d is for daemon) that actually stores key-value pairs in memory.
  • cache_store: Rails cache storage (Rails.cache) with a single API which can be configured to use different Ruby software implementations. One setting for config.cache_store is :memory_store to use an in-memory implementation. Another setting is :dalli_store that specifies using the dalli gem, which under the hood makes a possibly-remote connection to your memcached server.
  • Dalli Store: I assume you mean the Rails cache backed by the dalli gem, which physically stores values in memcached.
  • Rack::Cache: Rack middleware that inserts headers (Expires, Cache-Control, ETag, etc.) into your HTTP responses, and also acts as a reverse proxy cache, handling requests before they hit the Rails stack when possible. See website.

In order for Rack::Cache to handle requests before they hit the Rails stack and the rest of your app, it must store responses + metadata somewhere. Where it stores things are configured by the config.action_dispatch.rack_cache = { ... } setting.

Notice, this is a different setting from config.cache_store = :dalli_store. They don't have to be related. I think this is where a lot of confusion comes from. In practice, though, we may want them both to use memcached, which means using the dalli implementation. However, they each have their own Dalli::Client instance. (Also, your session_store could be related, but doesn't have to be.)

The Heroku cedar stack has an ephemeral file system that cannot be shared among dynos. However, Heroku themselves recommend using tmp file storage with Rack::Cache for the entitystore only, with memcached used for the metastore.

As for what actually gets stored in the Rack::Cache metastore, these are the docs from rack-cache v1.2 Rack::Cache::MetaStore class:

The MetaStore is responsible for storing meta information about a
request/response pair keyed by the request's URL.

The meta store keeps a list of request/response pairs for each canonical
request URL. A request/response pair is a two element Array of the form:
  [request, response]

The +request+ element is a Hash of Rack environment keys. Only protocol
keys (i.e., those that start with "HTTP_") are stored. The +response+
element is a Hash of cached HTTP response headers for the paired request.

So to answer your question, HTTP request headers and HTTP response headers are stored in the Rack::Cache metastore. On the other hand, the Rack::Cache entitystore stores entire response bodies (i.e. HTML).

Since you can't use page caching reliably on Heroku, this means you might be using action caching and fragment caching. Action and fragment caching use your Rails cache store (not rack cache). But if you've set them both to physically use the same memcached server, they'll both contribute to memory use. Action and partial caching store the actual HTML.

To get more insight of your actual usage, if you're using memcachier run the following command to open up an analytics dashboard in your browser.

heroku addons:open memcachier

See this question for more info about getting memcached stats.

这篇关于Memcached大小限制与文件系统实体存储所代表的究竟是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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