MySQL 中处理高负载表的常见做法

发布于 2024-08-06 23:50:43 字数 298 浏览 2 评论 0原文

我在 MySQL 5 (InnoDB) 中有一个表用作守护进程处理队列,因此它的访问非常频繁。通常每天插入大约 250,000 条记录。当我选择要处理的记录时,使用 FOR UPDATE 查询读取它们以消除竞争条件(一切都是基于事务的)。

现在我正在开发一个“队列存档”,我无意中遇到了严重的死锁问题。我需要在处理(实时)表时从表中删除“已执行”记录,但如果我这样做,表偶尔会死锁(每天两到三次)。

我虽然倾向于延迟删除(在低负载时间每天一次),但这并不能消除问题,只会让它变得不那么明显。

MySQL 中处理高负载表有常见做法吗?

I have a table in MySQL 5 (InnoDB) that is used as a daemon Processing Queue, thus it is being accessed very often. It is typical to have around 250 000 records inserted per day. When I select records to be processed, they are read using a FOR UPDATE query to eliminate race conditions (everything is Transaction Based).

Now I am developing a "queue archive" and I have stumbled into a serious dead-lock problem. I need to delete "executed" records from the table as they are being processed (live), yet the table dead-locks every once in a while if I do so (two-three times per day at).

I though of moving towards delayed deletion (once per day at low load times) but this will not eliminate the problem only make it less obvious.

Is there a common-practice in dealing with high-load tables in MySQL?

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

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

发布评论

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

评论(1

躲猫猫 2024-08-13 23:50:43

InnoDB 锁定它检查的所有行,而不仅仅是那些请求的行。

有关更多详细信息,请参阅此问题

您需要创建一个与您的搜索条件完全匹配的索引,以摆脱不必要的锁定,并确保它被使用。

不幸的是,MySQL 中的DML 查询不接受提示。

InnoDB locks all rows it examines, not only those requested.

See this question for more details.

You need to create an index that would exactly match your search condition to get rid of unnecessary locks, and make sure it is used.

Unfortunately, DML queries in MySQL do not accept hints.

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