advisory_rules_mysql_before80003.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. declare(strict_types=1);
  3. return [
  4. // Query cache
  5. [
  6. 'id' => 'Query cache disabled',
  7. 'name' => __('Query cache disabled'),
  8. 'formula' => 'query_cache_size',
  9. 'test' => 'value == 0 || query_cache_type == \'OFF\' || query_cache_type == \'0\'',
  10. 'issue' => __('The query cache is not enabled.'),
  11. 'recommendation' => __(
  12. 'The query cache is known to greatly improve performance if configured correctly. Enable it by'
  13. . ' setting {query_cache_size} to a 2 digit MiB value and setting {query_cache_type} to \'ON\'.'
  14. . ' <b>Note:</b> If you are using memcached, ignore this recommendation.'
  15. ),
  16. 'justification' => __('query_cache_size is set to 0 or query_cache_type is set to \'OFF\''),
  17. ],
  18. [
  19. 'id' => 'Query cache efficiency (%)',
  20. /* xgettext:no-php-format */
  21. 'name' => __('Query cache efficiency (%)'),
  22. 'precondition' => 'Com_select + Qcache_hits > 0 && !fired(\'Query cache disabled\')',
  23. 'formula' => 'Qcache_hits / (Com_select + Qcache_hits) * 100',
  24. 'test' => 'value < 20',
  25. 'issue' => __('Query cache not running efficiently, it has a low hit rate.'),
  26. 'recommendation' => __('Consider increasing {query_cache_limit}.'),
  27. 'justification' => __('The current query cache hit rate of %s%% is below 20%%'),
  28. 'justification_formula' => 'round(value,1)',
  29. ],
  30. [
  31. 'id' => 'Query Cache usage',
  32. 'name' => __('Query Cache usage'),
  33. 'precondition' => '!fired(\'Query cache disabled\')',
  34. 'formula' => '100 - Qcache_free_memory / query_cache_size * 100',
  35. 'test' => 'value < 80',
  36. /* xgettext:no-php-format */
  37. 'issue' => __('Less than 80% of the query cache is being utilized.'),
  38. 'recommendation' => __(
  39. 'This might be caused by {query_cache_limit} being too low.'
  40. . ' Flushing the query cache might help as well.'
  41. ),
  42. 'justification' => __(
  43. 'The current ratio of free query cache memory to total query'
  44. . ' cache size is %s%%. It should be above 80%%'
  45. ),
  46. 'justification_formula' => 'round(value,1)',
  47. ],
  48. [
  49. 'id' => 'Query cache fragmentation',
  50. 'name' => __('Query cache fragmentation'),
  51. 'precondition' => '!fired(\'Query cache disabled\')',
  52. 'formula' => 'Qcache_free_blocks / (Qcache_total_blocks / 2) * 100',
  53. 'test' => 'value > 20',
  54. 'issue' => __('The query cache is considerably fragmented.'),
  55. 'recommendation' => __(
  56. 'Severe fragmentation is likely to (further) increase Qcache_lowmem_prunes. This might be'
  57. . ' caused by many Query cache low memory prunes due to {query_cache_size} being too small. For a'
  58. . ' immediate but short lived fix you can flush the query cache (might lock the query cache for a'
  59. . ' long time). Carefully adjusting {query_cache_min_res_unit} to a lower value might help too,'
  60. . ' e.g. you can set it to the average size of your queries in the cache using this formula:'
  61. . ' (query_cache_size - qcache_free_memory) / qcache_queries_in_cache'
  62. ),
  63. 'justification' => __(
  64. 'The cache is currently fragmented by %s%% , with 100%% fragmentation meaning that the query'
  65. . ' cache is an alternating pattern of free and used blocks. This value should be below 20%%.'
  66. ),
  67. 'justification_formula' => 'round(value,1)',
  68. ],
  69. [
  70. 'id' => 'Query cache low memory prunes',
  71. 'name' => __('Query cache low memory prunes'),
  72. 'precondition' => 'Qcache_inserts > 0 && !fired(\'Query cache disabled\')',
  73. 'formula' => 'Qcache_lowmem_prunes / Qcache_inserts * 100',
  74. 'test' => 'value > 0.1',
  75. 'issue' => __('Cached queries are removed due to low query cache memory from the query cache.'),
  76. 'recommendation' => __(
  77. 'You might want to increase {query_cache_size}, however keep in mind that the overhead of'
  78. . ' maintaining the cache is likely to increase with its size, so do this in small increments'
  79. . ' and monitor the results.'
  80. ),
  81. 'justification' => __(
  82. 'The ratio of removed queries to inserted queries is %s%%. The lower this value is,'
  83. . ' the better (This rules firing limit: 0.1%%)'
  84. ),
  85. 'justification_formula' => 'round(value,1)',
  86. ],
  87. [
  88. 'id' => 'Query cache max size',
  89. 'name' => __('Query cache max size'),
  90. 'precondition' => '!fired(\'Query cache disabled\')',
  91. 'formula' => 'query_cache_size',
  92. 'test' => 'value > 1024 * 1024 * 128',
  93. 'issue' => __(
  94. 'The query cache size is above 128 MiB. Big query caches may cause significant'
  95. . ' overhead that is required to maintain the cache.'
  96. ),
  97. 'recommendation' => __(
  98. 'Depending on your environment, it might be performance increasing to reduce this value.'
  99. ),
  100. 'justification' => __('Current query cache size: %s'),
  101. 'justification_formula' => 'ADVISOR_formatByteDown(value, 2, 2)',
  102. ],
  103. [
  104. 'id' => 'Query cache min result size',
  105. 'name' => __('Query cache min result size'),
  106. 'precondition' => '!fired(\'Query cache disabled\')',
  107. 'formula' => 'query_cache_limit',
  108. 'test' => 'value == 1024*1024',
  109. 'issue' => __('The max size of the result set in the query cache is the default of 1 MiB.'),
  110. 'recommendation' => __(
  111. 'Changing {query_cache_limit} (usually by increasing) may increase efficiency. This variable'
  112. . ' determines the maximum size a query result may have to be inserted into the query cache.'
  113. . ' If there are many query results above 1 MiB that are well cacheable (many reads, little writes)'
  114. . ' then increasing {query_cache_limit} will increase efficiency. Whereas in the case of many query'
  115. . ' results being above 1 MiB that are not very well cacheable (often invalidated due to table'
  116. . ' updates) increasing {query_cache_limit} might reduce efficiency.'
  117. ),
  118. 'justification' => __('query_cache_limit is set to 1 MiB'),
  119. ],
  120. ];