如何在heroku上查找当前的连接池大小 [英] How to find current connection pool size on heroku
问题描述
DATABASE_URL
配置中设置连接池的大小,但似乎无法找出默认情况下当前正在使用的连接数量。 两个主要问题:
$ b $ 1)如何找到heroku使用的连接池的大小?
2)是否有任何理由要求连接池的大小大于1?我的理解是,rails一次只能执行1个请求,因此我应该可以看到一个数据库连接应该是所需要的。
heroku run rails c
,然后运行: ActiveRecord :: Base.connection_pool.instance_eval {@size}
一些网络服务器(如Puma)是多线程的,因此数据库池大小很重要。你也可以运行一个多线程工作者,比如Sidekiq,它也会受到池大小的影响。
请注意,Heroku会忽略你的database.yml文件。要设置池大小,您可以在您的heroku应用程序的配置中将?pool = 25
附加到DATABASE_URL中。
We have a rails 3.2(.11) app with many dynos running on the heroku bamboo stack, connecting to a MySQL RDS server. There seem to be some issues with our current database connections, so we are trying to debug exactly how many connections each dyno is spinning up. I know I can set the size of a connection pool in the DATABASE_URL
config on heroku, but can't seem to find out how many connections are currently being used by default.
Two main questions:
1) How can I find the size of the connection pool used by heroku?
2) Is there any reason why a dyno would need a connection pool size greater than 1? My understanding is that rails can only execute 1 request at a time so one database connection should be all that is needed as far as I can see.
To check the pool size, start a heroku console heroku run rails c
, and run:
ActiveRecord::Base.connection_pool.instance_eval { @size }
Some webservers such as Puma are multithreaded, so the DB pool size matters. You can also run a multi-threaded worker such as Sidekiq, which also will be affected by the pool size.
Note that Heroku will ignore your database.yml file. To set the pool size you can append ?pool=25
to the DATABASE_URL in your heroku app's configuation.
这篇关于如何在heroku上查找当前的连接池大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!