memcached的替代方法,可以持久保存到磁盘 [英] alternative to memcached that can persist to disk

查看:162
本文介绍了memcached的替代方法,可以持久保存到磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用memcached和我的java应用程序,总体来说它工作得很好。


对我来说最重要的memcached的功能是:

I am currently using memcached with my java app, and overall it's working great.

The features of memcached that are most important to me are:


  • 它很快,因为读取并且写入内存并且不要触摸磁盘
  • 它只是一个键/值存储(因为这是我的所有应用程序需要)
  • 它的分发
  • 它通过让每个对象只在一台服务器上有效地使用内存
  • 它不假设对象来自数据库(因为我的对象不是数据库对象)
  • it's fast, since reads and writes are in-memory and don't touch the disk
  • it's just a key/value store (since that's all my app needs)
  • it's distributed
  • it uses memory efficiently by having each object live on exactly one server
  • it doesn't assume that the objects are from a database (since my objects are not database objects)


但是,有一件事我想做,memcached无法做到。我想定期(可能每天一次)将缓存内容保存到磁盘。我希望能够从保存的磁盘映像恢复缓存。


磁盘保存不需要非常复杂。如果在保存期间添加了新的键/值,我不在乎它是否包含在保存中。如果在保存发生时修改了现有的键/值,则保存的值应该是旧值或新值,但我不关心哪一个。


任何人都可以推荐另一种缓存解决方案(免费或商业),它具有对我很重要的所有(或很大一部分)memcached功能,并且还允许保存和从磁盘恢复整个缓存?

However, there is one thing that I'd like to do that memcached can't do. I want to periodically (perhaps once per day) save the cache contents to disk. And I want to be able to restore the cache from the saved disk image.

The disk save does not need to be very complex. If a new key/value is added while the save is taking place, I don't care if it's included in the save or not. And if an existing key/value is modified while the save is taking place, the saved value should be either the old value or the new value, but I don't care which one.

Can anyone recommend another caching solution (either free or commercial) that has all (or a significant percentage) of the memcached features that are important to me, and also allows the ability to save and restore the entire cache from disk?

推荐答案

也许你的问题像我一样:我只有几台机器用于memcached,但有很多记忆即使其中一个发生故障或需要重新启动,它也会严重影响系统的性能。根据最初的memcached哲学,我应该添加更多内存较少的机器,但这不符合成本效益而且不完全是绿色IT;)

Maybe your problem like mine: I have only a few machines for memcached, but with lots of memory. Even if one of them fails or needs to be rebooted, it seriously affects the performance of the system. According to the original memcached philosophy I should add a lot more machines with less memory each, but that's not cost efficient and not exactly "green IT" ;)

对于我们的解决方案,我们为Cache系统构建了一个接口层,使得底层缓存系统的提供者可以嵌套,就像你可以使用流一样,并为memcached写了一个缓存提供者以及我们自己的简单的Key-Value-2磁盘存储提供商。然后我们为缓存项定义权重,表示如果无法从缓存中检索项目,则重建项目的成本是多少。嵌套磁盘缓存仅用于权重高于特定阈值的项目,可能约为所有项目的10%。

For our solution, we built a interface layer for the Cache system in a way that providers to underlying cache systems can be nested, like you can do with streams, and wrote a cache provider for memcached as well as our own very simple Key-Value-2-disk storage provider. Then we define a weight for cache items that represents how costly it is to rebuild an item if it cannot be retrieved from cache. The nested Disk cache is only used for items with a weight above a certain threshold, maybe around 10% of all items.

当在缓存中存储对象时,我们不会浪费时间,因为保存到一个或两个缓存无论如何都排队等待异步执行。因此写入磁盘缓存不需要很快。读取相同:首先我们选择memcached,只有当它不存在并且它是一个昂贵的对象时,我们检查磁盘缓存(比memcached慢一点,但仍然比重新计算30 GB更好)单台机器出现故障后的数据。)

When storing an object in the cache, we won't lose time as saving to one or both caches is queued for asynchronous execution anyway. So writing to the disk cache doesn't need to be fast. Same for reads: First we go for memcached, and only if it's not there and it is a "costly" object, then we check the disk cache (which is by magnitudes slower than memcached, but still so much better then recalculating 30 GB of data after a single machine went down).

这样我们就可以从两个世界中获得最佳效果,而无需用新的东西替换memcached。

This way we get the best from both worlds, without replacing memcached by anything new.

这篇关于memcached的替代方法,可以持久保存到磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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