# Performance overhead numbers

**URL:** <https://discuss.ray.io/t/performance-overhead-numbers/4208>\
**Category:** Ray Core\
**Created:** [November 22, 2021, 5:45pm UTC](https://discuss.ray.io/t/performance-overhead-numbers/4208 "2021-11-22T17:45:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbehrendt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mbehrendt/32/516_2.png) [@mbehrendt](https://discuss.ray.io/u/mbehrendt)\
**Post date:** [November 22, 2021, 5:45pm UTC](https://discuss.ray.io/t/performance-overhead-numbers/4208/1 "2021-11-22T17:45:57Z")

</div>

![ex_1000_1.1GB_files_0.25cpu_per_function40_nodes_8x32](https://us1.discourse-cdn.com/flex020/uploads/ray/original/2X/e/e5e9854d5f84b3e2bbb1933cbcc86e24ddde2f44.png)  
 ![ex_1000_1.1GB_files_0.125cpu_per_function40_nodes_8x32](https://us1.discourse-cdn.com/flex020/uploads/ray/original/2X/6/63a67fc1e05a895ef2e8bac1d903e0946a1bcd17.png)  
 ![ex_awss3_300M_chunksize_40_nodes_1.0cpus_per_call](https://us1.discourse-cdn.com/flex020/uploads/ray/original/2X/d/d4d247faea32258f347fde77b7b541890fd810fe.png)  
Hi— i’d have a quick performance/scale related question.

I created a ray cluster with 50 VMs, each having 8 vCPUs and 32GB of memory,. In the cluster yaml i specified that each VM has 7 vCPU available. In the code you can see below, I specified that each function call should be getting 0.5 vCPU.

So in an ideal world, it should be possible to run 7\*50/0.5=700 function calls in parallel. In that ideal world, 10k of these calls would then take 10k/700= ~14 seconds.

Having in mind that this is just the theoretical optimum, if there is no overall at all from the scheduler, it feels quite long that it takes in my test a bit more than 2 minutes.

Are you seeing the same, or am I missing something, or not using things correctly?

In particular, i’m wondering whether part of the problem could be that scheduling seems to be done in a kind of sequential fashion. That is kinda indicated also by some graphs i generated for running some other logic on ray. Normally I’d expect that the lines representing when each function invocation start at least more parallel than what is implied by this graph. wdyt?

```auto
ray.init(address="auto")

@ray.remote(num_cpus=0.5)
def f(x, i):
    print(i)
    time.sleep(0.5)
    return i * i

x=2
futures = [f.remote(x, i) for i in range(10000)]
print(ray.get(futures))

```

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [November 23, 2021, 11:27am UTC](https://discuss.ray.io/t/performance-overhead-numbers/4208/2 "2021-11-23T11:27:44Z")

</div>

Hi, @mbehrendt Thanks for the post! I am also curious if you are seeing the same behavior if you set num\_cpus=1 instead of 0.5. In this case, would it take 1 minute (half of what you observe), or a lot faster than that?

Currently, lots of scheduling overhead we found is from worker process startup time, and one of causes could be we limit the # of concurrent worker startup to num\_cpus (so num\_cpus=0.5 means 8 workers are started first, and other 8 are going to be blocked until that’s done). I am curious if this is one of the factors of scheduling behavior you observed

---

<div class="post-metadata">

**Author:** ![mbehrendt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mbehrendt/32/516_2.png) [@mbehrendt](https://discuss.ray.io/u/mbehrendt)\
**Post date:** [November 23, 2021, 12:59pm UTC](https://discuss.ray.io/t/performance-overhead-numbers/4208/3 "2021-11-23T12:59:15Z")

</div>

Hi @sangcho – thx a lot for the feedback.

I think this can be broken down into 2 sub-problems:

1. Time a single scheduling and execution operation takes
2. Time many of them take, when invoked in parallel.

While work can probably be done on (1), the data I’ve been collecting so far seems to apply that the scheduling of workloads is a sequential operation, and not one that is done in parallel. Based on that, at least for me personally it would be interesting to better understand whether the sequential behavior of the scheduler works as-designed, or whether that is not expected. So even if we could cut exec time in half by maybe using double the amount of CPUs, it would be more interesting my mind whether we can achieve parallelism, as that could bring down the execution times way below one min, without having to increase the amount of vCPUs assigned to this.  
WDYT?

---

<div class="post-metadata">

**Author:** ![jjyao](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jjyao/32/1799_2.png) [@jjyao](https://discuss.ray.io/u/jjyao)\
**Post date:** [November 23, 2021, 6:08pm UTC](https://discuss.ray.io/t/performance-overhead-numbers/4208/4 "2021-11-23T18:08:11Z")

</div>

I did a quick test, changing num\_cpus to 1 improved a lot: the time for 10k task went down from 1m52s to 45s. Although I haven’t fully understand the reason yet.

---

<div class="post-metadata">

**Author:** ![mbehrendt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mbehrendt/32/516_2.png) [@mbehrendt](https://discuss.ray.io/u/mbehrendt)\
**Post date:** [December 1, 2021, 6:43pm UTC](https://discuss.ray.io/t/performance-overhead-numbers/4208/5 "2021-12-01T18:43:13Z")

</div>

did you do that in a cluster of multiple machines, or rather a single large one?

I think the primary challenge i’m seeing in my tests is that it takes 40-80 seconds to achieve maximum concurrency. Is that something you’re looking into? @jjyao

---

<div class="post-metadata">

**Author:** ![jjyao](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jjyao/32/1799_2.png) [@jjyao](https://discuss.ray.io/u/jjyao)\
**Post date:** [December 7, 2021, 5:12am UTC](https://discuss.ray.io/t/performance-overhead-numbers/4208/6 "2021-12-07T05:12:57Z")

</div>

I’m using a cluster of multiple machines. What’s the num\_cpus you are using? Could you try `num_cpus=1`.

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [December 7, 2021, 8:27am UTC](https://discuss.ray.io/t/performance-overhead-numbers/4208/7 "2021-12-07T08:27:08Z")

</div>

> it would be interesting to better understand whether the sequential behavior of the scheduler works as-designed,

For this comment, I believe this is intentional. IIUC, we are submitting tasks one by one currently. There’s a work in progress where we submit tasks as many as num nodes at a time instead of one by one. cc @Alex for confirmation (and why it is done this way).

---

<div class="post-metadata">

**Author:** ![mbehrendt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mbehrendt/32/516_2.png) [@mbehrendt](https://discuss.ray.io/u/mbehrendt)\
**Post date:** [December 7, 2021, 5:49pm UTC](https://discuss.ray.io/t/performance-overhead-numbers/4208/8 "2021-12-07T17:49:07Z")

</div>

cool, thanks a lot for sharing these details. Is there already a rough target timeframe for this enhancement?

---

<div class="post-metadata">

**Author:** ![jjyao](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jjyao/32/1799_2.png) [@jjyao](https://discuss.ray.io/u/jjyao)\
**Post date:** [December 7, 2021, 5:52pm UTC](https://discuss.ray.io/t/performance-overhead-numbers/4208/9 "2021-12-07T17:52:16Z")

</div>

I already implemented it (if that’s what sang was referring to): [https://github.com/ray-project/ray/pull/18647](https://github.com/ray-project/ray/pull/18647). You can change RAY\_max\_pending\_lease\_requests\_per\_scheduling\_category to increase the parallelism (you can set it to the number of nodes).

---

<div class="post-metadata">

**Author:** ![mbehrendt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mbehrendt/32/516_2.png) [@mbehrendt](https://discuss.ray.io/u/mbehrendt)\
**Post date:** [December 8, 2021, 9:02pm UTC](https://discuss.ray.io/t/performance-overhead-numbers/4208/10 "2021-12-08T21:02:00Z")

</div>

i used 0.5 vCPUs. But i just also ran the scenario with 1.0 cpus. The improved the ramp-up during startup, but also resulted in things being slower overall.
