My application is very database intensive so I've tried really hard to make sure the application and the MySQL database are working as efficiently as possible together.

我的應用程序是非常數據庫密集型的,所以我非常努力地確保應用程序和MySQL數據庫能夠盡可能高效地工作。

Currently I'm tuning the MySQL query cache to get it in line with the characteristics of queries being run on the server.

目前,我正在調優MySQL查詢緩存,以使其符合在服務器上運行的查詢的特性。

query_cache_size is the maximum amount of data that may be stored in the cache and query_cache_limit is the maximum size of a single resultset in the cache.

query_cache_size是緩存中可能存儲的最大數據量,query_cache_limit是緩存中單個resultset的最大大小。

My current MySQL query cache is configured as follows:

我現在的MySQL查詢緩存配置如下:

query_cache_size=128M

query_cache_limit=1M

tuning-primer.sh gives me the following tuning hints about the running system:

tuning-primer。sh給了我以下關於運行系統的調優提示:

QUERY CACHE

Query cache is enabled

Current query_cache_size = 128 M

Current query_cache_used = 127 M

Current query_cache_limit = 1 M

Current Query cache Memory fill ratio = 99.95 %

Current query_cache_min_res_unit = 4 K

However, 21278 queries have been removed from the query cache due to lack of memory

Perhaps you should raise query_cache_size

MySQL won't cache query results that are larger than query_cache_limit in size

And mysqltuner.pl gives the following tuning hints:

和mysqltuner。pl給出如下的調優提示:

[OK] Query cache efficiency: 31.3% (39K cached / 125K selects)

[!!] Query cache prunes per day: 2300654

Variables to adjust:

query_cache_size (> 128M)

Both tuning scripts suggest that I should raise the query_cache_size. However, increasing the query_cache size over 128M may reduce performance according to mysqltuner.pl (see http://mysqltuner.pl/).

兩個調優腳本都建議我應該提高query_cache_size。然而,根據mysqltuner,增加query_cache大小超過128M可能會降低性能。pl(見http://mysqltuner.pl/)。

How would you tackle this problem? Would you increase the query_cache_size despite mysqltuner.pl's warning or try to adjust the querying logic in some way? Most of the data access is handled by Hibernate, but quite a lot of hand-coded SQL is used in the application as well.

你將如何解決這個問題?您是否會在mysqltuner中增加query_cache_size。pl的警告或試圖以某種方式調整查詢邏輯?大多數數據訪問都是由Hibernate處理的,但是在應用程序中也使用了很多手工編碼的SQL。

6 个解决方案

#1

12

Usually "too big cache size" warnings are issued under assumption that you have few physical memory and the cache itself well need to be swapped or will take resources that are required by the OS (like file cache).

通常“太大的緩存大小”警告是在假設您沒有物理內存和緩存本身需要被交換或將需要的資源(如文件緩存)的情況下發出的。

If you have enough memory, it's safe to increase query_cache size (I've seen installations with 1GB query cache).

如果您有足夠的內存,那么增加query_cache大小是安全的(我已經看到了帶有1GB查詢緩存的安裝)。

But are you sure you are using the query cache right? Do have lots of verbatim repeating queries? Could you please post the example of a typical query?

但是,您確定使用的是查詢緩存嗎?是否有大量重復的查詢?你能把一個典型的查詢的例子張貼出來嗎?

#2

17

The warning issued by mysqltuner.py is actually relevant even if your cache has no risk of being swapped. It is well-explained in the following: http://blogs.oracle.com/dlutz/entry/mysql_query_cache_sizing

mysqltuner發出的警告。py實際上是相關的,即使你的緩存沒有被交換的風險。它在以下內容中得到了很好的解釋:http://blogs.oracle.com/dlutz/entry/mysql_query_cache_size。

Basically MySQL spends more time grooming the cache the bigger the cache is and since the cache is very volatile under even moderate write loads (queries gets cleared often), putting it too large will have an adverse effect on your application performance. Tweak the query_cache_size and query_cache_limit for your application, try finding a breaking point where you have most hits per insert, a low number of lowmem_prunes and keep a close eye on your database servers load while doing so too.

基本上,MySQL花更多的時間來修飾緩存,緩存越大,而且即使是適度的寫負載(查詢經常被清除),緩存也會變得非常不穩定,把它設置得太大會對您的應用程序性能產生不利影響。為您的應用程序調整query_cache_size和query_cache_limit,試着找到一個斷點,在這里,每個insert有最多的點擊量,低數量的lowmem_prunes,並且在這樣做的同時,密切關注數據庫服務器的負載。

#3

12

You should be easy on increasing your cache, it is not only a "not that much available mem" thing!

你應該很容易增加你的緩存,它不僅僅是一個“沒有那么多可用的mem”的東西!

Reading for instance the manual you get this quote:

例如,閱讀手冊你得到這句話:

Be cautious about sizing the query cache excessively large, which increases the overhead required to maintain the cache, possibly beyond the benefit of enabling it. Sizes in tens of megabytes are usually beneficial. Sizes in the hundreds of megabytes might not be.

對於過於龐大的查詢緩存,要謹慎,這增加了維護緩存所需的開銷,可能超出了啟用它的好處。幾十兆字節的大小通常是有益的。幾百兆字節的大小可能不是。

There are various other sources you can check out!

還有很多其他的來源你可以看看!

A non-zero prune rate may be an indication that you should increase the size of your query cache. However, keep in mind that the overhead of maintaining the cache is likely to increase with its size, so do this in small increments and monitor the result. If you need to dramatically increase the size of the cache to eliminate prunes, there is a good chance that your workload is not a good match for the query cache.

一個非零的prune速率可能是一個提示,您應該增加查詢緩存的大小。但是,請記住,保持緩存的開銷可能會隨着它的大小而增加,所以要以較小的增量來執行,並監控結果。如果您需要顯著地增加緩存的大小以消除prunes,那么您的工作負載很可能不是查詢緩存的好匹配。

So don't just put as much as you can in that query cache!

所以,不要在查詢緩存中盡可能多地添加內容!

The best thing, would be to gradually increase the query cache and measure performance on your site. It's some sort of default in performance questions, but in cases like this 'testing' is one of the best things you can do.

最好的方法是逐步增加查詢緩存,並在站點上測量性能。在性能問題上,這是一種默認,但在這種情況下,“測試”是你能做的最好的事情之一。

#4

4

Be careful with setting the query_cache_size and limit to high. MySQL only uses a single thread to read from the query cache.

小心設置query_cache_size和limit到high。MySQL只使用從查詢緩存讀取的單個線程。

With the query_cache_size set to 4G and query_cache_limit 12M we had a query cache rate of 85% but noticed a recurring spikes in connections.

在query_cache_size設置為4G和query_cache_limit 12M時,我們的查詢緩存率為85%,但注意到連接中出現了重復的峰值。

After changing the query_cache_size to 256M with 64K query_cache_limit the query cache ratio dropped to 50% but the overall performance increased.

在將query_cache_size更改為256M,並使用64K query_cache_limit后,查詢緩存比率下降到50%,但是總體性能提高了。

#5

3

Query Cache gets invalidated/flush every time there is an insert, Use InnoDB/cache and avoid query cache or set it to a very small value.

每次有插入時,查詢緩存都會失效/刷新,使用InnoDB/ Cache,避免查詢緩存,或者將其設置為非常小的值。

#6

3

Overhead for Query cache is around 10% so I would disable query caching. Usually if you can't get your hit rate over 40 or 50 % maybe query cache isn't right for your database.

查詢緩存的開銷約為10%,因此我將禁用查詢緩存。通常情況下,如果您無法將命中率超過40%或50%,那么查詢緩存就不適合您的數據庫。

關於這個話題,我有博客……Mysql query_cache_size性能。

mysql query cache 大小_MySQL查詢緩存:限制為128 MB的最大緩存大小?相关推荐

  1. mysql query cache 命中率_MySQL缓存命中率概述及如何提高缓存命中率

    MySQL缓存命中率概述 工作原理: 查询缓存的工作原理,基本上可以概括为: 缓存SELECT操作或预处理查询(注释:5.1.17开始支持)的结果集和SQL语句: 新的SELECT语句或预处理查询语句 ...

  2. mysql query cache

    1.概述: MySQL Query Cache 缓存客户端提交给MySQL的SELECT(注意只是select)语句以及该语句的结果集. 注意:query_cache是mysql server端的查询 ...

  3. mysql query cache优化

    query cache原理 当mysql接收到一条select类型的query时,mysql会对这条query进行hash计算而得到一个hash值,然后通过该hash值到query cache中去匹配 ...

  4. 为什么要关闭 MySQL Query Cache?

    备注:插图来自淘宝苏普的博客并保留水印,如果觉得不当还请及时告知 :) 写在前面:MySQL的query cache大部分情况下其实只是鸡肋而已,建议全面禁用.当然了,或许在你的场景下还是挺好的,还能 ...

  5. mysql query cache 关闭_为什么要关闭MySQL query cache-Fun言

    MySQL的query cache大部分情况下其实只是鸡肋而已,建议全面禁用.当然了,或许在你的场景下还是挺好的,还能发挥作用,那就继续使用吧,把本文当做参考就好. 不过,可能有的人人为只需要把 qu ...

  6. mysql query cache 查询缓存

    查看本博文,并进行验证(验证结果与博文一致): https://blog.csdn.net/carmazhao/article/details/7088530 mysql默认是开启查询缓存的. 设置查 ...

  7. mysql 多重group_mysql多重子查詢group_concat查詢

    我的數據庫結構很好,有一張表,如城鎮,郵政編碼和自治市鎮. town_postcode & town_borough還有每個關係表. 理想我想返回的數據爲: 「貝克斯利格林威治」, 「倫敦金融 ...

  8. mysql havequerycache_如何开启MySQL的中的Query Cache缓存

    MySQL Query Cache是mysql中的一个功能,主要是用来缓存和查询相关数据,本文文详细介绍如何开启MySQL中的Query Cache,以及Query Cache中的一些参数. MySQ ...

  9. gmap mysql cachet,MySQL的缓存(Query Cache)

    1.MySQL Query Cache query cache是MySQL数据库用于缓存select语句以及语句的结果集.该缓存在技术细节上类似键值对存储,将select语句和语句的查询结果集做了一个 ...

最新文章

  1. url主机域名可以省略_网站迁移虚拟主机怎么样能不影响网站优化
  2. rabbitmq消费固定个数消息_SpringBoot+RabbitMQ (保证消息100%投递成功并被消费)
  3. 18春《c语言》在线作业3,18春福师《C++语言程序设计》在线作业二【参考答案】...
  4. boost::system::generic_category相关的测试程序
  5. 前端优化中使用base64的优缺点
  6. Java GUI 基础知识2 监听机制
  7. 一起学习C语言:C语言基本语法(五)
  8. 操作系统内核的一些事
  9. Jenkins 自动化部署上线
  10. [前端]网页网络分析及前端网络优化
  11. K8s系列之:Persistent Volume
  12. 项目管理的经验(4年项目管理经验)
  13. YOLO测试图片显示准确率值
  14. python条形码识别_使用Python和OpenCV在视频中实时监测条形码
  15. error: RPC failed; curl 56 GnuTLS recv error (-9): A TLS packet with unexpected length was received.
  16. WordPress 5文章编辑真难用 换回老版经典编辑器教程
  17. 与虎谋皮,饮鸩止渴,却有什么办法呢?
  18. 一名Java大佬跳槽之旅,离开京东,14面面试经验和收获
  19. 当攀藤 PM2.5 传感器遇上 RT-Thread
  20. 递归、分治算法刷题笔记

热门文章

  1. Redis Pipeline 原理及注意事项
  2. 数字图像处理--图像增强
  3. 我的书架——对一些书和如何买书的见解
  4. mysql主从同步可靠吗_说一下mysql主从同步
  5. Spring 系列框架的中文文档
  6. ZT关于AA制的由来
  7. 即使吃遍全世界的苦,也要让宝宝在六一成为小公主
  8. MySQL的关系模式集是什么_数据库中“关系模式”的定义是什么?
  9. 『Three.js』几个简单的入门动画(新手篇)
  10. Goland 包自动智能排序和分屏设置