# Resource utilization for RayServe in Kubernetes (AKS)

**URL:** <https://discuss.ray.io/t/resource-utilization-for-rayserve-in-kubernetes-aks/6614>\
**Category:** Kubernetes\
**Created:** [June 23, 2022, 5:00pm UTC](https://discuss.ray.io/t/resource-utilization-for-rayserve-in-kubernetes-aks/6614 "2022-06-23T17:00:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![akelloway](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/akelloway/32/575_2.png) [@akelloway](https://discuss.ray.io/u/akelloway)\
**Post date:** [June 23, 2022, 5:00pm UTC](https://discuss.ray.io/t/resource-utilization-for-rayserve-in-kubernetes-aks/6614/1 "2022-06-23T17:00:11Z")

</div>

Trying to better understand resource utilization in Kubernetes cluster for Ray Serve deployments. Assume relatively lightweight CPU only deployments (e.g., {num\_cpus: 1} per deployment).

How does the cluster config yaml specs for worker cpu resource limits interact with my @serve.deployment deployments? For example, if my cluster config says workers resource limits are CPU=4 does that mean that I can have 4 deployments per worker? At the 5th deployment(/deployment replica) does Ray spin up a new worker (assuming less than max workers)? Does each deployment “reserve” its “num\_cpus” from the worker pool and hold on to them forever? How would this affect CPU utilization numbers from a kubernetes admin viewpoint?

I am asking because we are seeing high cpu consumption and I was wondering if perhaps I did not have optimal/best practice Cluster Config settings for my use case.

Thanks

---

<div class="post-metadata">

**Author:** ![ckw017](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ckw017/32/1683_2.png) [@ckw017](https://discuss.ray.io/u/ckw017)\
**Post date:** [June 23, 2022, 9:20pm UTC](https://discuss.ray.io/t/resource-utilization-for-rayserve-in-kubernetes-aks/6614/2 "2022-06-23T21:20:32Z")

</div>

cc @Dmitri for cluster config question, @eoakes for serve questions

---

<div class="post-metadata">

**Author:** ![Dmitri](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/dmitri/32/657_2.png) [@Dmitri](https://discuss.ray.io/u/Dmitri)\
**Post date:** [June 24, 2022, 6:09pm UTC](https://discuss.ray.io/t/resource-utilization-for-rayserve-in-kubernetes-aks/6614/3 "2022-06-24T18:09:16Z")

</div>

> [@akelloway](#):
>
> For example, if my cluster config says workers resource limits are CPU=4 does that mean that I can have 4 deployments per worker? At the 5th deployment(/deployment replica) does Ray spin up a new worker (assuming less than max workers)? Does each deployment “reserve” its “num\_cpus” from the worker pool and hold on to them forever?

This sounds correct.

> How would this affect CPU utilization numbers from a kubernetes admin viewpoint?

One deployment occupies one “logical” CPU, as tracked by the Ray scheduler. The actual CPU usage depends on what the deployment is actually doing.  
Allocating 1 logical CPU to a Ray task/actor that actually uses significantly more than 1 core in terms of actual usage would cause problems. If you have 4 such over-active tasks/actors in a 4CPU K8s pod, K8s’s CPU throttling mechanisms would kick in.

---

<div class="post-metadata">

**Author:** ![akelloway](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/akelloway/32/575_2.png) [@akelloway](https://discuss.ray.io/u/akelloway)\
**Post date:** [June 24, 2022, 6:28pm UTC](https://discuss.ray.io/t/resource-utilization-for-rayserve-in-kubernetes-aks/6614/4 "2022-06-24T18:28:31Z")

</div>

Thanks @Dmitri all that information helps a lot. So you are saying we should be picky about getting that “num\_cpus” on the ray side approximately correct to the work being done so that additional K8S workers/pods can be spun as/if needed?  
Thanks again

---

<div class="post-metadata">

**Author:** ![Dmitri](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/dmitri/32/657_2.png) [@Dmitri](https://discuss.ray.io/u/Dmitri)\
**Post date:** [June 24, 2022, 7:07pm UTC](https://discuss.ray.io/t/resource-utilization-for-rayserve-in-kubernetes-aks/6614/5 "2022-06-24T19:07:41Z")

</div>

> [@akelloway](#):
>
> So you are saying we should be picky about getting that “num\_cpus” on the ray side approximately correct to the work being done so that additional K8S workers/pods can be spun as/if needed?

Exactly. Underestimating num\_cpus is bad for performance. Overestimating is safe but bad from a cost/utilization perspective.
