-
Notifications
You must be signed in to change notification settings - Fork 1
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
allow initiating peer to close stream gracefully #5
Open
simeonschaub
wants to merge
7
commits into
JuliaParallel:master
Choose a base branch
from
simeonschaub:sds/check_eof2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d700b33
allow initiating peer to close stream gracefully
simeonschaub 7bb2144
add integration tests
simeonschaub 35a095d
Distributed -> DistributedNext
simeonschaub 8a58312
fixup! add integration tests
JamesWrigley d3b6655
fixup! add integration tests
JamesWrigley 9bf5217
fixup! add integration tests
JamesWrigley 719be61
fixup! add integration tests
JamesWrigley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
include("testhelpers/PersistentWorkers.jl") | ||
using .PersistentWorkers | ||
using Test | ||
using Random | ||
using DistributedNext | ||
|
||
@testset "PersistentWorkers.jl" begin | ||
cookie = randstring(16) | ||
port = rand(9128:9999) # TODO: make sure port is available? | ||
helpers_path = joinpath(@__DIR__, "testhelpers", "PersistentWorkers.jl") | ||
cmd = `$(Base.julia_exename()) --startup=no --project=$(Base.active_project()) -L $(helpers_path) -e "using .PersistentWorkers; wait(start_worker_loop($port; cluster_cookie=$(repr(cookie)))[1])"` | ||
worker = run(pipeline(cmd; stdout, stderr); wait=false) | ||
try | ||
@show worker.cmd | ||
cluster_cookie(cookie) | ||
sleep(10) | ||
|
||
p = addprocs(PersistentWorkerManager(port))[] | ||
@test procs() == [1, p] | ||
@test workers() == [p] | ||
@test remotecall_fetch(myid, p) == p | ||
rmprocs(p) | ||
@test procs() == [1] | ||
@test workers() == [1] | ||
@test process_running(worker) | ||
# this shouldn't error | ||
@everywhere 1+1 | ||
|
||
# try the same thing again for the same worker | ||
p = addprocs(PersistentWorkerManager(port))[] | ||
@test procs() == [1, p] | ||
@test workers() == [p] | ||
@test remotecall_fetch(myid, p) == p | ||
rmprocs(p) | ||
@test procs() == [1] | ||
@test workers() == [1] | ||
@test process_running(worker) | ||
# this shouldn't error | ||
@everywhere 1+1 | ||
finally | ||
kill(worker) | ||
wait(worker) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
# Run the distributed test outside of the main driver since it needs its own | ||
# set of dedicated workers. | ||
include(joinpath(Sys.BINDIR, "..", "share", "julia", "test", "testenv.jl")) | ||
disttestfile = joinpath(@__DIR__, "distributed_exec.jl") | ||
# # Run the distributed test outside of the main driver since it needs its own | ||
# # set of dedicated workers. | ||
# include(joinpath(Sys.BINDIR, "..", "share", "julia", "test", "testenv.jl")) | ||
# disttestfile = joinpath(@__DIR__, "distributed_exec.jl") | ||
|
||
cmd = `$test_exename $test_exeflags $disttestfile` | ||
# cmd = `$test_exename $test_exeflags $disttestfile` | ||
|
||
if !success(pipeline(cmd; stdout=stdout, stderr=stderr)) && ccall(:jl_running_on_valgrind,Cint,()) == 0 | ||
error("Distributed test failed, cmd : $cmd") | ||
end | ||
# if !success(pipeline(cmd; stdout=stdout, stderr=stderr)) && ccall(:jl_running_on_valgrind,Cint,()) == 0 | ||
# error("Distributed test failed, cmd : $cmd") | ||
# end | ||
|
||
include("managers.jl") | ||
# include("managers.jl") | ||
include("persistent_workers.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
module PersistentWorkers | ||
|
||
using DistributedNext: DistributedNext, ClusterManager, WorkerConfig, worker_from_id, set_worker_state, W_TERMINATED | ||
using Sockets: InetAddr, localhost | ||
|
||
export PersistentWorkerManager, start_worker_loop | ||
|
||
struct PersistentWorkerManager{IP} <: ClusterManager | ||
addr::InetAddr{IP} | ||
end | ||
|
||
PersistentWorkerManager(host, port::Integer) = PersistentWorkerManager(InetAddr(host, port)) | ||
PersistentWorkerManager(port::Integer) = PersistentWorkerManager(localhost, port) | ||
|
||
function DistributedNext.launch(cm::PersistentWorkerManager, ::Dict, launched::Array, launch_ntfy::Base.GenericCondition{Base.AlwaysLockedST}) | ||
(; host, port) = cm.addr | ||
wc = WorkerConfig() | ||
wc.io = nothing | ||
wc.host = string(host) | ||
wc.bind_addr = string(host) | ||
wc.port = Int(port) | ||
push!(launched, wc) | ||
notify(launch_ntfy) | ||
return nothing | ||
end | ||
|
||
function DistributedNext.manage(::PersistentWorkerManager, ::Int, ::WorkerConfig, ::Symbol) end | ||
|
||
# don't actually kill the worker, just close the streams | ||
function Base.kill(::PersistentWorkerManager, pid::Int, ::WorkerConfig) | ||
w = worker_from_id(pid) | ||
close(w.r_stream) | ||
close(w.w_stream) | ||
set_worker_state(w, W_TERMINATED) | ||
return nothing | ||
end | ||
|
||
using DistributedNext: LPROC, init_worker, process_messages, cluster_cookie | ||
using Sockets: IPAddr, listen, listenany, accept | ||
|
||
function start_worker_loop(host::IPAddr, port::Union{Nothing, Integer}; cluster_cookie=cluster_cookie()) | ||
init_worker(cluster_cookie) | ||
LPROC.bind_addr = string(host) | ||
if port === nothing | ||
port_hint = 9000 + (getpid() % 1000) | ||
port, sock = listenany(host, UInt16(port_hint)) | ||
else | ||
sock = listen(host, port) | ||
end | ||
LPROC.bind_port = port | ||
t = let sock=sock | ||
@async while isopen(sock) | ||
client = accept(sock) | ||
process_messages(client, client, true) | ||
end | ||
end | ||
errormonitor(t) | ||
@info "Listening on $host:$port, cluster_cookie=$cluster_cookie" | ||
return t, host, port | ||
end | ||
|
||
function start_worker_loop((; host, port)::InetAddr; cluster_cookie=cluster_cookie()) | ||
return start_worker_loop(host, port; cluster_cookie) | ||
end | ||
|
||
function start_worker_loop(port::Union{Nothing, Integer}=nothing; cluster_cookie=cluster_cookie()) | ||
return start_worker_loop(localhost, port; cluster_cookie) | ||
end | ||
|
||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You could open a temporary server with
Sockets.listenany()
and get the port from that.