Skip to content
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

delay part of Distributed's initialization to improve startup time #28140

Merged
merged 1 commit into from
Jul 17, 2018
Merged
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
1 change: 0 additions & 1 deletion stdlib/Distributed/src/Distributed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ include("precompile.jl")
@deprecate pmap(p::AbstractWorkerPool, f, c1, c...; kwargs...) pmap(f, p, c1, c...; kwargs...)

function __init__()
push!(Base.package_callbacks, _require_callback)
init_parallel()
end

Expand Down
22 changes: 18 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,27 @@ 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
push!(Base.package_callbacks, _require_callback)
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