Puma doesn't start the ruby on rails application immediately after puma started

28 views Asked by At

I have a ruby on rails application, use kubernetes & puma for deployment.

This is the command to run RoR app with puma. bundle exec puma -e production -C /home/app/htdocs/config/puma.rb --preload

The problem is, after puma server start, the RoR application doesn't start automatically. If the first request come in, then it try to compile and start application. It takes almost 2 minutes to run the app first time.

What I understand with --preload option with puma is, it is eager loading. so instead of waiting the first request, it start the RoR application immediately after the puma start. The current puma version is 5.7.6 The ruby 3.2.2, rails 6.1.7

This is the puma.rb in config folder.

directory "/home/app/htdocs"

environment "production"

stdout_redirect '/home/app/htdocs/log/puma.stderr.log', '/home/app/htdocs/log/puma.stdout.log'

workers 3

threads_count = 10

threads 1, 10

app_dir = File.expand_path("/home/app/htdocs", __FILE__)
shared_dir = "#{app_dir}/tmp"

bind 'tcp://0.0.0.0:9292'
bind "unix://#{shared_dir}/sockets/puma.socket"
port ENV.fetch("PORT") { 3000 }

stdout_redirect "#{app_dir}/log/puma.stdout.log", "#{app_dir}/log/puma.stderr.log", true

pidfile "#{shared_dir}/pids/puma.pid"

state_path "#{shared_dir}/pids/puma.state"

on_worker_boot do
    ActiveRecord::Base.establish_connection
end

activate_control_app

plugin :tmp_restart

I want the puma start the RoR application immediately after the puma start. Start means it's ready to get a request from the user. not the status showing listening 0.0.0.0:3000 Even it shows listening 0.0.0.0:3000, when first request come in, it starts to compile the assets and etc. It takes almost 2 minutes. I want this things runs automatically after the puma start and start the application. Therefore, I can see the app is really ready to get a request. and also I can check readinessProbe Path if the app is ready or not.

0

There are 0 answers