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性能。