Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

caching - Memcached与Redis?(Memcached vs. Redis?)

We're using a Ruby web-app with Redis server for caching. (我们正在将带Redis服务器的Ruby Web应用程序用于缓存。) Is there a point to test Memcached instead? (有没有要测试Memcached的地方呢?)

What will give us better performance? (什么会给我们带来更好的性能?) Any pros or cons between Redis and Memcached? (Redis和Memcached之间有什么优缺点?)

Points to consider: (要考虑的要点:)

  • Read/write speed. (读/写速度。)
  • Memory usage. (内存使用情况。)
  • Disk I/O dumping. (磁盘I / O转储。)
  • Scaling. (缩放比例。)
  ask by Sagiv Ofek translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Summary (TL;DR) (摘要(TL; DR))

Updated June 3rd, 2017 (2017年6月3日更新)

Redis is more powerful, more popular, and better supported than memcached. (与memcached相比,Redis功能更强大,更受欢迎并且得到更好的支持。) Memcached can only do a small fraction of the things Redis can do. (Memcached只能做Redis可以做的一小部分。) Redis is better even where their features overlap. (即使Redis的功能重叠,Redis也更好。)

For anything new, use Redis. (对于任何新内容,请使用Redis。)

Memcached vs Redis: Direct Comparison (Memcached与Redis:直接比较)

Both tools are powerful, fast, in-memory data stores that are useful as a cache. (两种工具都是功能强大,快速的内存中数据存储,可用作缓存。) Both can help speed up your application by caching database results, HTML fragments, or anything else that might be expensive to generate. (两者都可以通过缓存数据库结果,HTML片段或其他可能产生成本很高的内容来帮助加快应用程序的速度。)

Points to Consider (要考虑的要点)

When used for the same thing, here is how they compare using the original question's "Points to Consider": (当用于同一事物时,以下是它们如何使用原始问题的“要考虑的要点”进行比较:)

  • Read/write speed : Both are extremely fast. (读/写速度 :两者都非常快。) Benchmarks vary by workload, versions, and many other factors but generally show redis to be as fast or almost as fast as memcached. (基准测试因工作负载,版本和许多其他因素而异,但通常显示redis与memcached一样快或几乎一样快。) I recommend redis, but not because memcached is slow. (我建议使用redis,但不是因为memcached速度慢。) It's not. (不是。)
  • Memory usage : Redis is better. (内存使用 :Redis更好。)
    • memcached: You specify the cache size and as you insert items the daemon quickly grows to a little more than this size. (memcached:您指定高速缓存大小,并且在插入项目时,守护程序会迅速增长到略大于该大小。) There is never really a way to reclaim any of that space, short of restarting memcached. (除了重新启动memcached之外,从来没有真正的方法可以回收任何空间。) All your keys could be expired, you could flush the database, and it would still use the full chunk of RAM you configured it with. (您所有的密钥都可能过期,您可以刷新数据库,并且该数据库仍将使用您为其配置的全部RAM。)
    • redis: Setting a max size is up to you. (redis:设置最大大小由您决定。) Redis will never use more than it has to and will give you back memory it is no longer using. (Redis将永远不会使用过多的内存,并将为您提供不再使用的内存。)
    • I stored 100,000 ~2KB strings (~200MB) of random sentences into both. (我将100,000个?2KB字符串(?200MB)的随机句子存储到了两者中。) Memcached RAM usage grew to ~225MB. (Memcached RAM使用量增加到约225MB。) Redis RAM usage grew to ~228MB. (Redis RAM使用量增加到?228MB。) After flushing both, redis dropped to ~29MB and memcached stayed at ~225MB. (刷新两次后,redis降至?29MB,memcached保持在?225MB。) They are similarly efficient in how they store data, but only one is capable of reclaiming it. (它们在存储数据方面同样有效,但是只有一个能够回收数据。)
  • Disk I/O dumping : A clear win for redis since it does this by default and has very configurable persistence. (磁盘I / O转储 :Redis显然是赢家,因为它默认情况下会这样做,并且具有非常可配置的持久性。) Memcached has no mechanisms for dumping to disk without 3rd party tools. (没有第3方工具,Memcached没有任何机制可以转储到磁盘。)
  • Scaling : Both give you tons of headroom before you need more than a single instance as a cache. (可扩展性 :在需要多个实例作为缓存之前,两者都为您提供了大量的净空。) Redis includes tools to help you go beyond that while memcached does not. (Redis包含的工具可帮助您超越此范围,而memcached则不会。)

memcached (记忆快取)

Memcached is a simple volatile cache server. (Memcached是一个简单的易失性缓存服务器。) It allows you to store key/value pairs where the value is limited to being a string up to 1MB. (它允许您存储键/值对,其中值限制为最大1MB的字符串。)

It's good at this, but that's all it does. (擅长此事,但仅此而已。) You can access those values by their key at extremely high speed, often saturating available network or even memory bandwidth. (您可以通过它们的键以极高的速度访问这些值,这通常会使可用的网络或什至是内存带宽饱和。)

When you restart memcached your data is gone. (重新启动内存缓存后,您的数据不见了。) This is fine for a cache. (这对于缓存很好。) You shouldn't store anything important there. (您不应该在其中存储任何重要内容。)

If you need high performance or high availability there are 3rd party tools, products, and services available. (如果您需要高性能或高可用性,则可以使用第三方工具,产品和服务。)

redis (Redis)

Redis can do the same jobs as memcached can, and can do them better. (Redis可以完成与memcached相同的工作,并且可以做得更好。)

Redis can act as a cache as well. (Redis也可以充当缓存 。) It can store key/value pairs too. (它也可以存储键/值对。) In redis they can even be up to 512MB. (在redis中,它们甚至可以达到512MB。)

You can turn off persistence and it will happily lose your data on restart too. (您可以关闭持久性,并且在重新启动时也很可能会丢失数据。) If you want your cache to survive restarts it lets you do that as well. (如果您希望缓存能够继续运行,那么重新启动也可以。) In fact, that's the default. (实际上,这是默认设置。)

It's super fast too, often limited by network or memory bandwidth. (它也非常快,通常受网络或内存带宽的限制。)

If one instance of redis/memcached isn't enough performance for your workload, redis is the clear choice. (如果一个redis / memcached实例的性能不足以处理您的工作负载,那么redis是不二之选。) Redis includes cluster support and comes with high availability tools ( redis-sentinel ) right "in the box". (Redis包括集群支持,并附带了“在盒子里”的高可用性工具( redis-sentinel )。) Over the past few years redis has also emerged as the clear leader in 3rd party tooling. (在过去的几年中,redis也已成为第三方工具的明确领导者。) Companies like Redis Labs, Amazon, and others offer many useful redis tools and services. (Redis Labs,Amazon等公司提供许多有用的Redis工具和服务。) The ecosystem around redis is much larger. (Redis周围的生态系统更大。) The number of large scale deployments is now likely greater than for memcached. (现在,大规模部署的数量可能会大于内存缓存的数量。)

The Redis Superset (Redis超集)

Redis is more than a cache. (Redis不仅仅是一个缓存。) It is an in-memory data structure server. (它是一个内存中的数据结构服务器。) Below you will find a quick overview of things Redis can do beyond being a simple key/value cache like memcached. (在下面,您将快速概览Redis可以做的事情,而不仅仅是像memcached这样的简单键/值缓存。) Most of redis' features are things memcached cannot do. (Redis的大多数功能都是memcached无法做到的。)

Documentation (文献资料)

Redis is better documented than memcached. (Redis的文档比memcached的文档更好。) While this can be subjective, it seems to be more and more true all the time. (尽管这可能是主观的,但它似乎一直在越来越真实。)

redis.io is a fantastic easily navigated resource. (redis.io是一个很棒的易于导航的资源。) It lets you try redis in the browser and even gives you live interactive examples with each command in the docs. (它使您可以在浏览器中尝试redis,甚至还可以通过文档中的每个命令为您提供实时的交互式示例。)

There are now 2x as many stackoverflow results for redis as memcached. (现在,redis的堆栈溢出结果是内存缓存的2倍。) 2x as many Google results. (是Google结果的2倍。) More readily accessible examples in more languages. (提供更多语言的更易于访问的示例。) More active development. (更积极的发展。) More active client development. (更积极的客户开发。) These measurements might not mean much individually, but in combination they paint a clear picture that support and documentation for redis is greater and much more up-to-date. (这些度量可能并没有太大的意义,但结合起来可以清楚地看到,有关Redis的支持和文档越来越多,而且是最新的。)

Persistence (坚持不懈)

By default redis persists your data to disk using a mechanism called snapshotting. (默认情况下,redis使用称为快照的机制将数据持久保存到磁盘。) If you have enough RAM available it's able to write all of your data to disk with almost no performance degradation. (如果您有足够的可用RAM,则可以将所有数据写入磁盘,而性能几乎不会降低。) It's almost free! (它几乎是免费的!)

In snapshot mode there is a chance that a sudden crash could result in a small amount of lost data. (在快照模式下,突然崩溃可能会导致少量数据丢失。) If you absolutely need to make sure no data is ever lost, don't worry, redis has your back there too with AOF (Append Only File) mode. (如果您绝对需要确保没有任何数据丢失,请放心,redis也使用AOF(仅附加文件)模式支持您。) In this persistence mode data can be synced to disk as it is written. (在这种持久模式下,数据可以在写入时同步到磁盘。) This can reduce maximum write throughput to however fast your disk can write, but should still be quite fast. (这样可以将最大写入吞吐量降低到磁盘可以写入的速度,但是仍然应该非常快。)

There are many configuration options to fine tune persistence if you need, but the defaults are very sensible. (如果需要,有许多配置选项可以微调持久性,但是默认设置非常明智。) These options make it easy to setup redis as a safe, redundant place to store data. (这些选项使将Redis设置为安全,冗余的数据存储位置变得容易。) It is a real database. (这是一个真实的数据库。)

Many Data Types (许多数据类型)

Memcached is limited to strings, but Redis is a data structure server that can serve up many different data types. (Memcached仅限于字符串,但是Redis是一个数据结构服务器,可以提供许多不同的数据类型。) It also provides the commands you need to make the most of those data types. (它还提供了充分利用这些数据类型所需的命令。)

Strings ( commands ) (字符串( 命令 ))

Simple text or binary values that can be up to 512MB in size. (简单文本或二进制值,最大可为512MB。) This is the only data type redis and memcached share, though memcached strings are limited to 1MB. (这是唯一的数据类型redis和memcached共享,尽管memcached字符串限制为1MB。)

Redis gives you more tools for leveraging this datatype by offering commands for bitwise operations, bit-level manipulation, floati


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...