Redis is a new universal storage system, and memcached still has its field of application
Memcached or Redis? This has been a controversial topic in modern high-performance Web applications. When Web applications that are based on relational databases need to improve performance, using caching is the first choice for the vast majority of architects, and naturally, memcached and redis are often preferred.
Common features
- Are key-value in the form of a memory database
- is a NoSQL family data management solution
- are based on the same Key-value data model
- All data is put in memory (this is also the reason for caching)
- Performance scores are the same, including metrics such as data throughput and latency
- Key-value storage systems that are mature and popular with open source projects
Memcached was originally developed by Brad Fitzpatrick for the LiveJournal website in 2003. And then rewrite it again in C (the first edition for Perl) and open to the public, which has become the cornerstone of modern web system development. The current development direction of memcached is to improve stability and performance optimization, rather than adding new feature features.
Redis was created in 2009 by Salvatore Sanfilippo, and until today Sanfilippo remains the only developer and code maintainer of Redis. It's also not surprising that Redis is also known as the "Memcached enhanced version (Memcached on steroids)", because part of Redis is built on the experience summary of Memcached. Redis has more features than memcached, which makes it more flexible, more powerful and more complex.
Memcached and Redis are used by many enterprises and a large number of production systems, supporting a variety of language development of the client, has a rich SDK. In fact, in the Internet Web development language of the dot scale, there is basically no support for memcached or Redis.
Why are memcached and Redis so popular? Not only is it extremely high performance, but also because they are relatively simple. It's pretty easy for programmers to get started using memcached or Redis. It may take only a few minutes to install and set up and integrate into the system. So it takes a little bit of time and effort to boost system performance immediately-usually by an order of magnitude. A simple solution can make a huge performance benefit: It's just too sour to imagine.
Memcached Applicable Scenarios
Because Redis is an emerging solution that offers more features, Redis is generally a better choice than memcached. Memcached may be a better choice in two specific scenarios.
The first is very finely-grained static data, such as HTML code snippets. Memcached's memory management is not as complex as Redis, so performance is higher because Memcached's meta-data metadata is smaller, with relatively little additional overhead. The only supported data type for memcached is the string, which is String
ideal for caching read-only data because the string does not require additional processing.
The second scenario is that memcached is easier to scale horizontally than redis. The reason for this is that it is simple to design and function, and memcached easier to extend. The message shows that Redis will have built-in reliable cluster support [but has been skipping tickets] in the upcoming version 3.0 (read CA release notes).
Redis comes in
You should prefer Redis unless you are under environmental constraints (such as legacy systems), or if your business complies with the 2 above scenarios. Using Redis as a cache, system efficiency can be greatly improved by tuning cache content.
It is clear that the advantage of Redis is cache management. The cache will make room for new data by removing the old data from memory, if necessary, by some kind of data eviction mechanism. Memcached's data recovery mechanism uses the LRU (Least recently used, least recently used) algorithm while prioritizing old blocks of data that are about the same size as new data. In contrast, Redis allows fine-grained control over expired caches, with 6 different strategies to choose from. Redis also employs a number of more complex memory management methods and recycling strategies.
Redis provides greater flexibility for cached objects. While the memcached limit is 250 bytes, the value is limited to 1 MB and can only be communicated through a plain text string. The key and value size limits for Redis are all megabytes (MB), which is binary safe "without data loss, regardless of encoding". With 6 data types, Redis makes caching and managing caches smarter and easier, opening up an infinite world for application developers.
Redis stores the fields and values of an object with a hash, and can be managed by a single key, compared to storing the object in string format.
See what you need to update an object with memcached:
- Get the entire string
- Deserializing objects
- Modify the value in it
- Serialize the object again
- Replace the entire string with a new string in the cache
And every update is going to do these things.
The use of Redis hashing can significantly reduce resource consumption and improve performance. Other Redis data types, such as list or Set, can be used to implement more complex cache management patterns.
Another significant advantage of Redis is that the data it stores is opaque, which means that the data can be manipulated directly on the server side. Most of the more than 160 commands can be used for data manipulation, so processing data through a server-side script call is a reality. These built-in commands and user scripts allow you to handle data tasks directly and flexibly without having to transfer data to another system over the network for processing.
Redis provides optional/adjustable data persistence to quickly load the cache after a crash/restart. Although we generally believe that the data in the cache is unstable and instantaneous, it is valuable to persist the data to disk in the cache system. Loading the warm-up immediately after a reboot takes a short time and reduces the overhead of the primary database system.
Finally, Redis provides master-slave replication (replication). The Replication can be used to implement a highly available cache system that allows for uninterrupted service in the event of some server downtime. Assuming that a cache server crashes, only a small number of users and programs are affected in a short time, and in most cases, there is a proven solution to ensure the availability of cached content and services.
Today's open source software is always providing the best practical technology solutions. When you need to use caching to improve application performance, Redis and memcached are the best product-level solutions. But given its rich features and advanced design, the vast majority of the time Redis should be your first choice.
Author's profile: Itamar Haber (@itamarhaber) is the chief developer of Redis Labs, which provides fully managed memcached and Redis cloud services for developers. With years of experience in software product development, Xeround, Etagon, Amicada, and M.N.S Ltd. as management and leadership positions. Itamar get Northwestern and Tel-aviv universitiesd Ogg-recanati, Master of Business Administration, and science in computer BS.
Related reading:
- Improve Java Enterprise application performance with memcached, Part 1: Architecture and Configuration
- Using memcached to improve Java Enterprise Application performance, Part 2: Database-based WebApp
- Cache contention: Azure and AWS Upgrade caching services
Original link: Why Redis beats Memcached for caching
Original Date: 2014-10-15
Translation Date: 2014-10-23
Translators: Anchor
From:https://github.com/cncounter/translation/blob/master/tiemao_2014/redis_beats_memcached/redis_beats_memcached.md
Why Redis is more useful than memcached