我的应用程序是数据库密集型的,因此我非常努力地确保应用程序和 MySQL 数据库尽可能高效地协同工作。
目前,我正在调整 MySQL 查询缓存,使其符合服务器上运行的查询的特征。
query_cache_size
是可以存储在缓存中的最大数据量,query_cache_limit
是缓存中单个结果集的最大大小。
我当前的MySQL查询缓存配置如下:
query_cache_size=128M
query_cache_limit=1M
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
给出以下调整提示:
[OK] Query cache efficiency: 31.3% (39K cached / 125K selects)
[!!] Query cache prunes per day: 2300654
Variables to adjust:
query_cache_size (> 128M)
两个调整脚本都建议我应该提高query_cache_size
。然而,增加query_cache size
超过 128M 可能会降低性能mysqltuner.pl
(see http://mysqltuner.pl/ http://mysqltuner.pl/).
你会如何解决这个问题?你会增加query_cache_size吗?mysqltuner.pl
的警告或尝试以某种方式调整查询逻辑?大部分数据访问由 Hibernate 处理,但应用程序中也使用了大量手工编码的 SQL。