Hi everyone! I'm migrating to the 1.2 service def...
# ask-for-help
p
Hi everyone! I'm migrating to the 1.2 service definition. That is a real improvement! But I have a question. Context: I'm working on distributing the load on our own kubernetes cluster better. We are building and containerizing bento's and then deploying them as a Deployment of pods on our cluster. Ideally, I would like to use a liveness probe so that the kubernetes Service automatically redirects the incoming requests to available pods. Ideally a pod fails the liveness probe if it is already processing its (max) concurrent requests. I cannot figure out how to do it though. Question: How can I configure a bento so that I can use an endpoint as a liveness probe that fails when it is processing more than the (max) concurrent requests? What I've tried: • Reducing the (max) concurrent requests. The /livez endpoint however never fails with 419 Too Many Requests. It sometimes takes longer to respond, but it is always successfull. • Try to access the
requests_in_progress
gauge, and use it to create a custom endpoint that fails when the value is above some threshold. I could not find a way to get that gauge because it is implemented in the middleware. Also any custom endpoint will have the POST method, and a liveness probe needs the GET method. Would love to have some suggestions on how to do this. Using BentoCloud is definitely on our roadmap, but not for now.
I've found a way to hack this into BentoML. I noticed that the
MaxConcurrencyMiddleware
has a class variable that excludes /livez from the concurrency checks. By removing that, the /livez now also fails when the service is already handling the max concurrent requests.
Copy code
from bentoml._internal.server.http.traffic import MaxConcurrencyMiddleware
MaxConcurrencyMiddleware.BYPASS_PATHS = frozenset({"/metrics", "/healthz", "/readyz"})  # no /livez here
💡 1
Edit: I really care about the readiness probe, because that determines if a pods is used by a service. Read "readiness probe" whenever I mention "liveness probe".
Now that I'm thinking about this for a bit longer, I actually thing that for my use case it makes sense to reject the probes but not the actual API. So that kubernetes won't use the pod as part of the service, but any accidental requests (e.g. made in between sequential calls to the probes endpoint) are still processed.