-
-
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
Memory competition between notebook processes - proactively run GC? #1850
Comments
Can you create a MWE example notebook? |
On my system with 64 GB of RAM, this code accumulates ~1 GB of RAM:
If you open up another notebook, same code but append In this test case, I'm noticing it won't go much above 1 GB before the GC runs. |
@fonsp - Just wanted to bump this. It seems like it would be easy enough to implement? After all cells have run, execute I'd do a PR but not sure where to put it. The issue is that the GC only runs when memory is requested by a process. So if no new memory is requested by a notebook, it'll just sit there holding on to unneeded memory forever. |
Hi @BioTurboNick , thanks! My only concern is making interactive notebooks slower, e.g. Perhaps we could run it only after the initial run, or only after a manual run (Shift+Enter), not a bond change. What is |
Fair point about adjusting sliders... could there be a cancelable task spawned that waits some duration and is reset each time cells are run? EDIT: or just on those runs you suggested. Re: malloc_trim: JuliaLang/julia#42566 (comment) (the process in question was a Pluto notebook) Basically, Julia frees memory with the GC but doesn't always release it back to the OS. This is good if Julia needs to allocate that memory again soon because it doesn't have to make a syscall. This may be improved in a later release. Trim makes it give up some of that memory. |
Just to add that a common pattern I think is to put long/intensive executions behind checkboxes or button. It would be nice if this feature could run then too, somehow. Like if the execution was longer than 1 s, the overhead of the GC may be acceptable. |
Can GC run safely in a separate thread? |
RE: malloc_trim: I think it's best to wait a bit for JuliaLang/julia#42566 to progress. Adding But adding a |
It seems like we could run GC in a debounced, trailing way after completing cell execution. i.e. after the last cell finished, start a 3 second (example) timer. If, during that timeout, no cells started running, then run GC after the timeout. This will guarantee that GC runs after cell execution, but not during fast interactivity. Then also, we could run GC after each |
Could be generalized into some kind of "idle" state in which we can execute background tasks |
Yes; you also don't want the GC to starve, as it may be stressing the execution. |
@fonsp - I'm interested in trying a PR on this. Could you please point me to where a hook exists, or could be placed, to trigger such a mechanism? And if you also know of similar places to hook into user actions on a notebook (loading an open notebook into a tab, performing some other interaction), that would be useful for #2236 |
A kind-of educated guess could be to run the GC step before (or using) Pluto.jl/src/evaluation/Run.jl Line 34 in 4d9596b
Pluto.jl/src/evaluation/Run.jl Lines 452 to 455 in 4d9596b
import Pluto
function onevent(ev::Pluto.PlutoEvent) end
function onevent(ev::Pluto.NotebookExecutionDoneEvent)
condition = true
condition && GC.gc()
end
otherOptions = Dict{Symbol, Any}(#=Add more here =#)
Pluto.run(;on_event=onevent, otherOptions...) Edit: this is actually a bit oversimplified. You would want a |
I have an issue where there's a shared Pluto instance and multiple people are using notebooks. They leave them open, and in total the notebooks are absorbing a huge chunk of system memory.
I've noticed that Pluto memory usage can grow really large to fill available memory, without running the GC. We're talking 4-5 GB when after GC it's 2.5 GB, in one instance.
I think it would help to have Pluto run the GC on a notebook process automatically to reduce its footprint on the system. Either when no cells are pending, or some time after the notebook has been idle?
The text was updated successfully, but these errors were encountered: