I want to monitor the boot time for various rails apps so I can tweak load-balancer health-checks and Kubernetes readiness probes, and know when a change created a large increase in boot time.
What’s the best way to achieve this?
Currently I made a change to bin/rails
to create a global variable at the beginning of that script.
#!/usr/bin/env ruby
RAIL_START_TIME = (Time.now.to_f * 1000).to_i
I also made some changes to the end of config/puma.rb
to calculate the boot time.
puma_ready_at = (Time.now.to_f * 1000).to_i
app_boot_time = puma_ready_at - RAIL_START_TIME
Rails.logger.info "Puma booted in #{app_boot_time} ms"
Those changes result in the following output in my log, which I think is close enough, and I can later extract and monitor over time but is there a better way to achieve this?
bundle exec rails server -p 3000
=> Booting Puma
=> Rails 7.1.2 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma booted in 12697 ms
Puma starting in single mode...
* Puma version: 6.4.0 (ruby 3.2.2-p53) ("The Eagle of Durango")
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 99906
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000
Use Ctrl-C to stop