0
我们在Heroku上使用了Sidekiq的Rails应用程序,并且数据库连接不足。为什么我们在Heroku上没有数据库连接?
ActiveRecord::ConnectionTimeoutError: could not obtain a database
connection within 5.000 seconds (waited 5.000 seconds)
Heroku的东西:
数据库计划:Standard0(120个连接)
网络DYNOS:2标准-2X
工人DYNOS:1标准-2X
heroku配置:
MAX_THREADS: 5
(DB_POOL not set)
(WEB_CONCURRENCY not set)
Procfile:
web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq
database.yml中:
...
production:
url: <%= ENV["DATABASE_URL"] %>
pool: <%= ENV["DB_POOL"] || ENV['MAX_THREADS'] || 5 %>
puma.rb:
# https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#adding-puma-to-your-application
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 2)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end
sidekiq.yml:
---
:concurrency: 25
:queues:
- [default]
我们还有几个rake任务每隔10分钟就会触发一次,并在一两秒内完成。
当我们在sidekiq中做了很多消息处理时,问题似乎就会发生。我们做这样的事情:
- 获取文章的标题从第三方Web服务
- 插入每个标题到一个数据库中的单个事务
- 为每一个标题(worker.perform_async)在sidekiq消息 内
- 处理每封邮件,打一个端点,以获得身体和更新体(可以0.5 - 3秒)
虽然4号发生的事情,我们看到的连接问题。
我的理解是我们的方式低于上述配置的连接限制,但我们是否做了不正确的事情?是否只是消耗游泳池?任何帮助将是伟大的,谢谢。
来源:
- https://devcenter.heroku.com/articles/concurrency-and-database-connections
- https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server
- https://github.com/mperham/sidekiq/wiki/Advanced-Options