MySQL查询与静态缓存性能对比 [英] Performance comparison between MySQL queries and static caching

查看:76
本文介绍了MySQL查询与静态缓存性能对比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划为我的网站实施一个缓存系统,该系统可以接收到不错的流量.有时 MySQL 服务器超载,这就是为什么我将 MySQL 结果缓存为静态(缓存)文件.这是我所做的:

I am planning to implement a caching system for my site that receives decent traffic. Sometimes MySQL server is overloaded that's why I'm caching MySQL results in static (cached) files. Here is what I do:

  1. 首先,我检查缓存文件(特定于页面)
  2. 如果它不存在,我查询数据库并序列化结果
  3. 我将结果写入缓存文件
  4. 当文件存在时,我使用 file_get_contents() 函数获取内容并反序列化数据
  1. First of all, I check for cache file (page specific)
  2. If it doesn't exist, I query database and I serialize the results
  3. I write results to the cache file
  4. When file exists, I get content with file_get_contents() function and unserialize the data

现在我的问题是,我的缓存策略会提高性能还是应该继续对每个请求使用数据库查询?

Now my question is, will my caching strategy improve performance or should I keep using database queries for every request?

推荐答案

有很多方法可以加速您的网站并降低数据库负载.这些比尝试制作手动缓存文件要好得多.以下是其中一些:

There are many ways to speed up your web site and to lower database load. Those are much better then trying to make manual cache files. Here are some of them:

  1. 优化数据库设置(这么多有趣的时刻!)
  2. 使用内存表
  3. 将 CPU\RAM 添加到 Web 服务器
  4. 使用 nginx 或 varnish 等缓存服务器(它们可以将整个静态页面缓存)
  5. 在 PHP 中使用特殊的数据缓存 - 如 memcached
  6. 使用套接字代替 TCP\IP 连接到数据库
  7. 使用 mysql-nd 代替 mysql

这里是您确切问题的答案:PHP - 在 txt 文件中缓存 MYSQL 查询是个好习惯吗?

And here is the answer to your exact question: PHP - Is it good practice to cache MYSQL queries in a txt file?

这篇关于MySQL查询与静态缓存性能对比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆