# Help understanding c.Spawner.cpu\_limit

**URL:** <https://discourse.jupyter.org/t/help-understanding-c-spawner-cpu-limit/13086>\
**Category:** JupyterHub\
**Tags:** cpu\
**Created:** [February 18, 2022, 1:52pm UTC](https://discourse.jupyter.org/t/help-understanding-c-spawner-cpu-limit/13086 "2022-02-18T13:52:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![foxz88](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@foxz88](https://discourse.jupyter.org/u/foxz88)\
**Post date:** [February 18, 2022, 1:52pm UTC](https://discourse.jupyter.org/t/help-understanding-c-spawner-cpu-limit/13086/1 "2022-02-18T13:52:12Z")

</div>

Hello,

I have a Jupyterhub install on Mint 20.3 started with jupyterhub-systemdspawner. It is running on a 48 cores server.

c.Spawner.cpu\_limit is set to 4.

Reading the documentation, i thought that a user notebook would be able to use up to 4 cores @ 100% (400%). But in reality, a notebook is able to use 48 cores @ 2.83% (400%).

c.Spawner.cpu.limit is supposed to be the maximum number of cpu-cores a single-user notebook server is allowed to use.

How can I really limit a notebook to a maximum number of cpu-cores instead of using all cpu-cores at a lower rate?

Python code used for testing:

from multiprocessing import Pool  
import psutil  
import time  
def f(x):  
set\_time = 1  
timeout = time.time() + 60\*float(set\_time) # X minutes from now  
while True:  
if time.time() \> timeout:  
break  
if **name** == ‘ **main** ’:  
# Test on for core/cpu  
# processes = 4  
# Test on all core/cpu  
processes = psutil.cpu\_count()  
print (‘utilizing %d cores\n’ % processes)  
pool = Pool(processes)  
pool.map(f, range(processes))

Thanks.

---

<div class="post-metadata">

**Author:** ![markperri](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/markperri/32/2187_2.png) [@markperri](https://discourse.jupyter.org/u/markperri)\
**Post date:** [February 18, 2022, 4:44pm UTC](https://discourse.jupyter.org/t/help-understanding-c-spawner-cpu-limit/13086/2 "2022-02-18T16:44:27Z")

</div>

It only works if your spawner supports it. It looks like systemdspawner does support it, I wonder if your system doesn’t support it, like if cgroups isn’t supported. (I’m not sure what systemdspawner uses to limit cpu usage).

You could try c.SystemdSpawner.cpu\_limit = 4.0 and see if that helps.

---

<div class="post-metadata">

**Author:** ![markperri](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/markperri/32/2187_2.png) [@markperri](https://discourse.jupyter.org/u/markperri)\
**Post date:** [February 18, 2022, 4:56pm UTC](https://discourse.jupyter.org/t/help-understanding-c-spawner-cpu-limit/13086/3 "2022-02-18T16:56:03Z")

</div>

Oh I just reread your message. I don’t know of any way to pin it to cpus, or why it would matter.

---

<div class="post-metadata">

**Author:** ![manics](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/manics/32/85_2.png) [@manics](https://discourse.jupyter.org/u/manics)\
**Post date:** [February 18, 2022, 5:44pm UTC](https://discourse.jupyter.org/t/help-understanding-c-spawner-cpu-limit/13086/4 "2022-02-18T17:44:29Z")

</div>

@markperri is right. It sounds like you want CPU pinning (or CPU affinity) which isn’t supported. It’d be very difficult to do, how would you know which CPUs to assign to each user with multiple users, and how would you handle other processes running on the system?

Can you explain what you’re hoping to achieve?

---

<div class="post-metadata">

**Author:** ![foxz88](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@foxz88](https://discourse.jupyter.org/u/foxz88)\
**Post date:** [February 18, 2022, 6:10pm UTC](https://discourse.jupyter.org/t/help-understanding-c-spawner-cpu-limit/13086/5 "2022-02-18T18:10:25Z")

</div>

I want to limit the number of cores used by a user. I think the documentation is misleading. c.Spawner.cpu\_limit = 4 should let you use up to 4 cores at 100% for a total of 400%.

Instead, it seems to take 400% of the total number of core. On a 10 cores system, a user will be able to use 10 core @ 40% for a total of 400% instead of just 4 cores.

c.Spawner.cpu\_limit = 4.0 does not change the behaviour.

---

<div class="post-metadata">

**Author:** ![markperri](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/markperri/32/2187_2.png) [@markperri](https://discourse.jupyter.org/u/markperri)\
**Post date:** [February 19, 2022, 4:29am UTC](https://discourse.jupyter.org/t/help-understanding-c-spawner-cpu-limit/13086/6 "2022-02-19T04:29:54Z")

</div>

Really all you care about is that in top they show 400%, right? If you have 12 cores then 3 users can get their full computational power. If you really want cpu pinning then you should use something like slurmspawner.

Thanks,  
Mark
