The difference between memcached and Redis

Source: Internet
Author: User
Tags cas

1. The cached data in Redis is not all in memory, Redis is on MaxMemory or VM is on and Vm-max-memory arrives at a time-limited departure permutation operation uses the swap mechanism to transfer part of the value object (cold data) to disk. The redisobj is also replaced with the VM pointer object, which identifies the value of the disk where it is stored, with a blocking and non-blocking mechanism, so redis can store data far beyond the capacity itself

2, Network IO Model:Memcached is a multi-threaded, non-blocking IO multiplexing network model, divided into the main thread and the worker sub-thread, listening thread listening network connection, accept the request, the connection description Word pipe to the worker thread, read and write Io, The network layer uses the Libevent encapsulated event Library, the multithreaded model can play a multi-core role, but the introduction of the cache coherency and lock problems, such asMemcached most commonly used stats command, the actual Memcached all operations have to lock the global variable, count, and so on, resulting in performance loss.

Redis uses a single-threaded IO multiplexing model, which encapsulates a simple Aeevent event processing framework that implements Epoll, Kqueue, and select, which can be used to maximize the speed advantage for purely IO operations, but Redis also provides a number of simple computing functions, such as sorting, aggregation, etc., for these operations, the single-threaded model will actually seriously affect the overall throughput, CPU calculation process, the entire IO schedule is blocked.

3, memory management aspects

  Memcached uses a pre-allocated pool of memory to manage memory using slab and chunk of different sizes, item selects the appropriate chunk storage based on size, the way memory pools can save the cost of requesting/freeing memory, and can reduce memory fragmentation, However, this approach also leads to a certain amount of space waste, and in memory still has a lot of space, the new data may also be rejected, for reasons can refer to Timyang's article: http://timyang.net/data/Memcached- lru-evictions/

  The Redis data Store command parameters, which will be stored separately with the expiration time, and call them temporary data, non-temporary data will never be rejected, even if the physical memory is not enough, the swap will not eliminate any non-temporary data (but will try to exclude some temporary data), At this point Redis is more suitable as a storage rather than a cache.

4. Data consistency issues

  Memcached provides a CAS command that guarantees consistency of the same data for multiple concurrent access operations. Redis does not provide CAS commands, and this is not guaranteed, but Redis provides the functionality of a transaction that guarantees the atomicity of a sequence of commands and is not interrupted by any action.

5. Storage mode and other aspects

Memcached Basically only supports simple key-value storage, does not support enumeration, and does not support persistence and replication functions.

In addition to Key/value, Redis supports numerous data structures such as list,set,sorted Set,hash, which provides the keys for enumeration operations, but cannot be used online, and if you need to enumerate the data on-line,Redis It also provides features such as persistence and replication.

The difference between memcached and Redis

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.