Skip to content
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

Thread to monitor the kernel usage (CPU, Memory...) #912

Closed
echarles opened this issue Apr 8, 2022 · 5 comments · Fixed by #937
Closed

Thread to monitor the kernel usage (CPU, Memory...) #912

echarles opened this issue Apr 8, 2022 · 5 comments · Fixed by #937
Assignees

Comments

@echarles
Copy link
Member

echarles commented Apr 8, 2022

While implementing a jupyterlab extension to monitor the kernel usage (https://github.com/Quansight/jupyterlab-kernel-usage), a few PRs have been merged to use psutil to return Memory, CPU usage of the machine and the kernel processes.

This has worked great for most of the metrics, but we hit now an issue for the kernel CPU reported on Quansight/jupyterlab-kernel-usage#11. psutil returns the CPU based on the last call, so it looks like everytime we ask the CPU via the kernel websocket, it return zero as psutil considers it is the first time the request is made, see info on:

Please note that similar issue is reported on the jupyter-resource-usage extension (which monitors the server usage, not the kernel usage) jupyter-server/jupyter-resource-usage#107

A solution would be to maintain a separated thread that would be responsible to return that CPU in a correct way based on psutil.

What would be the impact to create such as separated thread? What are the already existing threads? Does it sound like a reasonable approach? Any other idea?

@blink1073
Copy link
Contributor

What are the already existing threads?

It looks like the existing threads are heartbeat, iopub, and control.

Jupyter Client has threads for iopub, shell, stdin, control, and heartbeat.

I think it is worth trying to add a another thread, but maybe this is a good opportunity to add a performance regression check. SciPy uses airspeed velocity.

@echarles
Copy link
Member Author

echarles commented Apr 8, 2022

It looks like the existing threads are heartbeat, iopub, and control.

Thx @blink1073 Great to know ipykernel is already kind with thread hosting. I guess an additional one monitor, or maybe telemetry (thinking about the discussion in jupyter-server jupyter-server/jupyter_server#780 - maybe offtopic here, not sure?) could be added.

Jupyter Client has threads for iopub, shell, stdin, control, and heartbeat.

if we add a thread in ipykernel to monitor the resources, does that imply we ned also a thread in jupyter-client. My first intake was no, but I may miss context.

I think it is worth trying to add a another thread,

+1

but maybe this is a good opportunity to add a performance regression check. SciPy uses airspeed velocity.

It would be good. I guess that is not a small task to get that performance benchmarking setup.

@echarles echarles changed the title [DISCUSS] Trait to maintain the kernel usage (CPU, Memory...) [DISCUSS] Thread to maintain the kernel usage (CPU, Memory...) Apr 8, 2022
@echarles echarles changed the title [DISCUSS] Thread to maintain the kernel usage (CPU, Memory...) [DISCUSS] Thread to monitor the kernel usage (CPU, Memory...) Apr 8, 2022
@blink1073
Copy link
Contributor

does that imply we need also a thread in jupyter-client

I don't believe so, since client is launching ipykernel in a subprocess

I guess that is not a small task to get that performance benchmarking setup.

I don't think it needs to be too comprehensive to start.

@echarles echarles self-assigned this Apr 26, 2022
@dimpase
Copy link

dimpase commented Apr 30, 2022

Adding psutil as a dependency makes it impossible to install ipython on Cygwin. (psutil refused to merge @embray's patch for Cygwin in https://github.com/embray/psutil).

@dimpase
Copy link

dimpase commented Apr 30, 2022

@mkoeppe

@echarles echarles changed the title [DISCUSS] Thread to monitor the kernel usage (CPU, Memory...) Thread to monitor the kernel usage (CPU, Memory...) May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants