Reputation: 9825
We have an app that handles request which could take several minutes to return a response. Does it make sense to put this app in a pod and replicate many times in the same node so we can handle each request on a new thread (Considering nodejs is single threaded)?
Upvotes: 2
Views: 351
Reputation: 1711
The use-case here is quite a bit, unsteady. As per your say your application is a single threaded one, and you want to increase the pod as soon as a new request is fired only if the previous pod is busy or has a lock, in simplest terms a new pod to come with a new request if the previous pod is busy.
Kubernetes is an Orchestrator for containers and deploying a monolithic application on kubernetes not just bring down all the tremendous that kubernetes can do but also bring lots of overhead with Deployment and automation issues.
Also, the nice thing when you break away from a monolith (= single thread) into a (micro) service oriented architecture you can have an isolated event loop for each service. Because every Node process would be running isolated inside a container!
I would advise you to consider your architectural design of application, break them into multi threaded and then revisit kubernetes.
However quoting the same https://www.dataversity.net/use-kubernetes-deploy-monolithic-apps/# A Linux shell is a Linux shell is a Linux shell. You can make it work, and the following can be a way ahead.
Strategic Solution: You can declare an HPA[Horizontal Pod Autoscaler] for your deployment with a flag of --max-replicas=xx, then you need to write a job using request metrics, that whenever there is request to the service the Deployment should be scaled automatically and descaled likewise. Also you will have to downscale as soon as the request ends. You should use v2beta2 apiVersion of HPA, as it allows that type of metrics.
Also what I think is that you will have to use the v2beta2 apiVersion of HPA because you will have to keep the request count to unary so that the requests doesn't generate 5XX as kubernetes service will send the request to the same pod if such metric isn't set.
Upvotes: 2