PHP 或 MySQL 中的低优先级请求
我有一个网站和一个包含 500 万行的数据库,它运行得非常顺利。但是,我每小时运行一次清理cronjob,将旧数据放入“日志”表并删除旧数据,此时服务器响应非常慢。是否可以通过 PHP 或 MySQL 给予该作业较低的优先级?
I Have a site and a database with 5 million rows, it's working like a charm. However, I'm running a cleanup cronjob each hour, to put the old data to a 'log' table and delete the old data, and in this time the server response is very slow. Is it possible to give that job a lower priority via PHP or MySQL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为清理中最繁重的任务是可以使用 LOW_PRIORITY 的 DELETE 操作。
MySql 手册页中的 DELETE 语法:
以及描述:
I think the heaviest task in your cleanup is the DELETE operation for which you can use LOW_PRIORITY.
DELETE syntax from MySql manual page:
and the description:
MYSQL 中有一个低优先级更新的东西 - 它在这里记录 -> http://dev.mysql.com /doc/refman/5.5/en/server-options.html#option_mysqld_low-priority-updates
** 仅适用于 MyISAM、MEMORY、MERGE 存储引擎 ....
There is such a thing in MYSQL as low-priority-updates - its documented here -> http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_low-priority-updates
** only works for MyISAM, MEMORY, MERGE storage engines ....
一种可能的解决方案是在从属复制服务器上复制旧数据。这样,重载就完全落在了从属箱上。一旦在slave上复制完成,你就可以在master上删除。
One possible solution would be to do the copying of old data on a slaved replication server. That way, the heavy load is entirely on that slave box. Once the copying is finished on slave, you could delete on master.
正如文档中所述,您可以添加
LOW_PRIORITY
您的查询。因此,您的查询将变为:As explained in the documentation, you could add
LOW_PRIORITY
to your query. So, your query would become:MYSQL 中的低优先级请求之一是 INSERT DELAYED 。但它只适用于 INSERT,不适用于 UPDATE 或 DELETE。
编辑:我只知道删除也可以延迟!
One of the low priority requests in MYSQL is INSERT DELAYED. But it only works on INSERT, not UPDATE or DELETE.
EDIT: I just knew that DELETE also can be delayed!