A story of OS file cache in MySql

14 篇文章 0 订阅

问题

在一次Sql语句的测试中,我们发现一个有趣的现象:同一个测试数据集,第一次run相当的慢(average超过100ms);第二次及后面的run都很快,而且也很稳定(average 4ms)。

  • sql 如下

select * from table where node_index in (?, ?. ...?)

  • 每次测试跑10k条上面的sql,不同的参数

who cache the data

很显然有cache在作怪,问题是谁缓存了数据?

Mysql cache

key_buffer_size 500m -> 8 byte
query_cache_size 64m -> 0

我们调整了Mysql的 key_buffer_sizequery_cache_size (/etc/my.inf), 重启Mysql

 /etc/rc.d/init.d/mysql stop
 /etc/rc.d/init.d/mysql start

再次测试,发现查询还是相当的快。只有将数据集从一个10k切换到另外一个时,查询数据来慢下来。

Mysql index pre-loading

key_buffer_size 4096m
load index into cache us_ta_1 (INDEX_NODEX_INDEX);

另外测试了下Mysql的Index preloading,基本没啥效果。

OS file cache

考略到我们使用的MyISAM引擎,它相当的依赖于OS的文件缓存,而linux使用物理内存来做文件cache,我们试着清空了linux的文件缓存

echo 3 > /proc/sys/vm/drop_caches

效果立现,查询速度回到第一次查询。

warm up your data

由上可见,Mysql在重启时,在真正handle流量之前,最好首先warm up。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Once upon a time, there was a student named Sarah. Sarah was a dedicated student who always worked hard to excel in her studies. She was always the first one to arrive in class and the last one to leave. Sarah was passionate about learning and was always eager to expand her knowledge in various subjects. Despite her passion for learning, Sarah faced a lot of challenges in her academic journey. She struggled with mathematics and often found herself spending hours studying and practicing. However, Sarah never gave up and continued to work hard to overcome her weaknesses. One day, her hard work paid off when she received an A in her math test. She was overjoyed and felt a sense of accomplishment that she had never felt before. From that day on, Sarah was motivated to work even harder. As Sarah's academic journey progressed, she faced many other obstacles such as time management, stress, and peer pressure. However, she remained determined and focused on her goals. She joined study groups and sought help from her teachers whenever she needed it. Despite the challenges, Sarah graduated with flying colors and was accepted into her dream university. She majored in biology and went on to pursue a career in the medical field. Sarah's dedication and hard work had paid off, and she was now on her way to achieving her dreams. In conclusion, Sarah's story is a testament to the fact that with hard work, determination, and perseverance, anything is possible. She faced many obstacles in her academic journey, but she never gave up. She continued to work hard and eventually achieved her goals. Sarah is an inspiration to all students who are struggling with their studies.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FireCoder

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值