Comments (6)
Haven't had time to think about this, but one question:
it's a common pattern to fail healthcheck requests for N seconds prior to draining existing connections and closing the listener.
So, you want Puma to 'wait N seconds, then drain existing connections'? Is that delay needed? Also, often 'drain' used, but there are three types. Also, see docs for Puma::DSL#drain_on_shutdown
- Backlog connections that haven't been accepted
- Connections that have been accepted, but not completed the request
- Connections that are 'keep-alive', and may have additional requests
from puma.
Yep, exactly – the pattern is effectively:
- Receive SIGTERM
- Continue processing new connections and requests. Only fail (e.g. 503) healthcheck requests.
- After N seconds, close the listener and process any pending requests (let's connections that have been accepted).
The delay is needed to allow clients and load balancers to detect that this server shouldn't receive any more traffic.
DSL#drain_on_shutdown
paired with checking Server#shutting_down?
in the healthcheck handler (allowing us to fail healthcheck requests) does seem promising. I see two downsides:
- For a low traffic server, the accept queue could be empty causing us to exit the accept loop. There could be a race condition with an incoming request.
- A server will always receive healthcheck requests, which could mean that with
drain_on_shutdown
we never exit the accept loop (seems unlikely)
from puma.
Hmm, isn't it better to instruct your load balancers to take out the server of the rotation when you want to restart it? (Not sure what you're using but HAProxy seems to have a drain
mode for this)
from puma.
Hmm, isn't it better to instruct your load balancers to take out the server of the rotation when you want to restart it?
This would be a good solution! Unfortunately, in this environment it's not an option. We're using client-side load balancers and real-time health information comes from client-side health check requests.
from puma.
Sounds cool… feel free to elaborate :)
from puma.
After some thinking, I could see another viable alternative: add a min/max drain time to Puma::DSL#drain_on_shutdown
(in other words, continue the accept() loop until we've waited the minimum drain time and there are either no more connections or we've spent the max drain time).
Sounds cool… feel free to elaborate :)
Of course! We're using Envoy as a sidecar mesh proxy in this environment – it proxies requests on both the client and server hosts. In our current configuration, health checks are an important part of the "draining" process. Please let me know if there are other specifics you're interested.
from puma.
Related Issues (20)
- Systemd watchdog kills puma during hot restart. HOT 4
- NoMethodError: undefined method `release' for Rack:Module error at "rails s" initialization time HOT 5
- Staging environment, request.ENV['HTTP_HOST'] displays 2 urls when it should be a single url HOT 1
- HttpParserError raised when body (chunk) exceeds 4096 bytes does not end with "\r\n" HOT 4
- undefined method `log_writer' for #<Puma::Launcher on usin plugin :solid_queue in puma HOT 1
- `TestWorkerGemIndependence#test_changing_nio4r_version_during_phased_restart` fails in head builds
- Option to restrict cipher suites for TLS1.3
- Requests with a caret (`<` or `>`) in a query parameter raise a `Puma::HttpParserError` HOT 10
- Random freezes in dev mode
- Puma doesn't start the Rails app after run
- "undefined method `on_booted` for nil:NilClass" on "pumactl start" HOT 2
- Large number of workers are booting too long or not booting the first time HOT 4
- What options are not available when using `rails s`? HOT 1
- MAX_CHUNK_HEADER_SIZE = 4096 is too small for podman HOT 6
- Puma config get evaluated twice with pumactl HOT 3
- question about puma architecture
- Windows - Puma compiled without ssl support HOT 7
- Puma plugin in my Rails app
- Support for on-demand starting
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from puma.