Skip to content

Commit

Permalink
delay part of Distributed's initialization to improve startup time
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 16, 2018
1 parent 5b4d203 commit 3f1efed
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions stdlib/Distributed/src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ It does not return.
"""
start_worker(cookie::AbstractString=readline(stdin)) = start_worker(stdout, cookie)
function start_worker(out::IO, cookie::AbstractString=readline(stdin))
init_multi()

close(stdin) # workers will not use it
redirect_stderr(stdout)

Expand Down Expand Up @@ -358,6 +360,8 @@ master can be specified via variable `JULIA_WORKER_TIMEOUT` in the worker proces
environment. Relevant only when using TCP/IP as transport.
"""
function addprocs(manager::ClusterManager; kwargs...)
init_multi()

cluster_mgmt_from_master_check()

lock(worker_lock)
Expand Down Expand Up @@ -1111,17 +1115,26 @@ end

using Random: randstring

let inited = false
# do initialization that's only needed when there is more than 1 processor
global function init_multi()
if !inited
inited = true
atexit(terminate_all_workers)
init_bind_addr()
cluster_cookie(randstring(HDR_COOKIE_LEN))
end
return nothing
end
end

function init_parallel()
start_gc_msgs_task()
atexit(terminate_all_workers)

init_bind_addr()

# start in "head node" mode, if worker, will override later.
global PGRP
global LPROC
LPROC.id = 1
cluster_cookie(randstring(HDR_COOKIE_LEN))
@assert isempty(PGRP.workers)
register_worker(LPROC)
end
Expand Down

0 comments on commit 3f1efed

Please sign in to comment.