Open jlamcanopy opened 9 years ago
Not super easily. You could use a custom KernelManager that refuses to start new kernels if more than a certain number are already open. I don't think you will have a particularly good experience with error messages if you do that, though.
@minrk I'm new to Jupyter or Ipython but how do you control how much memory and CPU a user can use? For instance, a mad scientist can create thousand of notebooks in jupyter :)
@jlamcanopy you can use JupyterHub + your operating system's features for managing user accounts to limit the amount of memory per user. JupyterHub will simply make sure the server process is launched using the user's token.
@jdfreder Thanks for confirming this and your advice on how it could be done. Do you think it is useful to have a feature to have a configuration for limiting the number of notebooks running in jupyter?
I suppose in conjuncture with something like JupyterHub, it could be useful. But I do think if you are trying to control memory and cpu usage, it's best to do that directly. I'll mark this as wish list, and others can weigh in - or someone can come along and implement it ;)
I think this is probably one of those things like custom auth that probably shouldn't be implemented so much in the single-user notebook, but some code could be added to the single-user notebook to make it easier for managed deployments like JupyterHub to configure. We might already be at that point, though—registering a custom KernelManager that refuses to start new kernels is already available via existing config. But I'm pretty sure that failing to start kernels is not an error we handle well.
Hi, @jlamcanopy Did you get process of implementing this requirement? We are in a need to implement this feature too, if any information you would like to share with us?
It is possible now. (in jupyter server) In some cases, just shutdown existing kernel is better than refusing kernel start. (just ignore debug messages)
from jupyter_server.services.kernels.kernelmanager import AsyncMappingKernelManager
class CustomKernelManager(AsyncMappingKernelManager) :
async def start_kernel(self, kernel_id=None, path=None, **kwargs):
print("CustomKernelManager start_kernel")
print(f"Num Kernels Running: {len(self.list_kernels())}")
kernels = self.list_kernels()
if len(kernels) > 2 :
await self.shutdown_kernel(kernels[0]["id"])
return await AsyncMappingKernelManager.start_kernel(self, kernel_id, path, **kwargs)
c.ServerApp.kernel_manager_class = CustomKernelManager
For jupyterhub
(not jupyter notebooks for which this question was asked), for anyone who finds this, you can use active_server_limit .
I want to restrict users from starting too many notebooks. Is it possible? Thank you!