Giter VIP home page Giter VIP logo

Comments (6)

MSP-Greg avatar MSP-Greg commented on May 18, 2024

@jmuia

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

  1. Backlog connections that haven't been accepted
  2. Connections that have been accepted, but not completed the request
  3. Connections that are 'keep-alive', and may have additional requests

from puma.

jmuia avatar jmuia commented on May 18, 2024

Yep, exactly – the pattern is effectively:

  1. Receive SIGTERM
  2. Continue processing new connections and requests. Only fail (e.g. 503) healthcheck requests.
  3. 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:

  1. 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.
  2. 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.

dentarg avatar dentarg commented on May 18, 2024

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.

jmuia avatar jmuia commented on May 18, 2024

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.

dentarg avatar dentarg commented on May 18, 2024

Sounds cool… feel free to elaborate :)

from puma.

jmuia avatar jmuia commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.