# How to configure which port workers listen

**URL:** https://discourse.julialang.org/t/how-to-configure-which-port-workers-listen/46759
**Category:** Julia at Scale
**Created:** [September 17, 2020, 8:16am UTC](https://discourse.julialang.org/t/how-to-configure-which-port-workers-listen/46759 "2020-09-17T08:16:10Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)
#### Post date: [September 17, 2020, 8:16am UTC](https://discourse.julialang.org/t/how-to-configure-which-port-workers-listen/46759/1 "2020-09-17T08:16:10Z")

</div>

I’m trying to use ClusterManagers.jl to distribute jobs on an LSF cluster but I have ran into issues as the ports used by workers (9000-10000?) are not open.

Is it possible to specify a port range when the `--worker` argument is used in a similar way as the IP can be specified with `--bind-to` (perhaps `–bind-to $(hostname -i):$(rand[x:y]))?

If not, where can I find what the `--worker` argument does so I can just write an own version of that? Or is this not going to be feasible?

---

<div class="post-metadata">

### Author: ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)
#### Post date: [September 17, 2020, 9:17am UTC](https://discourse.julialang.org/t/how-to-configure-which-port-workers-listen/46759/2 "2020-09-17T09:17:56Z")

</div>

Uhm, I should probably have tried before asking 🙂

`--bind-to <ipaddress>:<port>` seems to work.

EDIT: It works, but port number for workers on same IP must also be unique. How to achieve this?

---

<div class="post-metadata">

### Author: ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)
#### Post date: [September 17, 2020, 10:22am UTC](https://discourse.julialang.org/t/how-to-configure-which-port-workers-listen/46759/3 "2020-09-17T10:22:53Z")

</div>

I would be interested to hear about your experiences.  
I’m now going to get a bit boring - on large clusters the job launch mechanism uses munge for authentication. And large MPI jobs are launched using mechanisms which scale.  
I guess by saying such things I ought to put my money where my mouth is and start to investigate them.

---

<div class="post-metadata">

### Author: ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)
#### Post date: [September 17, 2020, 10:46am UTC](https://discourse.julialang.org/t/how-to-configure-which-port-workers-listen/46759/4 "2020-09-17T10:46:27Z")

</div>

I will happily do so, but the rest of your post kinda makes me feel like this post wasn’t meant for me 🙂

I’m kinda fiddling with this in between other tasks and meetings, so progress is not super fast.

One slight annoyance was how to use the above to generate random port numbers for each worker, just mundane things like this:

```julia
julia> `--bind-to \`hostname -i\`:\$\(\(6000+RANDOM%1000\)\)`
`--bind-to \`hostname '-i\`:$((6000+RANDOM%1000))'`

```

Note the inserted single quotes which prevents the random expression from being evaluated by the shell.

I don’t know enough about ports to know if it is important to randomize them so for now I just try with the same port for all workers.

---

<div class="post-metadata">

### Author: ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)
#### Post date: [September 18, 2020, 8:23pm UTC](https://discourse.julialang.org/t/how-to-configure-which-port-workers-listen/46759/5 "2020-09-18T20:23:53Z")

</div>

Ok, when scaling up I realized why one needs different port numbers: Workers on the same IP address of course need to have unique port numbers.

Am I correct in my understanding that it is not possible to use variables like $LSB\_BATCH\_JID or $RANDOM in a cmd? Any suggestions on what to do?

---

<div class="post-metadata">

### Author: ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)
#### Post date: [September 24, 2020, 8:36am UTC](https://discourse.julialang.org/t/how-to-configure-which-port-workers-listen/46759/6 "2020-09-24T08:36:54Z")

</div>

I managed to work around the issue by using perl to compute the port number instead of bash. For some reason any permutation of `bash -c 'echo <expr>'` resulted in unwanted single quotes in the final expression and for some reason this does not happen when using `perl -le 'print <expr>'`

Here is the final expression I ended up using:

```julia
exeflags=`--bind-to \`hostname -i\`:\`perl -le 'print 6000+(10*$ENV{"LSB_JOBID"}+$ENV{"LSB_JOBINDEX"})%1000' \`

```

---

<div class="post-metadata">

### Author: ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)
#### Post date: [September 24, 2020, 11:22am UTC](https://discourse.julialang.org/t/how-to-configure-which-port-workers-listen/46759/7 "2020-09-24T11:22:06Z")

</div>

Perl? Yay - the camel lives again.  
I would make a flippant remark about why not use Julia…  
Actually a serious question here - if you limit yourself to Base functions only, what is the startup time of a short script like that?  
Note to self - again why not do some work and measure it?

---

<div class="post-metadata">

### Author: ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)
#### Post date: [September 24, 2020, 12:16pm UTC](https://discourse.julialang.org/t/how-to-configure-which-port-workers-listen/46759/8 "2020-09-24T12:16:31Z")

</div>

I guess I could, but the startup time would be unnecessary to just print a number.

It would be interesting to have a richer worker startup script but I just could not find the effort to dig out what that --worker flag does. Do you think it would allow for not running that annoying `@everywhere` expression after workers are added? That could possibly alleviate [that other issue](https://discourse.julialang.org/t/adding-remote-workers-to-ongoing-dagger-job/47196/2) I’m investigating.

Adding a script when the worker flag is present seems to prevent the script from executing. If all --worker does is printing out the ip and port then it is ofc not much to duplicate. At one point I was contemplating to just feed a malformed IP address and follow the stacktrace to reverse engineer what happens but once I got a working solution there were other problems to focus on.

---

<div class="post-metadata">

### Author: ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)
#### Post date: [September 24, 2020, 3:49pm UTC](https://discourse.julialang.org/t/how-to-configure-which-port-workers-listen/46759/9 "2020-09-24T15:49:10Z")

</div>

I know it is not possible to change your cluster scheduler…  
Somehow I think array jobs would be useful here. I Am sure LSF supports similar

[https://slurm.schedmd.com/job\_array.html](https://slurm.schedmd.com/job_array.html)
