# Problem connecting on a local h20 java session when having job array

**URL:** <http://hpc-community.unige.ch/t/problem-connecting-on-a-local-h20-java-session-when-having-job-array/2765>\
**Category:** HPC Technical\
**Created:** [March 10, 2023, 10:02am UTC](http://hpc-community.unige.ch/t/problem-connecting-on-a-local-h20-java-session-when-having-job-array/2765 "2023-03-10T10:02:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denis.Mongin](http://hpc-community.unige.ch/letter_avatar_proxy/v4/letter/d/ba9def/32.png) [@Denis.Mongin](http://hpc-community.unige.ch/u/Denis.Mongin)\
**Post date:** [March 10, 2023, 10:02am UTC](http://hpc-community.unige.ch/t/problem-connecting-on-a-local-h20-java-session-when-having-job-array/2765/1 "2023-03-10T10:02:31Z")

</div>

Dear all

I am trying to use H20 within R to analyze some data.  
H20 has some highly efficient trained AI models, that I would like to use. In R, there is the h20 R package, which gives convenient functions to connect to an h20 server. If there is no server to connect to with an h20 instance running, it launches a local instance of a java serve with h20 and connect to it, see [https://docs.h2o.ai/h2o/latest-stable/h2o-r/docs/articles/h2o-r-package.html](https://docs.h2o.ai/h2o/latest-stable/h2o-r/docs/articles/h2o-r-package.html).

It does work well on baobab: R launch a local java instance of h20 on IP “127.0.0.1” port 54321 and connect to it. But I would like to launch job array of 20 instances, and if I launch a job array, it no longer works, and I obtain the following error:

> Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = urlSuffix, :  
> Unexpected CURL error: Failed to connect to localhost port 54321: Connection refused  
> Calls: as.h2o … h2o.uploadFile → .h2o.doSafePOST → .h2o.doSafeREST  
> Execution halted

What could I do? My tests are the h20\_baobab\_testing.R and the associated baobab\_h20\_test.sh files, in the trip\_advisor folder.

Thank you for the help

Denis

---

<div class="post-metadata">

**Author:** ![Yann.Sagon](http://hpc-community.unige.ch/user_avatar/hpc-community.unige.ch/yann.sagon/32/3_2.png) [@Yann.Sagon](http://hpc-community.unige.ch/u/Yann.Sagon)\
**Post date:** [March 23, 2023, 8:47am UTC](http://hpc-community.unige.ch/t/problem-connecting-on-a-local-h20-java-session-when-having-job-array/2765/2 "2023-03-23T08:47:15Z")

</div>

Hi, you should use a distinct port per java instance. As stated in the documentation, you need to init h20 with a parameter to do so.

> `2o.init` without any arguments, and H2O will be automatically launched at `localhost:54321`, where the IP is “127.0.0.1” and the port is 54321. If H2O is running on a cluster, you must provide the IP and port of the remote machine as arguments to the `h2o.init()` call.

---

<div class="post-metadata">

**Author:** ![Denis.Mongin](http://hpc-community.unige.ch/letter_avatar_proxy/v4/letter/d/ba9def/32.png) [@Denis.Mongin](http://hpc-community.unige.ch/u/Denis.Mongin)\
**Post date:** [November 2, 2023, 9:29am UTC](http://hpc-community.unige.ch/t/problem-connecting-on-a-local-h20-java-session-when-having-job-array/2765/3 "2023-11-02T09:29:07Z")

</div>

> [@Denis.Mongin](#):
>
> 54321

Hy Yann

Sorry I come back to this question months after (just have the time to retry that now).  
What are the ports that are allowed to connect to ? I changed the port according to the baobab job, and some managed to connect, others no.

---

<div class="post-metadata">

**Author:** ![Yann.Sagon](http://hpc-community.unige.ch/user_avatar/hpc-community.unige.ch/yann.sagon/32/3_2.png) [@Yann.Sagon](http://hpc-community.unige.ch/u/Yann.Sagon)\
**Post date:** [November 3, 2023, 1:08pm UTC](http://hpc-community.unige.ch/t/problem-connecting-on-a-local-h20-java-session-when-having-job-array/2765/4 "2023-11-03T13:08:12Z")

</div>

Hi, @Denis.Mongin

all the ports bigger than 1024 _could_ be usable. The issue you may face is if the port is already in use this will fail. You should check if a port is free and use it.

Example script (quick and dirty, to be adapted to your use case:

```bash
#!/bin/sh
## check if the port in argument is free to use or already listening

PORT=$1
if $(ss -tln '( dport = :'${PORT}' or sport = :'${PORT}' )' | grep LISTEN -q)
then
   echo "port $PORT already in use"
   exit 1
else
   echo "port $PORT free"
fi

```

Example

```auto
(baobab)-[sagon@cpu001 ~]$ ./bla.sh 22
port 22 already in use
(baobab)-[sagon@cpu001 ~]$ ./bla.sh 23
port 23 free

```
