Skip to main content

No project description provided

Project description

JupyterHub Idle Culler Service

GitHub Workflow Status - Test Latest PyPI version GitHub Discourse Gitter

jupyterhub-idle-culler provides a JupyterHub service to identify and shut down idle or long-running Jupyter Notebook servers. The exact actions performed are dependent on the used spawner for the Jupyter Notebook server (e.g. the default LocalProcessSpawner, kubespawner, or dockerspawner). In addition, if explicitly requested, all users whose Jupyter Notebook servers have been shut down this way are deleted as JupyterHub users from the internal database. This neither affects the authentication method which continues to allow those users to log in nor does it delete persisted user data (e.g. stored in docker volumes for dockerspawner or in persisted volumes for kubespawner).

Setup

Installation

pip install jupyterhub-idle-culler

As a hub managed service

In jupyterhub_config.py, add the following dictionary for the idle-culler Service to the c.JupyterHub.services list:

c.JupyterHub.services = [
    {
        'name': 'idle-culler',
        'admin': True,
        'command': [
            sys.executable,
            '-m', 'jupyterhub_idle_culler',
            '--timeout=3600'
        ],
    }
]

where:

  • 'admin': True indicates that the Service requires admin permissions so it can shut down arbitrary user notebooks, and
  • 'command' indicates that the Service will be managed by the Hub.

As a standalone script

jupyterhub-idle-culler can also be run as a standalone script. It can access the hub's api with a service token. The service token must have admin privileges.

Generate an API token and store it in a JUPYTERHUB_API_TOKEN environment variable. Then start jupyterhub-idle-culler manually

export JUPYTERHUB_API_TOKEN=$(jupyterhub token)
python3 -m jupyterhub-idle-culler [--timeout=900] [--url=http://localhost:8081/hub/api]

The command line interface also gives a quick overview of the different options for configuration.

  --concurrency                    Limit the number of concurrent requests made
                                   to the Hub.                  Deleting a lot
                                   of users at the same time can slow down the
                                   Hub,                 so limit the number of
                                   API requests we have outstanding at any
                                   given time.                  (default 10)
  --cull-every                     The interval (in seconds) for checking for
                                   idle servers to cull (default 0)
  --cull-users                     Cull users in addition to servers.
                                   This is for use in temporary-user cases such
                                   as tmpnb. (default False)
  --max-age                        The maximum age (in seconds) of servers that
                                   should be culled even if they are active
                                   (default 0)
  --remove-named-servers           Remove named servers in addition to stopping
                                   them.             This is useful for a
                                   BinderHub that uses authentication and named
                                   servers. (default False)
  --timeout                        The idle timeout (in seconds) (default 600)
  --url                            The JupyterHub API URL

Caveats

  1. last_activity is not updated with high frequency, so cull timeout should be greater than the sum of:

    • single-user websocket ping interval (default: 30 seconds)
    • JupyterHub.last_activity_interval (default: 5 minutes)
  2. The same --timeout and --max-age values are used to cull users and users' servers. If you want a different value for users and servers, you should add this script to the services list twice, just with different names, different values, and one with the --cull-users option.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyterhub-idle-culler-1.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

jupyterhub_idle_culler-1.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file jupyterhub-idle-culler-1.1.tar.gz.

File metadata

  • Download URL: jupyterhub-idle-culler-1.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for jupyterhub-idle-culler-1.1.tar.gz
Algorithm Hash digest
SHA256 45bceffeea8758b60e1f60650bc3de0d0d1e5f774623793db268ded1fa0cbdcb
MD5 150af330c66b7b63fd1ff797162d838b
BLAKE2b-256 4af472ae0932d0a42076d6c4e9bef76f8015d9ca5e888f28837d34511f94a543

See more details on using hashes here.

File details

Details for the file jupyterhub_idle_culler-1.1-py3-none-any.whl.

File metadata

  • Download URL: jupyterhub_idle_culler-1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8

File hashes

Hashes for jupyterhub_idle_culler-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 600b2713f90ecc475f690747d1ec02bcae8f44fa7f3e51a71e400727895631d8
MD5 b3fe5c5a6287cba45b3a56ebcea32733
BLAKE2b-256 8eea0758be25096893df3e5fb0e5565556c1a7f25c597ca059345e8127a60c4d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page