Skip to content

Commit a5f822e

Browse files
committed
feat(run): force a gc after every notebook run
1 parent 12569bc commit a5f822e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/evaluation/Run.jl

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function run_reactive!(
3232
)
3333
end
3434
try_event_call(session, NotebookExecutionDoneEvent(notebook, user_requested_run))
35+
WorkspaceManager.gc_worker((session, notebook))
3536
return topological_order
3637
end
3738

@@ -487,6 +488,7 @@ function update_save_run!(
487488
session,
488489
NotebookExecutionDoneEvent(notebook, get(kwargs, :user_requested_run, true))
489490
)
491+
WorkspaceManager.gc_worker((session, notebook))
490492
topological_order
491493
end
492494
end

src/evaluation/WorkspaceManager.jl

+13
Original file line numberDiff line numberDiff line change
@@ -712,4 +712,17 @@ function interrupt_workspace(session_notebook::Union{SN,Workspace}; verbose=true
712712
end
713713
end
714714

715+
function gc_worker(session_notebook::SN)
716+
workspace = get_workspace(session_notebook)
717+
718+
bytes = Malt.remote_eval_fetch(workspace.worker, quote
719+
bytes1 = Base.gc_live_bytes()
720+
Base.GC.gc(true)
721+
bytes2 = Base.gc_live_bytes()
722+
bytes1 - bytes2
723+
end)
724+
725+
@debug " Running succeded, cleanup cleaned $(round(bytes/1024/1024))MBs"
726+
end
727+
715728
end

src/webserver/GCUtils.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ function setup_gc()
1212
gcfull_metrics = GCFullMetrics(0.0, 0, 0.0)
1313

1414
function gcfull_automatic()
15+
b = Base.gc_live_bytes()
1516
e = @elapsed GC.gc(true)
17+
c = Base.gc_live_bytes()
1618
@atomic gcfull_metrics.last_time = time()
1719
@atomic gcfull_metrics.counter += 1
18-
@debug "GC full run (automatic)" time_taken = e
20+
@debug "GC full run (automatic) $(round(100*e)/100)s, $(round(100*(b-c)/1024/1024)/100)MB"
1921
end
2022

2123
@atomic gcfull_metrics.last_http_call_time = time()

0 commit comments

Comments
 (0)