'best practices' 在高并发 Rails 系统中处理暂时性数据库错误的方法是什么?
What are 'best practices' for dealing with transient database errors in a highly concurrent Rails system?
在研究死锁问题时,我发现了以下 post:
https://rails.lighthouseapp.com/projects/8994/tickets/6596
大意如下:
MySQL 文档说:
Deadlocks are a classic problem in transactional databases, but they are not dangerous unless they are so frequent that you cannot run certain transactions at all. Normally, you must write your applications so that they are always prepared to re-issue a transaction if it gets rolled back because of a deadlock.
因此调试暂时性死锁是一种反模式,因为 MySQL 说它们是可以的并且是不可避免的。
因此,Rails应该给我们提供一个方法,因为它:
makes the assumption that there is the "best" way to do things, and it's designed to encourage that way
但是 Rails 没有给我们提供方法,所以我们正在使用一个 hacky DIY 东西。
那么,如果所有这些都是真的,Rails 解决方案在哪里?
注意:这个项目不活跃,但看起来很简单,可以作为一个解决方案。为什么 Rails 没有这样的东西?
https://github.com/qertoip/transaction_retry
对我来说,修复是一个更好的索引。
有问题的更新是在带有连接的查询中,现有索引不足以让 MySQL 有效地连接和搜索。
即使在具有不合理并发负载的测试中,添加适当的索引也能完全消除死锁问题。
在研究死锁问题时,我发现了以下 post:
https://rails.lighthouseapp.com/projects/8994/tickets/6596
大意如下:
MySQL 文档说:
Deadlocks are a classic problem in transactional databases, but they are not dangerous unless they are so frequent that you cannot run certain transactions at all. Normally, you must write your applications so that they are always prepared to re-issue a transaction if it gets rolled back because of a deadlock.
因此调试暂时性死锁是一种反模式,因为 MySQL 说它们是可以的并且是不可避免的。
因此,Rails应该给我们提供一个方法,因为它:
makes the assumption that there is the "best" way to do things, and it's designed to encourage that way
但是 Rails 没有给我们提供方法,所以我们正在使用一个 hacky DIY 东西。
那么,如果所有这些都是真的,Rails 解决方案在哪里?
注意:这个项目不活跃,但看起来很简单,可以作为一个解决方案。为什么 Rails 没有这样的东西? https://github.com/qertoip/transaction_retry
对我来说,修复是一个更好的索引。
有问题的更新是在带有连接的查询中,现有索引不足以让 MySQL 有效地连接和搜索。
即使在具有不合理并发负载的测试中,添加适当的索引也能完全消除死锁问题。