PHP 或 MySQL 中的低优先级请求

发布于 2024-12-09 12:06:24 字数 120 浏览 5 评论 0原文

我有一个网站和一个包含 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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

吖咩 2024-12-16 12:06:24

我认为清理中最繁重的任务是可以使用 LOW_PRIORITY 的 DELETE 操作。

MySql 手册页中的 DELETE 语法:

从 tbl_name 中删除[LOW_PRIORITY] [快速] [忽略] ...

以及描述:

如果您指定LOW_PRIORITY,服务器将延迟 DELETE 的执行,直到没有其他客户端从表中读取数据为止。这仅影响仅使用表级锁定的存储引擎(例如 MyISAM、MEMORY 和 MERGE)。

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:

DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name ...

and the description:

If you specify LOW_PRIORITY, the server delays execution of the DELETE until no other clients are reading from the table. This affects only storage engines that use only table-level locking (such as MyISAM, MEMORY, and MERGE).

方圜几里 2024-12-16 12:06:24

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 ....

静水深流 2024-12-16 12:06:24

一种可能的解决方案是在从属复制服务器上复制旧数据。这样,重载就完全落在了从属箱上。一旦在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.

面犯桃花 2024-12-16 12:06:24

正如文档中所述,您可以添加LOW_PRIORITY 您的查询。因此,您的查询将变为:

$sql = "INSERT LOW_PRIORITY INTO #__bet_oddslog (id, team1, team2, league, sport, time, q1, q2)"; $sql .= " SELECT a.id, a.team1, a.team2, a.league, a.sport, a.time, AVG(b.q1) as q1, "; $sql .= " AVG(b.q2) as q2 FROM #__bet_details as a, #__bet_1x2_best as b WHERE time<'".date('Y-m-d H:i:s', strtotime("now"))."' AND a.id=b.bet_id GROUP BY b.bet_id";

As explained in the documentation, you could add LOW_PRIORITY to your query. So, your query would become:

$sql = "INSERT LOW_PRIORITY INTO #__bet_oddslog (id, team1, team2, league, sport, time, q1, q2)"; $sql .= " SELECT a.id, a.team1, a.team2, a.league, a.sport, a.time, AVG(b.q1) as q1, "; $sql .= " AVG(b.q2) as q2 FROM #__bet_details as a, #__bet_1x2_best as b WHERE time<'".date('Y-m-d H:i:s', strtotime("now"))."' AND a.id=b.bet_id GROUP BY b.bet_id";
无名指的心愿 2024-12-16 12:06:24

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文