-
-
Notifications
You must be signed in to change notification settings - Fork 297
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
Trailing throttle syncs to front-end #1036
Conversation
Converting this to draft as I would like to check whether we can add a lock to the function call; I don't trust concurrency 🎈✨⭐ |
Added 'thread safety', which means that the function cannot be running by two threads simultaneously. The last thing to consider is, do mutations that may happen 'simultaneously' matter? should every throttled function call get its own copy of the state?? |
In the first paragraph of your comment, aren't you saying that the second paragraph is not possible? |
Can you add some basic tests with
|
Not exactly - I'm saying that if BUT if I'm not even sure if that's possible by Julia's thread model (since our The thing is that we'll probably need to be locking the resource (
Of course! I have a notebook that does this here: https://github.com/pankgeorg/spam/blob/main/throttled.jl, I'll convert to a test |
Why does |
@@ -47,7 +47,8 @@ function run_reactive!(session::ServerSession, notebook::Notebook, old_topology: | |||
end | |||
|
|||
# Send intermediate updates to the clients at most 20 times / second during a reactive run. (The effective speed of a slider is still unbounded, because the last update is not throttled.) | |||
send_notebook_changes_throttled = throttled(1.0/20, 0.0/20) do | |||
# flush_send_notebook_changes_throttled, | |||
send_notebook_changes_throttled, flush_notebook_changes = throttle(1.0/20; leading=false, trailing=true) do | |||
send_notebook_changes!(ClientRequest(session=session, notebook=notebook)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code will run at most once per 1/20 sec, @async
.
BUT there is no guarantee I can think of that code that mutates (notebook, session) will not run right before/right after/inbetween.
e.g. runsingle!
at line 80-something
This comment has been minimized.
This comment has been minimized.
The feature is not related; the
all these functions all hold the lock, I think. |
I see, I can try to think about the thread safe stuff tomorrow with a CLEAR brain :) It does seem like the code would be simpler if you deleted the args, kwargs, and result features. Because then, |
Co-authored-by: Fons van der Plas <fonsvdplas@gmail.com>
I'm using a slightly modified version of
Flux.jl
's throttle: https://github.com/FluxML/Flux.jl/blob/8afedcd6723112ff611555e350a8c84f4e1ad686/src/utils.jl#L662