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

High CPU #2

Open
mpcjanssen opened this issue Aug 2, 2020 · 13 comments
Open

High CPU #2

mpcjanssen opened this issue Aug 2, 2020 · 13 comments

Comments

@mpcjanssen
Copy link
Owner

After killing the jupyter notebook the kernels seem to keep running and taking a constant 1-3% of CPU power.

@mpcjanssen
Copy link
Owner Author

This probably has to do with the fact that we can't detect when a client goes away.

@mpcjanssen
Copy link
Owner Author

Actual problem is constant polling probably because of the readable callback on the zmq sockets.

@mpcjanssen
Copy link
Owner Author

it's a tclzmq issue. The following script has high cpu:

package require zmq

zmq context ctx

vwait forever

@mrcalvin
Copy link
Collaborator

It is an issue by design, as internal to tclzmq, the ZMQ events are married with the Tcl event loop using (as you write) constant polling. tclzmq would need to adopt another integration technique (e.g., using ZMQ_USE_FD plus Tcl_CreateFileHandler), but this would lead to platform-specific pieces of implementation (e.g., on Win, Tcl has no Tcl_CreateFileHandler!). However, in absence of readable/ writeable handlers, polling should be paused ... maybe, as a workaround, use a default handler with some sleep time to cool down the polling?

@mpcjanssen
Copy link
Owner Author

Using Tcl event handlers with after and manually polling works fine. I am thinking about adding a switch to disable the event source integration

@mpcjanssen
Copy link
Owner Author

This is fixed by a combination of:

@mpcjanssen
Copy link
Owner Author

I am tempted to build a minimal zmq client in Tcl only for Tcljupyter use which would use socket readable handlers

@mrcalvin
Copy link
Collaborator

This is fixed by a combination of:

I used to solve this by using after in the writable (or, readable) handler, no need to deactivate event-source registration ... there is no difference to this end. But interval polling will dwarf throughput (among other issues), which is acceptable for an interactive application (like Jupyter notebooks), but not so acceptable in other settings.

@mrcalvin
Copy link
Collaborator

I am tempted to build a minimal zmq client in Tcl only for Tcljupyter use which would use socket readable handlers

I had the same thought, once, but it would require programming against Windows APIs directly (as I said, there is no Tcl file-handler abstraction under Win), I did not want to jump into this rabbit hole.

@mpcjanssen
Copy link
Owner Author

Why would a readable event handler on the zmq sockets not work? No platform API in sight.

@mrcalvin
Copy link
Collaborator

mrcalvin commented Aug 25, 2020

Why would a readable event handler on the zmq sockets not work? No platform API in sight.

Oh, you mean, create a Tcl channel type for ZMQ sockets? Well, right now, ZMQ sockets are no Tcl channels ... the reason being, probably, that ZMQ sockets are not sockets in the purest sense, you will have to extract the sibling sockets for each ZMQ socket ... and this will bring platform APIs in sight. If you don't, from what I found out back then, you will end up using polling again just under the hood of a Tcl channel ...

but maybe I am just wrong?

@mpcjanssen
Copy link
Owner Author

No just a plain Tcl server socket. This obviously will only support tcp:// type 0MQ sockets.

@mpcjanssen
Copy link
Owner Author

Cleanest way would be to do a blocking poll on all sockets in a separate thread and remove the event sourcing. And wrap this in a higher level API.

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

No branches or pull requests

2 participants