-
Notifications
You must be signed in to change notification settings - Fork 372
Kernelspec Caching #1271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Kernelspec Caching #1271
Conversation
|
Hi @blink1073. The kernelspec cache test failures are due to a missing EDIT: Hmm, I'm also seeing a different issue not seen in dev (sorry about that), so will need to address that as well, but I think my questions are still applicable (although it looks like Windows must include |
|
|
|
Thanks Steve. Yeah, that's the issue I saw as well and things are moving along better in my fork. I had originally thought it was the watchdog dependency but, after closer inspection, it was all about the indexing issue. Looks like the docs build is failing due to the new sub folder for the monitors that I'll follow up on. Thanks for your help.
|
Kernelspec Caching
This pull request introduces a new configurable feature called KernelSpec Caching. The
KernelSpecCacheinstance supports the same retrieval methods as aKernelSpecManagerand contains the configuredKernelSpecManagerinstance. If caching is not enabled (by default), the cache is a direct pass-through to theKernelSpecManager, otherwise it acts as a read through cache, deferring to theKernelSpecManageron any cache misses. This functionality has proven useful in Enterprise Gateway where it has existed for a few years. In that implementation, thewatchdogpackage is used to determine cache updates.By introducing kernelspec caching, we can now define events corresponding to the addition, update, and deletion of kernel specifications and get closer to removing the 10-second polling performed by Lab once it has been updated to consume kernelspec events.
Monitors
Besides its enablement via the
cache_enabledconfigurable,KernelSpecCachesupports pluggable monitors that are responsible for detecting changes to the cached items and keeping the cache updated due to out-of-band updates. A kernelspec cache monitor is registered via the entry points group"jupyter_server.kernelspec_monitors"to introduce a layer of decoupling. This pull request includes two monitors:KernelSpecWatchdogMonitorunder the entry point name"watchdog-monitor":This monitor uses the
watchdogpackage to monitor changes to directories containing kernelspec definitions. Because this monitor uses thewatchdogpackage, an optional dependency has been added for users wishing to use this monitor:pip install jupyter_server[watchdog-monitor]KernelSpecPollingMonitorunder the entry point name"polling-monitor":This monitor periodically polls (via a configurable
intervaltrait) for kernelspec changes and computes an MD5 hash on each entry to further determine changes. It only updates the cache when the hash values have changed (or are new) and when it determines a kernelspec has been removed. The interval's default value is 30 (sec).KernelSpecPollingMonitoris the default monitor used since it does not introduce new packages.Other monitors that would be useful are:
"watchdog-monitor", but usingwatchfilesinstead, since we have other needs forwatchfiles. At that point, we may be able to make"watchfiles-monitor"the default - assuming we include thewatchfilespackage.KernelSpec caching is disabled by default. If we want to enable it by default, we'll need to adjust some tests (probably only kernelspecs and perhaps kernels api tests) to configure a much shorter polling interval, or switch the default to the
"watchfiles-monitor"(once implemented) since it sounds like there's a preference towatchfilesoverwatchdog. (Note: Enterprise Gateway happened to usewatchdoga few years ago, thus the reason the watchdog monitor exists. If we built a"watchfiles-monitor", I have no affinity for"watchdog-monitor"and see no reason to keep it unless we find advantages overwatchfiles.)Class Hierarchy
KernelSpecCachecontains instances of theKernelSpecManagerandKernelSpecMonitorBasethat corresponds to themonitor_nameconfigurable.--- title: KernelSpecCache Class Hierarchy --- classDiagram KernelSpecCache --* KernelSpecManager KernelSpecCache --* KernelSpecMonitorBase KernelSpecMonitorBase <|-- KernelSpecWatchdogMonitor KernelSpecMonitorBase <|-- KernelSpecPollingMonitor KernelSpecMonitorBase <|-- BYOMonitor class KernelSpecCache{ +str monitor_name +bool cache_enabled +get_kernel_spec(name) +get_all_specs() +get_item(name) +get_all_items() +put_item() +put_all_items() +remove_item(name) +remove_all_items() } class KernelSpecManager{ +get_kernel_spec(name) +get_all_specs() } class KernelSpecMonitorBase["KernelSpecMonitorBase (ABC)"]{ +initialize()* +destroy()* } class KernelSpecPollingMonitor{ +float interval }Event Support (Future)
With caching in place, we should be able to fire add and update kernelspec events from
KernelSpecCache.put_item()and delete kernelspec events fromKernelSpecCache.remove_item()since their corresponding all items methods simply call on the singleton versions.