Auto culling Jupyterhub notebooks

Hi all,

I would like to cull the idle jhub kernels which are idle for 12 hours. I would like to check every 1 hour interval. I am going to use jupyterhub-idle-culler-service. Setting --timeout=43200 will cull 12 hours idle kernel? How can I set the interval
1)
c.JupyterHub.services = [
{
“name”: “jupyterhub-idle-culler-service”,
“command”: [
sys.executable,
“-m”, “jupyterhub_idle_culler”,
“–timeout=3600”,
],
“admin”: True,
}
]

c.JupyterHub.load_roles = [
{
“name”: “jupyterhub-idle-culler-role”,
“scopes”: [
“list:users”,
“read:users:activity”,
“read:servers”,
“delete:servers”,
“admin:users”, # if using --cull-users
],
# assignment of role’s permissions to:
“services”: [“jupyterhub-idle-culler-service”],
}
]
what is the difference between using jupyterhub-idle-culler-service and below two options. For my requirement which is the best option
2)
MappingKernelManager.cull_busy =True

MappingKernelManager.cull_idle_timeout=43200

MappingKernelManager.cull_interval=3600

MappingKernelManager.cull_connected=True

3)c.ServerApp.shutdown_no_activity_timeout = 43200

Please clarify

Thanks,
Elango

You can see the full list of options by running python3 -m jupyterhub_idle_culler --help or here in the README GitHub - jupyterhub/jupyterhub-idle-culler at 1.2.1

--cull-every should do what you want.

1 Like

Thanks a lot @manics. It resolved the issue and I could auto cull the kernel.

After culling when I login to the Jhub, the server itself restarting again. Is it expected. Is there a way to just cull the kernel. Below is the config that I used for testing. Is it due to the property in the scope “delete:servers”.
My requirement is to just stop the long running notebook to free up resources. Please clarify
Also I assume after the culling, do we have to run the paragraph from the beginning again and we can not continue from where we left before culling? Please confirm.

import sys
c.JupyterHub.services = [
{
‘name’: “jupyterhub-idle-culler-service”,
‘admin’: True,
‘command’: [
sys.executable,
‘-m’, ‘jupyterhub_idle_culler’,
‘–timeout=2400’,
‘–cull-every=1200’,
‘–max-age=3600’
],
}
]
c.JupyterHub.load_roles = [
{
“name”: “jupyterhub-idle-culler-role”,
“scopes”: [
“list:users”,
“read:users:activity”,
“read:servers”,
“delete:servers”,
“admin:users”, # if using --cull-users
],
# assignment of role’s permissions to:
“services”: [“jupyterhub-idle-culler-service”],
}
]

Have a read through this, it explains some of the complexity behind culling servers/kernels:

I’m not sure what you mean by “paragraph”, do you mean a notebook cell? If so then you’ll have to run the notebook again from the beginning, since killing a kernel means all your internal state is lost.

1 Like

Thanks @manics for the clarification . Understood.