简体   繁体   English

在Rails中ActiveRecord :: Base。Establishment_connection有什么影响?

[英]What is the impact of ActiveRecord::Base.establish_connection in Rails?

I use Rails in production with Passenger. 我在旅客中使用Rails。 The app is able to handle multiple requests in parallel 该应用程序能够并行处理多个请求

In a migration helper code I establish a connection to an old database to copy data to the new one. 在迁移助手代码中,我建立了到旧数据库的连接,以将数据复制到新数据库。

As the connection is made by calling ActiveRecord::Base.establish_connection , does it affect only the current request or may it have some side effects ? 由于通过调用ActiveRecord::Base.establish_connection ,因此它仅影响当前请求,还是可能会有一些副作用?

Just after getting the data I restore the connection to the Rails env. 刚获取数据后,我就恢复了与Rails env的连接。

(My guess is that Passenger spawns multiple processes therefore this should not be a problem) (我的猜测是乘客产生了多个过程,因此这应该不是问题)

On a normal pasenger deploy this is not a problem at all. 在普通的Pasenger部署上,这根本不是问题。 It indeed just spawns multiple processes. 实际上,它只是产生了多个进程。 They do not share any state, so there cannot be any side effects. 它们不共享任何状态,因此不会有任何副作用。

If you would use passenger enterprise in a multithreaded setup this could be some concern. 如果要在多线程设置中使用客运企业,则可能要担心一些。 But establish_connection, to my knowledge, takes care of grabing a new connection from the connection pool and saves it into Thread.current hash for this Class. 但是据我所知,Establishment_connection负责从连接池中获取一个新连接,并将其保存到该Class的Thread.current哈希中。 So there should be also no side effects, like having the connection globally switched for other requests. 因此也应该没有副作用,例如将连接全局切换为其他请求。

Take a further look at Concurrency and Database Connections with ActiveRecord 进一步了解ActiveRecord的并发和数据库连接

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

相关问题 在AWS上与Postgresql的ActiveRecord :: Base。Establishment_connection - ActiveRecord::Base.establish_connection with postgresql on AWS 红宝石死于“ ActiveRecord :: Base。Establishment_connection” - ruby just dies on “ActiveRecord::Base.establish_connection” ActiveRecord :: Base。Establishment_connection连接到错误的数据库 - ActiveRecord::Base.establish_connection connects to wrong database 不同模型中的ActiveRecord :: Base。Establishment_connection是否使用相同的连接池? - Does ActiveRecord::Base.establish_connection in different models use same connection pool? Mongoid中的ActiveRecord#Establishment_connection等效项是什么? - what is the equivalent of ActiveRecord#establish_connection in Mongoid? Rails:没有 ActiveRecord::Base 的连接池 - Rails: No connection pool for ActiveRecord::Base Rails无法使用ActiveRecord :: establish_connection连接到数据库 - Rails cant connect to database with ActiveRecord::establish_connection 更改 rails secret_key_base 对生产有什么影响? - What is the impact of changing rails secret_key_base on production? 如何从Rails中的ActiveRecord :: Base.connection.execute中捕获错误? - How to capture errors from ActiveRecord::Base.connection.execute in Rails? Rails ActiveRecord::Base.connection 在外部文件上执行 - Rails ActiveRecord::Base.connection to execute upon an external file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM