优化基于mysql/PHP的网站|每秒 300 次
嘿, 目前我的 mysql 上有超过300+ qps。在相当重的 PHP 网站上,每天大约有 12000 个 UIP/没有 cron。我知道在不查看网站的情况下很难判断是否可以,但您认为这完全是矫枉过正吗? 你的经验是什么?如果我优化脚本,您认为我能够大幅降低 qps 吗?我的意思是,如果我达到 200 qps,那对我没有多大帮助。谢谢
Hey,
I currently have over 300+ qps on my mysql. There is roughly 12000 UIP a day / no cron on fairly heavy PHP websites. I know it's pretty hard to judge if is it ok without seeing the website but do you think that it is a total overkill?
What is your experience? If I optimize the scripts, do you think that I would be able to get substantially lower of qps? I mean if I get to 200 qps that won't help me much. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的网站可以在 Via C3 上运行,对您有好处!
这取决于它是否是
我们有一个 50-60.000 的网站,它在 Via C3 上运行(与那个垃圾服务器相比,你的烤面包机是一个数据中心),但 torrent 跟踪器使用了大约 50% 的 cpu,所以只有那个微小的一半cpu 可供网站使用,但无论如何,该网站似乎从未使用过其中的任何重要部分。
如果你想知道你是否要杀死你的服务器,或者你的网站是否被优化,以下内容的信息内容几乎为零:
但是以下内容非常重要:
您没有关注正确的指标...
Your website can run on a Via C3, good for you !
That depends if it's
We had a site with 50-60.000, and it ran on a Via C3 (your toaster is a datacenter compared to that crap server) but the torrent tracker used about 50% of the cpu, so only half of that tiny cpu was available to the website, which never seemed to use any significant fraction of it anyway.
If you want to know if you are going to kill your server, or if your website is optimizized, the following has close to zero information content :
But the following is extremely important :
You're not focusing on the right metric...
我认为你没有抓住重点。如果 300+ qps 太多,很大程度上取决于网站本身、每秒访问网站的用户数、并发运行的后台脚本等等。您应该能够测试和/或计算服务器的平均查询吞吐量,以了解 300+ qps 是否公平。顺便说一句,这取决于这些查询所要求的内容(几个字段,还是大量的二进制数据?)。
当然,如果您优化脚本和/或减少查询数量,您可以降低数据库的负载,但如果没有具体数据,我们无法正确回答您的问题。要将 300+ qps 负载降低到 200 qps 以下,您平均应该将总查询量降低至少 1/3。
I think you are missing the point here. If 300+ qps are too much heavily depends on the website itself, on the users per second that visit the website, that the background scripts that are concurrently running, and so on. You should be able to test and/or compute an average query throughput for your server, to understand if 300+ qps are fair or not. And, by the way, it depends on what these queries are asking for (a couple of fields, or large amount of binary data?).
Surely, if you optimize the scripts and/or reduce the number of queries, you can lower the load on the database, but without having specific data we cannot properly answer your question. To lower a 300+ qps load to under 200 qps, you should on average lower your total queries by at least 1/3rd.
优化脚本可以创造奇迹。我通过优化对服务器的调用方式,将脚本从之前 3 分钟缩短到之后 0.5 秒。当然,这是一种极端情况。如果可能的话,我将主要关注通过组合查询来最小化查询数量。也许可以对您的查询发挥创意,在每次点击中包含更多信息。
从 300 qps 提高到 200 qps 实际上是一个巨大的进步。您的服务器流量下降了 33%……这非常重要。
Optimizing a script can do wonders. I've taken scripts that took 3 minutes before to .5 seconds after simply by optimizing how the calls were made to the server. That is an extreme situation, of course. I would focus mainly on minimizing the number of queries by combining them if possible. Maybe get creative with your queries to include more information in each hit.
And going from 300 to 200 qps is actually a huge improvement. That's a 33% drop in traffic to your server... that's significant.
您不应该关注脚本,而应该关注服务器。
您并不是说这 300 多个查询是否导致了问题。如果你的服务器没有死,就没有理由降低数量。而如果你已经做了优化,那么你应该把重点放在服务器上。升级或购买更多服务器。
You should not focus on the script, focus on the server.
You are not saying if these 300+ querys are causing issues. If your server is not dead, no reason to lower the amount. And if you have already done optimization, you should focus on the server. Upgrade it or buy more servers.