如何增加ActiveRecord中的最大池大小?

niknxzdl  于 2022-10-15  发布在  Ruby
关注(0)|答案(2)|浏览(169)

我得到的错误是:

Error "ActiveRecord::ConnectionTimeoutError - could not obtain a database connection within 5 seconds.  The max pool size is currently 5; consider increasing it."

如何增加最大池大小?


# DB CONNECTION

DB_CONN = ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => DB_FILE)
mrfwxfqh

mrfwxfqh1#

可以指定静态连接数,但是...


# config/database.yml

default: &default
  adapter: postgresql
  pool: 99 %>

。。但是,如果所需的连接数与线程数成比例,则可能需要动态指定它。在本例中,每个线程有两个连接。

pool: <%= 2 * (ENV.fetch("RAILS_MAX_THREADS") { 5 }) %>
mzaanser

mzaanser2#

config/database.yml
pool: 8 (default is 5)

阅读more

相关问题