MySQL and file system cache

Source: Internet
Author: User

Objective:

Today a friend asked a question, the original text is as follows: Mysql5.1,myisam table, select COUNT (*) as total from m_bff WHERE from_uid= ' 73149293 ' and isdeleted=0. From_uid Index, the first time to execute this sentence slow, more than 1 seconds, with show profile is slow on the sending data. But then I add sql_no_cache, execution only takes 0.01 seconds, there are a lot of sentences are similar to the first slow, and then add Sql_no_cache is not slow, key_blocks_unused also a lot, ask what is the reason for this?

The question is: Why is the query for the MyISAM table so much slower for the first time than the second?

Recalling the difference between InnoDB and MyISAM, one of the most important is that MyISAM caches only the indexed content, and InnoDB not only caches the index but also caches the data. That is supposed to say MyISAM every time the data query should be disk access will not have a big speed gap.

In fact, there is a layer of OS-level file caching between the MyISAM file and the operating system. Guessing is the OS file cache ramming Ghost.

Verify:

The authentication method is very simple, run cat 3 >/proc/sys/vm/drop_caches under the shell with root privileges to empty the OS file cache and run SQL to see if it is the same speed as the first run.

Results:

Well, afterEcho 3/proc/sys/vm/drop_caches , it's slow again, and it looks like you're talking about a problem.

Extended:

Once you know the MyISAM feature, you can use the file pre-read method to do data preheating.

Suppose a table is a hotspot table, and the operating system has more memory spare. We can use cat table. MYD >>/dev/null way to load files into the OS file cache. This way, when some users ' data is accessed for the first time, there is no slow query.

MySQL and file system cache

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.