Memcached 扩展:关键“分组”
由于最佳实践是将在单个服务器上经常检索在一起(使用 multiGet)的相关密钥分组以获得最佳性能,因此我有几个关于为此而构建的客户端函数所采用的隐式机制的问题。
我已经看到两种不同的方法来实现我认为使用 libmemcache(特别是 php-memcached)的相同目的。第一种也是最明显的方法是使用 getByKey/setByKey 将密钥映射到服务器,第二种方法是使用选项 OPT_PREFIX_KEY (在 memcached::_construct 下的 php 文档中发布了一个简单的示例),根据文档,该方法是“用于为您的项目密钥创建一个‘域’”。第二种方法的警告是它只能在每个实例的基础上设置,这可能是好事,也可能不是好事。
因此,除非我完全错误,否则这两种方法实际上并没有达到相同的目的;与其他方法相比,采用这种方法有什么明显的好处吗?
当我谈论这个主题时,我的另一个问题是:在一致的散列场景中将密钥映射到服务器有什么影响(如果有的话)?我假设如果一个节点发生故障,自由格式密钥将简单地重新映射到新服务器而不会出现任何问题..
谢谢!
As it is best practice to group related keys that are frequently retrieved together (using multiGet) on a single server for optimum performance, I have a couple questions regarding the implicit mechanics employed by the client functions built for doing this.
I have seen two different approaches for serving what I assume is the same purpose using libmemcache (php-memcached specifically). The first and most obvious approach is to use getByKey/setByKey to map keys to servers and the second is to use the option OPT_PREFIX_KEY (there is a simple example posted in the php documentation under memcached::_construct), which according to the documentation is "used to create a 'domain' for your item keys". The caveat of the second approach is that it can only be set on a per-instance basis, which may or may not be a good thing.
So unless I am completely mistaken, and these two approaches don't actually serve the same purpose; is that any clear benefit for going with approach over the other?
And while I'm on this topic my other question would be: What are the implications, if any, to mapping keys to servers in a consistently hashed scenario? I'm assuming that if a node were to fail, the freeform key would simply be remapped to a new server without any issue..
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果这些键实际上几乎总是一起检索,您可能希望将它们一起缓存在单个键/值对中,例如通过对键进行排序和连接并存储以 JSON 或类似格式序列化为字典的值。
回到你的问题:
If these keys are really almost always retrieved together you probably want to cache them together in a single key/value pair, for example by sorting and concatenating keys and storing values serialized as a dictionary in JSON or similar format.
Returning to your question: