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
Stop checking for Process.pid and trust the fork
decorators
#41850
Conversation
(I assume you're proposing removing all the I guess I don't feel super strongly about it, but given the failure mode is a possible segfault, I am still a bit cautious -- the pre- I feel like I've had this thought before somewhere, but it apparently wasn't on the previous PR: instead of checking the pid, we could use a sacrificial no-op thread: if Or, yeah, we just remove it, and trust it's probably fine. I am still feeling nervous that it'll eventually bite someone -- probably on a more medium-sized app: enough traffic to give it a lot of chances to fail, but still a low enough amount that they can afford a Alternatively: add a config option, so that people with very-high-traffic sites can avoid the expensive-at-scale check -- and thereby opt in to a nastier debugging process if things do go wrong -- while leaving most people to spend a few extra syscalls to be definitively safe. I really don't know which way I think we should go on this, sorry. 😕 All three of the above get the |
`Process.pid` is not cached on Linux and is surprisingly expensive. These checks are in hotspots, the the cost is not negligible. In rails#37296 (comment) we established that it's pretty much impossible to bypass `Process.fork` / `Kernel#fork`. We still added the checks to protect against user defined `after_fork` hooks that would use the connection. But I don't think the cost is worth this extra safety.
dea923a
to
930efcd
Compare
Absolutely, sometimes my editor plays tricks on me... It's corrected now. It's mostly the one in
You might have missed it because GitHub paginated the comments: #37296 (comment)
Hum, I'll have to bench, but not sure if
Yes, we never fork in the middle of a request. We fork after preloading the app, and that's it.
So of course it varies from request to request based on how many connection checkouts you do. In most case it hover between Part of the problem might be that our app likely goes through connection checkout a bit more than a regular one because of our sharding, as well our caching layer that need to check for open transactions. But in general Active Record calls There's probably some refactoring to do to do less connection checkouts, but I think making it a bit faster would be good. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
@casperisfine Is this still something you want to work on? Can you identify any blockers? |
It's not as important as previously thought. Turns out Ruby causes sampling profilers to have a bias toward methods implemented in C (some context here: tmm1/stackprof#150). But |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Process.pid
is not cached on Linux and is surprisingly expensive. These checks are in hotspots, so the cost is not negligible.In #37296 (comment) we established that it's pretty much impossible to bypass
Process.fork
/Kernel#fork
.We still added the checks to protect against user defined
after_fork
hooks that would use the connection. But I don't think the cost is worth this extra safety.At the same time I'll try to push for Ruby to expose a native
after_fork
callback, but of course even if it works it might take a while before Rails can use it.@matthewd What do you think? Do you still feel strongly about this extra check?