[Chinese-English control] Why Redis beats Memcached for caching | Why is Redis better than memcached in the context of caching?

Source: Internet
Author: User
Tags memcached redis labs

Students interested in memcached and Redis may wish to spend a few minutes reading this article, otherwise please drift over.

Why Redis beats Memcached for caching | Why is Redis better than memcached in the context of caching?

Memcached is sometimes more efficient, but Redis is almost alwaysthe better choice.

Xxx

Memcached or Redis? It's a question that nearly all arises in any discussion about squeezing more performance out of a modern, Database-dri Ven WEB application. When performance needs to be improved, caching was often the first step taken, and Memcached or Redis is typically the FIR St Places to turn.

Xxx

These renowned cache engines share a number of similarities, but they also has important differences. Redis, the newer and more versatile of the and, are almost always the superior choice.

Xxx

The similarities | similarities between memcached and Redis

Let's start with the similarities. Both Memcached and Redis serve as in-memory, Key-value data stores, although Redis is more accurately described as a data Structure store. Both Memcached and Redis belong to the NoSQL family of data management solutions, and Both is based on a key-value data m Odel. They both keep all data in RAM, which of course makes them supremely useful as a caching layer. In terms of performance, the data stores is also remarkably similar, exhibiting almost identical characteristics (and metrics) with respect to throughput and latency.
Xxxx

Both Memcached and Redis are mature and hugely popular open source projects. Memcached was originally developed by Brad Fitzpatrick in 2003 for the LiveJournal website. Since then, Memcached have been rewritten in C (the original implementation is in Perl) and put in the public domain, wher E It has become a cornerstone of modern WEB applications. Current development of Memcached are focused on stability and optimizations rather than adding new features.
Xxxx

Redis is created by Salvatore Sanfilippo in, and Sanfilippo remains the lead developer of the project today. Redis is sometimes described as "Memcached on steroids," which are hardly surprising considering that parts of Redis were B Uilt in response to lessons learned from using Memcached. Redis have more features than Memcached and are, thus, more powerful and flexible.
Xxxx

Used by many companies and in countless mission-critical production environments, both Memcached and Redis is supported B Y client libraries in every conceivable programming language, and it's included in a multitude of packages for developers. In fact, it's a rare Web stack that does does include built-in support for either Memcached or Redis.
Xxxx

Why is Memcached and Redis so popular? Not only is they extremely effective, they ' re also relatively simple. Getting started with either Memcached or Redis are considered easy work for a developer. It takes only a few minutes to set up and get them working with an application. Thus, a small investment of time and effort can has an immediate, dramatic impact on performance--usually by orders of Magnitude. A simple solution with a huge benefit; That's as close to magic as can get.
Xxxx

When to use Memcached | Why use mecached?

Because Redis is newer and have more features than Memcached, Redis are almost always the better choice. However, Memcached could is preferable when caching relatively small and static data, such as HTML code fragments. Memcached ' s internal memory management, while not as sophisticated as that of Redis, are more efficient in the simplest use Cases because it consumes comparatively less memory resources for metadata. Strings (the only data type supported by Memcached) is ideal for storing data this ' s only read, because Strings require n o further processing.
Xxx

That said, Memcached's memory management efficiency diminishes quickly when data size was dynamic, at which point Memcached ' s memory can become fragmented. Also, large data sets often involve serialized data, which always requires more space to store. While Memcached are effectively limited to storing data in their serialized form, the data structures in Redis can store any aspect of the data natively, thus reducing serialization overhead.
Xxx

The second scenario in which Memcached have an advantage over Redis are in scaling. Because Memcached is multithreaded, you can easily scale up by giving it more computational resources, but you'll lose p Art or all of the cached data (depending in whether you use consistent hashing). Redis, which is mostly single-threaded, can scale horizontally via clustering without loss of data. Clustering is a effective scaling solution, but it's comparatively more complex to set up and operate.
Xxx

When to use Redis | What about Redis?

You'll almost always want to use Redis because of its data structures. With Redis as a cache, you gain a lot of power (such as the ability to fine-tune cache contents and durability) and greate R efficiency overall. Once your use of the data structures, the efficiency boost becomes tremendous for specific application scenarios.
Xxx

Redis ' superiority is evident in almost every aspect of cache management. Caches employ a mechanism called data eviction to make the new data by deleting the old data from memory. Memcached ' s data eviction mechanism employs a Least recently used algorithm and somewhat arbitrarily evicts data that ' s SI Milar in size to the new data.
Xxx

Redis, by contrast, allows for fine-grained control over eviction, letting-choose from six different eviction policies . Redis also employs more sophisticated approaches to memory management and eviction candidate selection. Redis supports both lazy and active eviction, where data is evicted only if more space is needed or proactively. Memcached, on the other hand, provides lazy eviction only.
Xxx

Redis gives much greater flexibility regarding the objects you can cache. While Memcached limits key names to + bytes and works with plain strings only, Redis allows key names and values to be a s large as 512MB each, and they is binary safe. Plus, Redis have five primary data structures to choose from, opening up a world's possibilities to the application Develo Per through intelligent caching and manipulation of cached data.
Xxx

Beyond Caching | more than just the cache

Using REDIS data structures can simplify and optimize several tasks-not only while caching, but even when you want the Data to is persistent and always available. For example, instead of storing objects as serialized strings, developers can use a Redis Hash to store an object ' s fields And values, and manage them using a single key. Redis Hash saves developers the need to fetch the entire string, deserialize it, update a value, reserialize the object, a nd replace the entire string in the cache with its new value for every trivial update – that means lower resource consump tion and increased performance.
Xxx

Other data structures offered by Redis (such as lists, sets, sorted sets, hyperloglogs, bitmaps, and geospatial indexes) c An is used to implement even more complex scenarios. Sorted sets for time-series data ingestion and analysis are another example of a REDIS data structure that offers ENORMOUSL Y reduced complexity and lower bandwidth consumption.
Xxx

Another important advantage of Redis is that the data it stores isn ' t opaque and so the server can manipulate it directly. A considerable share of the 180-plus commands available in Redis is devoted to data processing operations and Embedding L Ogic in the data store itself via Server-side Lua scripting. These built-in commands and user scripts give you the flexibility of handling data processing tasks directly on Redis with Out has to ship data across the network to another system for processing.
Xxx

Redis offers optional and tunable data persistence designed to bootstrap the cache after a planned shutdown or an Unplanne D failure. While we tend to regard the data in caches as volatile and transient, persisting data to disk can is quite valuable in CAC Hing scenarios. Have the cache ' s data available for loading immediately after restart allows for much shorter cache warm-up and removes The load involved in repopulating and recalculating caches contents from the primary data store.
Xxx

Data replication Too | and data replication yo

Redis can also replicate the data that it manages. Replication can used for implementing a highly available cache setup that can withstand failures and provide Uninterrup Ted service to the application. A cache failure falls only slightly short of application failure in terms of the impact on user experience and application Performance, so has a proven solution that guarantees the cache's contents and service availability is a major Advanta GE in the most cases.
Xxx

Last but not least, in terms of operational visibility, Redis provides a slew of metrics and a wealth of introspective com Mands with which to monitor and track usage and abnormal behavior. Real-time statistics about every aspect of the database, the display of all commands being executed, the listing and Manag ing of the client connections--Redis has all, and more.
Xxx

When developers realize the effectiveness of Redis ' persistence and in-memory replication capabilities, they often use it As a first-responder database, usually to analyze and process high-velocity data and provide responses to the user while a Secondary (often slower) database maintains a historical record of what happened. When used in this manner, Redis can also is ideal for analytics use cases.
Xxx

Redis for Analytics | doing data analysis, Redis says, "I can."

Three analytics scenarios come immediately to mind. In the first scenario, if using something like Apache Spark to iteratively process large data sets, you can use Redis as A serving layer for data previously calculated by Spark. In the second scenario, using Redis as your shared, in-memory, distributed data store can accelerate Spark processing Spee DS by a factor of 100. Finally, an all too common scenario are one in which reports and analytics need to being customizable by the user, but Retriev ing data from inherently batch data stores (like Hadoop or an RDBMS) takes too long. In this case, an in-memory data structure store such as Redis are the only practical a-to, getting submillisecond a nd response times.
Xxx

When using extremely large operational data sets or analytics workloads, running everything in-memory might not being cost EF Fective. To achieve submillisecond performance at lower cost, Redis Labs created a version of Redis that runs on a combination of R AM and Flash, with the option to configure Ram-to-flash ratios. While this opens-several new avenues to accelerate workload processing, it also gives developers the option to simply R Un their "cache on Flash."
Xxxx

Open source software continues to provide some of the best technologies available today. When it comes to boosting application performance through caching, Redis and Memcached is the most established and Produc Tion-proven candidates. However, given its richer functionality, most advanced design, many potential uses, and greater cost efficiency at scale, Redis should is your first choice in nearly every case.
Xxx

[Bilingual]why Redis beats Memcached for caching | Why is Redis better than Memcached in terms of caching?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.