Skip to content

Commit 8ca5f5e

Browse files
Log how long each extension module takes to import (#1171)
* Log how long each extension module takes to import Based on some detailed debugging in 2i2c-org/infrastructure#2047 to figure out why a Jupyter Server *process* somtimes takes more than 30s to start, the primary culprit was server extensions that took multiple seconds to just even import. Thanks to some ad-hoc patching (2i2c-org/infrastructure#2047 (comment)), I was able to figure out which were the slow extensions. This PR emits extension import time as log messages, so this information is *much* more visible. I also explicitly chose info instead of debug, primarily because I believe it is *very* important to surface this performance information to users, so they can go bug the appropriate extension. Otherwise, it just feels like 'jupyter server is slow!'. This is compounded by the fact that while notebook server doesn't import *disabled* extensions, jupyter_server does seem to - so it's hard to isolate this. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Account for the possibility logger is None Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a52709c commit 8ca5f5e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

jupyter_server/extension/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Extension utilities."""
22
import importlib
3+
import time
34
import warnings
45

56

@@ -62,7 +63,15 @@ def get_metadata(package_name, logger=None):
6263
If it doesn't exist, return a basic metadata packet given
6364
the module name.
6465
"""
66+
start_time = time.perf_counter()
6567
module = importlib.import_module(package_name)
68+
end_time = time.perf_counter()
69+
duration = end_time - start_time
70+
# Sometimes packages can take a *while* to import, so we report how long
71+
# each module took to import. This makes it much easier for users to report
72+
# slow loading modules upstream, as slow loading modules will block server startup
73+
if logger:
74+
logger.info(f"Package {package_name} took {duration:.4f}s to import")
6675

6776
try:
6877
return module, module._jupyter_server_extension_points()

0 commit comments

Comments
 (0)