gpt4 book ai didi

mysql - 我应该牺牲 innodb_buffer_pool_size/RAM 来为 query_cache_size 腾出空间吗?

转载 作者:行者123 更新时间:2023-11-29 21:25:26 26 4
gpt4 key购买 nike

我有一个 16GB 的专用 Mysql 服务器数据库。我的 innodb_buffer_pool_size 设置为 11GB 左右,我正在系统中实现查询缓存,其大小为 80mb。我应该从哪里创建这个空间,innodb_buffer_pool_size还是RAM?

最佳答案

早在 2014 年 6 月,我就回答过 https://dba.stackexchange.com/questions/66774/why-query-cache-type-is-disabled-by-default-start-from-mysql-5-6/66796#66796

在那篇文章中,我讨论了 InnoDB 如何微观管理 InnoDB 缓冲池和查询缓存之间的变化。

不使用查询缓存

最简单的答案是禁用查询缓存,但有一个问题:您必须同时设置 query_cache_sizequery_cache_type为零(0)。

如果不设置query_cache_type到零(0),变更的微观管理仍然发生。 Paragraph 8 of the MySQL Documentation "Query Cache Configuration" 验证了这一点说

If query_cache_size is 0, you should also set query_cache_type variable to 0. In this case, the server does not acquire the query cache mutex at all, which means that the query cache cannot be enabled at runtime and there is reduced overhead in query execution.

使用查询缓存

如果您确实希望使用查询缓存,那么您需要研究您的数据。基本上,您需要知道结果的大小。然后您可以设置 query_cache_limitquery_cache_min_res_unit以容纳平均大小结果集以及最大大小结果集。

作为替代方案,您可以全局启用查询缓存,但在数据库 session 中禁用它的使用,如 Paragraph 9 中所述。 :

Setting the GLOBAL query_cache_type value determines query cache behavior for all clients that connect after the change is made. Individual clients can control cache behavior for their own connection by setting the SESSION query_cache_type value. For example, a client can disable use of the query cache for its own queries like this:

mysql> SET SESSION query_cache_type = OFF;

您的实际问题

查询缓存、InnoDB 缓冲池、每个连接线程(请参阅我的帖子 https://dba.stackexchange.com/questions/16969/how-costly-is-opening-and-closing-of-a-db-connection/16973#16973 )和操作系统都会争夺 RAM。

当仅查看查询缓存和 InnoDB 缓冲池时,您需要查看 MySQL 运行数天或数周后 InnoDB 缓冲池中有多少可用空间。

您可以运行此查询

SELECT variable_value / 64 free_mb
FROM information_schema.global_status
WHERE variable_name='Innodb_buffer_pool_pages_free';

这将告诉您可以将 InnoDB 缓冲池降低多少。然后,您可以将查询缓存增加该大小。如果此查询返回的值小于 1024,则可能不值得付出努力。您要么从 RAM 中获得额外的空间,要么只是禁用查询缓存。

关于mysql - 我应该牺牲 innodb_buffer_pool_size/RAM 来为 query_cache_size 腾出空间吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35533792/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com