Skip to content
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

fork_worker automatic refork never triggers #2985

Open
slondr opened this issue Oct 5, 2022 · 8 comments
Open

fork_worker automatic refork never triggers #2985

slondr opened this issue Oct 5, 2022 · 8 comments

Comments

@slondr
Copy link

slondr commented Oct 5, 2022

Describe the bug

I have fork_worker enabled and was excited to deprecate my hand-spun automatic cluster restart with the built-in automatic refork functionality. However, after a couple months of using fork_worker live on production, I have never seen a refork actually occur without manual intervention. On a typical day, my application gets about 40,000 hits, and I have puma configured for a cluster size of 8 workers. I've tried setting the value of the fork_worker to as low as 150, which should mean a median of (40k requests divided by 8 workers divided by 1/150 for a time series of reforks per time quanta...) 21 reforks per minute! Yet, I never see the telltale drop in memory usage that I see when I manually send SIGURG to the cluster, never see any of the typical worker startup messages in the logs, etc.

Puma config:

environment 'production'
workers 8
threads 1, 7
fork_worker 150
plugin :tmp_restart
bind 'unix:///path/to/server.sock'
activate_control_app 'unix://path/to/socket.sock', auth_token: 'hello world'
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }

I launch puma via systemd, with the command RAILS_ENV=production bundle exec --keep-file-descriptors puma.

@MSP-Greg
Copy link
Member

MSP-Greg commented Oct 5, 2022

@slondr

I think more data might be helpful. I set fork_worker to 1000, and threw a wrk stream at a server, and it did restart, so I'm not sure what the issue is (yet). That was using master, not a release.

21 reforks per minute!

You might check that, I think the number should be more like a refork once every 43 minutes? 40k/(8*24) = 208 req per hour per worker...

@slondr
Copy link
Author

slondr commented Oct 5, 2022

Oh yeah, worth mentioning this is on puma 5.6.4 — though I don't see anything in the 5.6.5 release notes that I think would change this? I'll go test that + master with my application to see if it does.

@MSP-Greg
Copy link
Member

MSP-Greg commented Oct 5, 2022

@slondr

Most of my local test code is for master; I probably should have checked 5.6.5 or 5.6.4. I'll check a release sometime soon...

@slondr
Copy link
Author

slondr commented Oct 6, 2022

I was looking into this more today and checked my pumactl stats. It looks like workers 1 through 7 each have thousands of requests served but worker 0 only has 21. I'm guessing that's why I never see a refork. It's weird that this is so consistent though. I don't really know how Puma's scheduling system works for cluster mode but this definitely doesn't seem right to me.

@MSP-Greg
Copy link
Member

MSP-Greg commented Oct 6, 2022

Interesting. I'll see if I can repo.

@dentarg
Copy link
Member

dentarg commented Jul 3, 2023

@slondr still having this issue? are you able to reproduce it for us if so?

@rus-max
Copy link

rus-max commented Jan 24, 2024

This will enable automatic fork

# Auto-fork after the specified number of requests.
if (fork_requests = @options[:fork_worker].to_i) > 0
  @events.register(:ping!) do |w|
    fork_worker! if w.index == 0 &&
      w.last_status[:requests_count] >= fork_requests * (w.phase + 1)
  end
end

@rus-max
Copy link

rus-max commented Jan 30, 2024

Auto-fork after the specified number of requests always. Commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants