Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(gc): gc after HTTP calls and after runs #3142

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
ExpressionExplorer = "21656369-7473-754a-2065-74616d696c43"
FileWatching = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
FuzzyCompletions = "fb4132e2-a121-4a70-b8a1-d5b831dcdcc2"
GCUtils = "25d72b2e-e87f-11ef-9f1d-00155d5ae889"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
HypertextLiteral = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Expand Down Expand Up @@ -43,6 +44,7 @@ Downloads = "1"
ExpressionExplorer = "0.5, 0.6, 1"
FileWatching = "1"
FuzzyCompletions = "=0.5.5"
GCUtils = "1.0.0"
HTTP = "^1.5.2"
HypertextLiteral = "0.7, 0.8, 0.9"
InteractiveUtils = "1"
Expand Down
2 changes: 2 additions & 0 deletions src/evaluation/Run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function run_reactive!(
)
end
try_event_call(session, NotebookExecutionDoneEvent(notebook, user_requested_run))
WorkspaceManager.gc_worker((session, notebook))
return topological_order
end

Expand Down Expand Up @@ -487,6 +488,7 @@ function update_save_run!(
session,
NotebookExecutionDoneEvent(notebook, get(kwargs, :user_requested_run, true))
)
WorkspaceManager.gc_worker((session, notebook))
topological_order
end
end
Expand Down
9 changes: 9 additions & 0 deletions src/evaluation/WorkspaceManager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -712,4 +712,13 @@ function interrupt_workspace(session_notebook::Union{SN,Workspace}; verbose=true
end
end

function gc_worker(session_notebook::SN)
try
workspace = get_workspace(session_notebook)
if isdefined(Malt, :requestgc)
Malt.requestgc(workspace.worker)
end
catch; end
end

end
7 changes: 7 additions & 0 deletions src/webserver/WebServer.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import MsgPack
import UUIDs: UUID
import HTTP
import GCUtils: setup_gc

import Sockets
import .PkgCompat

Expand Down Expand Up @@ -167,6 +169,9 @@ function run!(session::ServerSession)

local port, serversocket = port_serversocket(hostIP, favourite_port, port_hint)

# Manual GC for the server process
after_http, cleanup, rest = setup_gc(360)

on_shutdown() = @sync begin
# Triggered by HTTP.jl
@info("\nClosing Pluto... Restart Julia for a fresh session. \n\nHave a nice day! 🎈\n\n")
Expand All @@ -179,6 +184,7 @@ function run!(session::ServerSession)
for nb in values(session.notebooks)
@asynclog SessionActions.shutdown(session, nb; keep_in_session=false, async=false, verbose=false)
end
cleanup()
end

server = HTTP.listen!(hostIP, port; stream=true, server=serversocket, on_shutdown, verbose=-1) do http::HTTP.Stream
Expand Down Expand Up @@ -311,6 +317,7 @@ function run!(session::ServerSession)
end
end
end
after_http()
end

server_running() =
Expand Down
Loading