mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-15 05:53:00 +00:00
Add resource limits / guarantees consistently to jupyterhub
- Allows us to standardize this on the spawner base class, so there's a consistent interface for different spawners to implement this. - Specify the supported suffixes and various units we accept for memory and cpu units. - Standardize the way we expose resource limit / guarantees to single-user servers
This commit is contained in:
@@ -24,7 +24,7 @@ from traitlets import (
|
||||
validate,
|
||||
)
|
||||
|
||||
from .traitlets import Command
|
||||
from .traitlets import Command, MemorySpecification
|
||||
from .utils import random_port
|
||||
|
||||
class Spawner(LoggingConfigurable):
|
||||
@@ -182,7 +182,74 @@ class Spawner(LoggingConfigurable):
|
||||
from having an effect on their server.
|
||||
"""
|
||||
).tag(config=True)
|
||||
|
||||
|
||||
mem_limit = MemorySpecification(
|
||||
None,
|
||||
allow_none=True,
|
||||
help="""
|
||||
Maximum number of bytes a single-user server is allowed to use.
|
||||
|
||||
Allows the following suffixes:
|
||||
- K -> Kilobytes
|
||||
- M -> Megabytes
|
||||
- G -> Gigabytes
|
||||
- T -> Terabytes
|
||||
|
||||
If the single user server tries to allocate more memory than this,
|
||||
it will fail. There is no guarantee that the single-user server
|
||||
will be able to allocate this much memory - only that it can not
|
||||
allocate more than this.
|
||||
|
||||
This needs to be supported by your spawner for it to work.
|
||||
"""
|
||||
).tag(config=True)
|
||||
|
||||
cpu_limit = Float(
|
||||
None,
|
||||
allow_none=True,
|
||||
help="""
|
||||
Maximum number of cpu-cores a single-user server is allowed to use.
|
||||
|
||||
If this value is set to 0.5, allows use of 50% of one CPU.
|
||||
If this value is set to 2, allows use of up to 2 CPUs.
|
||||
|
||||
The single-user server will never be scheduled by the kernel to
|
||||
use more cpu-cores than this. There is no guarantee that it can
|
||||
access this many cpu-cores.
|
||||
|
||||
This needs to be supported by your spawner for it to work.
|
||||
"""
|
||||
).tag(config=True)
|
||||
|
||||
mem_guarantee = MemorySpecification(
|
||||
None,
|
||||
allow_none=True,
|
||||
help="""
|
||||
Minimum number of bytes a single-user server is guaranteed to have available.
|
||||
|
||||
Allows the following suffixes:
|
||||
- K -> Kilobytes
|
||||
- M -> Megabytes
|
||||
- G -> Gigabytes
|
||||
- T -> Terabytes
|
||||
|
||||
This needs to be supported by your spawner for it to work.
|
||||
"""
|
||||
).tag(config=True)
|
||||
|
||||
cpu_guarantee = Float(
|
||||
None,
|
||||
allow_none=True,
|
||||
help="""
|
||||
Maximum number of cpu-cores a single-user server is allowed to use.
|
||||
|
||||
If this value is set to 0.5, allows use of 50% of one CPU.
|
||||
If this value is set to 2, allows use of up to 2 CPUs.
|
||||
|
||||
Note that this needs to be supported by your spawner for it to work.
|
||||
"""
|
||||
).tag(config=True)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Spawner, self).__init__(**kwargs)
|
||||
if self.user.state:
|
||||
@@ -255,6 +322,17 @@ class Spawner(LoggingConfigurable):
|
||||
env[key] = value
|
||||
|
||||
env['JPY_API_TOKEN'] = self.api_token
|
||||
|
||||
# Put in limit and guarantee info if they exist.
|
||||
if self.mem_limit:
|
||||
env['LIMIT_MEM'] = str(self.mem_limit)
|
||||
if self.mem_guarantee:
|
||||
env['GUARANTEE_MEM'] = str(self.mem_guarantee)
|
||||
if self.cpu_limit:
|
||||
env['LIMIT_CPU'] = str(self.cpu_limit)
|
||||
if self.cpu_guarantee:
|
||||
env['GUARANTEE_CPU'] = str(self.cpu_guarantee)
|
||||
|
||||
return env
|
||||
|
||||
def template_namespace(self):
|
||||
|
Reference in New Issue
Block a user