It turns out you're the Key-value store.

Source: Internet
Author: User
Tags redis labs value store

Last week, teacher Mao, in-house sharing for our literacy for a bit memcached and redis support, said a lot of things, I am generally lazy reluctant to remember things like to summarize into a blog, when I forget the time can look back. That's all the good crap. First look at memcached and Redis's introduction:

Memcached

memcached is a distributed cache system developed by LiveJournal Brad Fitzpatrick, but is currently used by many Web sites. This is a set of open source software to be released in BSD license licensing.

Memcached lacks authentication and security controls, which means that the memcached server should be placed behind a firewall.

The Memcached API uses a 32-bit cyclic redundancy check (CRC-32) to calculate key values and spread the data across different machines. When the table is full, the next new data is replaced with the LRU mechanism. Since memcached is typically used only as a caching system, applications that use memcached require additional code to update the data in the memcached when they write back to a slower system, such as a back-end database.

Redis

Redis is an open source, support network, memory-based, key-value-pair storage database, written using ANSI C. Since June 2015, the development of Redis has been sponsored by Redis Labs, and its development was sponsored by pivotal from May 2013 to June 2015. [1] Prior to May 2013, its development was sponsored by VMware. [2][3] According to the monthly ranking website db-engines.com data shows that Redis is the most popular key-value pair storage database. [4]

Problems encountered in traditional mysql+ memcached architectures

The actual MySQL is suitable for massive data storage, through the memcached to load hot data to the cache, speed up access, many companies have used such a structure, but with the increasing volume of business data, and the continuous growth of traffic, we encounter a lot of problems:

    1. MySQL needs to continue to disassemble the table, memcached also need to continuously follow the expansion, expansion and maintenance work occupies a lot of development time.
    2. memcached and MySQL database data consistency issues.
    3. Memcached data hit rate is low or down, a large number of access directly through to the Db,mysql can not support.
    4. Cache sync problem across room.
The comparison between Redis and memcached

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, after accepting the request, the connection description Word pipe to the worker thread, read/write IO, the network layer using the Libevent encapsulated event Library , multithreading model can play a multi-core role, but the introduction of the cache coherency and lock problem, for example, memcached most commonly used stats command, the actual memcached all operations to the global variable lock, count, etc., resulting in performance loss.

(memcached network IO model)

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. However, Redis also provides some simple computing functions, such as sorting, aggregation, etc., for these operations, the single-threaded model can actually seriously affect the overall throughput, CPU calculation process, the entire IO schedule is blocked

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, But this approach can also lead to a certain amount of wasted space, and new data may be removed when there is still a lot of space in memory

Redis uses on-site memory storage to store data, and rarely uses free-list to optimize memory allocation, and there is a degree of memory fragmentation, and the Redis data store command parameters, which store the time-to-date information separately, and call them temporary data. Non-temporary data is never removed, even if there is not enough physical memory, so that swap will not eliminate any non-temporal data (but will attempt to eliminate some temporary data), which is more appropriate for Redis as storage instead of the cache.

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.

Storage methods 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

enumeration, but not on-line, if you need to enumerate online data, Redis provides tools to scan its dump files, enumerate all the data, and Redis also provides the functionality of persistence and replication.

Summarize:

    1. The best way to use Redis is to in-memory all data.
    2. Redis more scenes are used as substitutes for memcached.
    3. Redis is more appropriate when it is necessary to support more data types than Key/value.
    4. Redis is more appropriate when the stored data cannot be rejected.

The enemy, Baizhanbudai. To make good use of memcached and redis in development we need to know more about how they are implemented. READ MORE:

Memcached

Redis

Redis memory usage optimization and storage

Memcached data is kicked (evictions>0) phenomenon analysis

If you have any better information, please leave a message.

It turns out you're the Key-value store.

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.