自动删除mySQL查询缓存?

发布于 2024-12-12 07:12:04 字数 1238 浏览 0 评论 0原文

我是一款网页游戏的所有者,该游戏拥有高流量数据库和大量查询。 我现在正在优化 mySQL,像 mysqltuner 这样的工具一直说我的查询缓存内存不足。

+-------------------------+-----------+  
| Variable_name           | Value     |  
+-------------------------+-----------+  
| Qcache_free_blocks      | 218       |  
| Qcache_free_memory      | 109155712 |  
| Qcache_hits             | 60955602  |  
| Qcache_inserts          | 38923475  |  
| Qcache_lowmem_prunes    | 100051    |  
| Qcache_not_cached       | 10858099  |  
| Qcache_queries_in_cache | 19384     |  
| Qcache_total_blocks     | 39134     |  
+-------------------------+-----------+  

这是服务器运行大约 1.5 天的结果。 理想情况下,lowmem_prunes 当然是 0,但是有很多查询是基于用户的。就像,

SELECT username FROM users WHERE id='1';  
SELECT username FROM users WHERE id='12';
SELECT username FROM users WHERE id='12453';
SELECT username FROM users WHERE id='122348';

由于我每天有大约 3000 个不同的用户登录,你的内存中将会有很多这样的查询。

我知道“按需”规则,但我避免使用它,因为我们有很多查询,我不想全部检查。

增加内存也不是解决办法,因为我们有太多查询。

然后我想出了一个想法,让 cronjob 在 lowmem_prunes 为零时自动重置查询缓存。 (可能每小时一次)

最好的选择是什么?
1.每小时自动重置一次查询缓存
2. 购买更多 RAM 并增加缓存,例如 1GB(这有其缺点......我宁愿不这样做)
3. 指定每个查询哪些应该保存在缓存中,哪些不应该保存在缓存中。
4.保持这样就可以了。

I'm the owner of a web-game with a high-traffic database with a lot of queries.
I'm now optimizing the mySQL and tools like mysqltuner keep saying that I have insufficient query cache memory.

+-------------------------+-----------+  
| Variable_name           | Value     |  
+-------------------------+-----------+  
| Qcache_free_blocks      | 218       |  
| Qcache_free_memory      | 109155712 |  
| Qcache_hits             | 60955602  |  
| Qcache_inserts          | 38923475  |  
| Qcache_lowmem_prunes    | 100051    |  
| Qcache_not_cached       | 10858099  |  
| Qcache_queries_in_cache | 19384     |  
| Qcache_total_blocks     | 39134     |  
+-------------------------+-----------+  

That's from about 1,5 day of running the server.
Ideally the lowmem_prunes would be 0 of course, but there are very much queries which are user-based. Like,

SELECT username FROM users WHERE id='1';  
SELECT username FROM users WHERE id='12';
SELECT username FROM users WHERE id='12453';
SELECT username FROM users WHERE id='122348';

As I have about 3000 different users a day logging in you will have many queries like this in the memory.

I know about the ON DEMAND rule, but I'm avoiding it because we have a lot of queries which I don't want to check all over.

Increasing the memory wouldn't be a fix either since we're having so many queries.

Then I came up with the idea to make a cronjob to automatically RESET the query cache when the lowmem_prunes is zero. (which will probably be once an hour)

What's the best option?
1. Automatically reset the query cache once an hour
2. Buy more RAM and increase the cache with 1GB for example (which has it's downsides... I rather not do that)
3. Specify per query which should be kept in cache in which not.
4. Just keep it like this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文