The similarities and differences between Redis+mysql mode and memory + HDD mode

Source: Internet
Author: User

Http://www.open-open.com/lib/view/open1346029825942.html

Learn any new knowledge, is a gradual process, from the beginning of ignorant ignorance, to simple familiar, and then suddenly mourn, the results let people ecstatic, the mood will be happy for a long time.

Redis+mysql and memory + hard disk similar to the place

First look at the picture:

First of all, we know that MySQL is persistent storage, stored in the disk, retrieval, will involve a certain IO, in order to solve the bottleneck, so there is a cache, such as the current use of the most memcached (referred to as MC). First, the user accesses the MC and, if missed, accesses MySQL, then copies the data to the MC part like memory and hard disk.

Both Redis and MC are cached and reside in memory, which greatly increases the access speed of high data volume Web Access. However, MC simply provides a simple data structure, such as string storage, but Redis provides a lot of data structure, such as String, list, set, HashSet, sorted set these, which makes the user convenient a lot of, after all, encapsulated a layer of practical functions, At the same time achieve the same effect, of course, with Redis and slowly discard MC.

Memory and hard disk relationship, hard disk placement of the principal data for persistent storage, and memory is currently running part of the data, CPU access to memory rather than disk, which greatly increased the speed of operation, of course, this is based on the program's local access principle.

Reasoning to Redis+mysql, it is a mapping of memory + disk relationships, MySQL placed on disk, Redis placed in memory, so that the Web app accesses only Redis at a time, and if no data is found, it accesses MySQL.

However, the use of redis+mysql and memory + disks is best different.

Redis+mysql and memory + hard disk running mode is different to understand the memory and hard disk running process of students, know that they are between the two through the page replacement algorithm scheduling, that is, each time the data from the hard disk in a block or swap out memory, such as the hard disk has a 100G file, if you want to read this file, Only part of the file 10MB is placed in memory each time (this is what the small block in Figure 1 means).

So someone would guess that MySQL stored 100G of data, when users visit MySQL, the 10MB data copied to Redis, such as select a id=1000 data, then put id=10 to id=9999 data to Redis, for the next visit. But the key is that MySQL data access, not the local principle of the file, different users access is completely different things, and the order of the ID does not have any relationship.

In fact, the strengths of Redis are not here, it is good at preserving the metadata class data, which means descriptive rather than the data itself

In this context I have assumed several applications of Redis, please criticize:

    • The number that holds the counter
    • A list of IDs that hold search keywords (no content)
    • Storing follow relationships between users (non-user information)
    • Store simple static HTML, not all CSS and JS

In short, it is found that Redis is a large number of data table index field, if you just use the matching information, you can follow the index field, and then go to MySQL search, such as searching for the keyword "Redis", The first step we go to MySQL to get Redis related information back to the user, and then record a zset, the Redis as the name, will be searched for each ID in order to exist inside, then next time someone search "Redis", directly according to the list to go to MySQL to find the corresponding ID information on the line , which has greatly increased the speed of access.

is a flowchart for retrieving:

The similarities and differences between Redis+mysql mode and memory + HDD mode

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.