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

Add socket messages callbacks and comms API #376

Merged
merged 3 commits into from
Jun 23, 2022
Merged

Add socket messages callbacks and comms API #376

merged 3 commits into from
Jun 23, 2022

Conversation

ileasile
Copy link
Contributor

Fixes #366

Should also partially fix the needs of #375

@ileasile ileasile requested a review from nikolay-egorov June 20, 2022 00:32
Copy link
Contributor

@altavir altavir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be some kind of documentation about how those messages are used from the frontend part of the notebook.

fun messageReceived(data: JsonObject) {
if (closed) return
for (callback in onMessageCallbacks) {
callback(data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now here we execute callbacks on a callback thread inside another callback. I think, it's better to introduce some pool which would do that work for Comms instead of calling them right here.

Since it's callbacks, we don't need to worry much about stack-frame-awareness, but it would save time for the calling thread in case of large computations or a lot of messages

override fun <T> runExecution(classLoader: ClassLoader?, body: () -> T): ExecutionResult<T> {
var execRes: T? = null
var execException: Throwable? = null
val execThread = thread(contextClassLoader = classLoader ?: Thread.currentThread().contextClassLoader) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for posting a bit late. This would work, but creating and stopping a new thread a bit costly since it's OS call.

The more consise would be to reuse existing threads, so they wait for some tasks to appear from a queue and execute them, e.g. pool aproach. So perhaps we might reuse some existing, like Executors.newCachedThreadPool

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I undestand. It's just how it was implemented before. I will change it in a separate commit

@ileasile ileasile deleted the comms branch April 29, 2024 13:28
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 this pull request may close these issues.

Support Comm messages in the Kernel API
3 participants