简体   繁体   English

Ruby on Rails 应用程序中的 PgBouncer 和咨询锁

[英]PgBouncer in Ruby on Rails app and advisory locks

I've been using advisory locks extensively in multiple apps and now, am looking into introducing a connection pooler due to the huge number of DB connections.我一直在多个应用程序中广泛使用咨询锁,现在,由于数据库连接数量庞大,我正在考虑引入一个连接池。 I'm considering pgbouncer with transaction pool_mode and from the initial research, not everything is clear.我正在考虑将 pgbouncer 与事务 pool_mode 一起使用,并且从最初的研究来看,并非一切都清楚。

So advisory locks are session-based features, which won't work with a transaction pool mode.所以咨询锁是基于会话的特性,它不适用于事务池模式。 This is also a common source of the issues with running migrations in Ruby on Rails and one of the reasons why in Rails 6 it's possible to disable advisory locks to solve the issue with migrations.这也是在 Ruby on Rails 中运行迁移问题的常见来源,也是为什么在 Rails 6 中可以禁用咨询锁来解决迁移问题的原因之一。 On the other hand, there are transaction-level locks, which might work just fine with the transaction pool mode.另一方面,还有事务级锁,它可能在事务池模式下工作得很好。 Yet, this doesn't seem to go along with the general recommendations that you shouldn't use advisory locks with pgbouncer or even with the fact that in Rails, it's either a session-based advisory lock or not at all for migrations (although this decision could be made due to the fact that it's possible to disable transaction per migration), so it's a bit confusing.然而,这似乎不符合一般建议,即您不应该对 pgbouncer 使用咨询锁,甚至在 Rails 中,它要么是基于会话的咨询锁,要么根本不用于迁移(尽管这由于可以禁用每次迁移的事务,因此可以做出决定,因此有点令人困惑。

So I was wondering if transaction-level advisory locks will just work with pgbouncer or should I looks for some alternative?所以我想知道事务级咨询锁是否只适用于 pgbouncer 还是我应该寻找一些替代方案?

Thanks in advance for the answer.提前感谢您的回答。

Anything that doesn't survive the end of a transaction is no problem to use in transaction pooling mode of pgBouncer.任何在交易结束后无法存活的东西都可以在 pgBouncer 的交易池模式中使用。

So I see no problem with using transaction-level advisory locks.所以我认为使用事务级咨询锁没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM