I have a Hanami 1.3.3 application which should run with Puma as production webserver. I want to use puma in cluster mode and use preload_app properly. Now I'm struggling with the right Puma config. I know, that every child-process (worker) must have its own fresh DB-connection, redis-connection, etc.
My application uses multiple db-connections, redis, sidekiq. The main db is handled via hanami-model, the other db's are handled with pg-gem (connections are set up at class::initialize
) directly.
What's the right hanami-way to handle this?
Here's one approach:
workers 4
threads 1, 8
preload_app!
rackup DefaultRackup
port 2300
environment 'production'
on_worker_boot do
require_relative "config/environment"
Hanami.boot
end
Is that correct? For me it does not feel right.
Is following better?
# ...
on_worker_boot do
Hanami::Model.disconnect # but what happens to the opened db-connections of parent-process?
Hanami::Model.load!
# redis??
# sidekiq??
end
Thx
With the help of a fellow at hanami/chat, I ended up with following Puma config:
require_relative './environment'
workers 2
threads_count = 5
threads threads_count, threads_count
daemonize true
preload_app!
rackup DefaultRackup
port 2300
environment 'production'
on_worker_boot do
Hanami.boot
end
Here are infos which helped me to come to the conclusion:
puma and rails
definition of Hanami.boot
definition of Hanami.disconnect
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With