-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is the before_fork
block needed for Rails apps?
#36
Comments
I found a related issue while investigating this. When not using puma in worker mode, the In practice, that didn't seem to work: because barnes has no dependency on So, when this line is executed, Back to my original question – had this worked correctly, wouldn't adding the code to |
I'd love to know more as well, as I was looking into adding this, but docs have confused me... I am also not sure if I need to wrap everything inside |
I'm honestly not sure. I would have to test it. So I did...
This gave me an app with metrics: So I don't think it's required to use
If you add a Instead of having docs that say "do it this way with rails, do it this way without" another alternative is Barnes.start could be idempotent. We could store the instance of |
Also sorry on the delayed response. I was out for most of December with childcare duties. GitHub should have an OOO feature that allows someone to sub in to get my notifications. I only saw this thread due to the bump via @doutatsu |
I've heard many maintainers ask for that, definitely tough one. But I've heard Github is finally working on it Thanks for the detailed response. I've deployed myself, without adding before_fork and can confirm, it works as expected |
I went spelunking and here's what I found.
So in a vanilla Rails app like Richard used in his above example, where he only added However, as @chancancode points out, it's possible to get into a situation where that's not the case. If for whatever reason, Barnes is loaded first, then One way that can happen is if you Phew… so now we know how it is that Barnes can start even without those Back in point 3 (above) I mentioned that each call to On fork, only the forking thread continues to the child. No other threads from that process make it to the child. Meaning, none of the Barnes In the case of Puma-specific stats, that's actually exactly what we want. We want to collect and report those from the parent. In fact, But in the case of memory, GC, etc… we want those metrics from the child worker processes. And we can get them by using a different Puma hook: So this setup looks like: # Gemfile
gem 'barnes', require: false # Prevent Bundler from loading `Barnes` at the wrong time
# config/puma.rb
require 'barnes'
# Each time a new child worker process boots, start Barnes for it
on_worker_boot do
Barnes.start
end
# Once the app has fully booted, start Barnes for the parent process
on_booted do
Barnes.start
end There is still one hitch here - we're getting the Puma stats we want from the parent, but I'm not sure we want its GC, Memory, etc… metrics. Right? Or maybe we do? We certainly do if running Puma in Single mode. But in Clustered mode… I'm less sure. I can write up a change to the Barnes docs with new instructions based on single/clustered Puma. And I'm sure I can nudge some Herokai to get those pulled into Devcenter. But my real question is what about that parent process emitting the non-Puma metrics? Is that desirable? Expected? Let me know, and we'll take it from there. |
# What it does I noticed that we weren't seeing any Ruby metrics in Heroku, despite having followed the directions a while back to set them up: ![Screenshot 2024-04-08 at 8 34 44 PM](https://github.com/chicago-tool-library/circulate/assets/3331/193bb076-e03e-45a0-b973-3ad70f069bdb) I am interested in these metrics to help figure out how to tune the app's concurrency and ideally address the memory errors we've been seeing. The app was setup according the [the Heroku instructions](https://devcenter.heroku.com/articles/language-runtime-metrics-ruby), but evidently [they are out of date](heroku/barnes#36 (comment)) and having an explicit require of `barnes` in `config/puma.rb` loads the library before Rails, causing the Barnes server to not start properly and therefore not report metrics.
The Heroku docs seem to suggest yes, but the README of the gem seems to imply that it is only needed for non-Rails apps.
The text was updated successfully, but these errors were encountered: