Skip to content

Commit

Permalink
Allow cluster managers to specify specific bind ports
Browse files Browse the repository at this point in the history
  • Loading branch information
amitmurthy committed Sep 29, 2014
1 parent 2f81d9a commit 79712a9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
10 changes: 9 additions & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,15 @@ function init_bind_addr(args::Vector{UTF8String})
# --worker, -n and --machinefile options are affected by it
btoidx = findfirst(args, "--bind-to")
if btoidx > 0
bind_addr = parseip(args[btoidx+1])
bind_to = split(args[btoidx+1], ":")
bind_addr = parseip(bind_to[1])
if length(bind_to) > 1
bind_port = parseint(bind_to[2])
else
bind_port = 0
end
else
bind_port = 0
try
bind_addr = getipaddr()
catch
Expand All @@ -188,6 +195,7 @@ function init_bind_addr(args::Vector{UTF8String})
end
global LPROC
LPROC.bind_addr = bind_addr
LPROC.bind_port = uint16(bind_port)
end


Expand Down
12 changes: 9 additions & 3 deletions base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ end
type LocalProcess
id::Int
bind_addr::IPAddr
bind_port::Uint16
LocalProcess() = new(1)
end

Expand Down Expand Up @@ -944,10 +945,15 @@ function start_worker(out::IO)
# exit when process 1 shut down. Don't yet know why.
#redirect_stderr(STDOUT)

(actual_port,sock) = listenany(uint16(9009))
if LPROC.bind_port == 0
(actual_port,sock) = listenany(uint16(9009))
LPROC.bind_port = actual_port
else
sock = listen(LPROC.bind_port)
end
sock.ccb = accept_handler
print(out, "julia_worker:") # print header
print(out, "$(dec(actual_port))#") # print port
print(out, "$(dec(LPROC.bind_port))#") # print port
print(out, LPROC.bind_addr)
print(out, '\n')
flush(out)
Expand Down Expand Up @@ -1171,7 +1177,7 @@ function launch_on_machine(manager::SSHManager, config::Dict, resp_arr::Array, m

thisconfig = copy(config) # config for this worker

# machine could be of the format [user@]host[:port] bind_addr
# machine could be of the format [user@]host[:port] bind_addr[:bind_port]
machine_bind = split(machine)
if length(machine_bind) > 1
exeflags = `--bind-to $(machine_bind[2]) $exeflags_base`
Expand Down
7 changes: 4 additions & 3 deletions doc/manual/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ worker processes, while ``--machinefile file`` will launch a worker
for each line in file ``file``. The machines defined in ``file`` must be
accessible via a passwordless ``ssh`` login, with Julia installed at the
same location as the current host. Each machine definition takes the form
``[user@]host[:port] [bind_addr]`` . ``user`` defaults to current user,
``port`` to the standard ssh port. Optionally, in case of multi-homed hosts,
``bind_addr`` may be used to explicitly specify an interface.
``[user@]host[:port] [bind_addr[:port]]`` . ``user`` defaults to current user,
``port`` to the standard ssh port. The optional ``bind-to bind_addr[:port]``
specifies the ip-address and port that other workers should use to
connect to this worker.


If you have code that you want executed whenever julia is run, you can
Expand Down
5 changes: 4 additions & 1 deletion doc/manual/parallel-computing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,10 @@ The ``launch`` method takes the following arguments:

The ``launch`` method is called asynchronously in a separate task. The termination of this task
signals that all requested workers have been launched. Hence the ``launch`` function MUST exit as soon
as all the requested workers have been launched.
as all the requested workers have been launched. The julia worker MUST be launched with a ``--worker``
argument. Optionally ``--bind-to bind_addr[:port]`` may also be specified to enable other workers
to connect to it only at the specified ``bind_addr`` and ``port``.


Arrays of worker information tuples that are appended to ``resp_arr`` can take any one of
the following forms::
Expand Down
7 changes: 4 additions & 3 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5061,9 +5061,10 @@ Parallel Computing
Add processes on remote machines via SSH.
Requires julia to be installed in the same location on each node, or to be available via a shared file system.

``machines`` is a vector of host definitions of the form ``[user@]host[:port] [bind_addr]``. ``user`` defaults
to current user, ``port`` to the standard ssh port. Optionally, in case of multi-homed hosts, ``bind_addr``
may be used to explicitly specify an interface.
``machines`` is a vector of host definitions of the form ``[user@]host[:port] [bind_addr[:port]]``. ``user`` defaults
to current user, ``port`` to the standard ssh port. A worker is started at each host definition.
If the optional ``[bind_addr[:port]]`` is specified, other workers will connect to this worker at the
specified ``bind_addr`` and ``port``.

Keyword arguments:

Expand Down

0 comments on commit 79712a9

Please sign in to comment.