-
Notifications
You must be signed in to change notification settings - Fork 1
Add guideline on port forwarding #72
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
73332a1
Add draft guide
lauraporta 4162551
Add missing link from the idex
lauraporta ab77efb
Update indications on port fowarding in the code tunnel tutorial
lauraporta 717cd78
Update port fowarding tutorial
lauraporta 3f61d96
Remove flask example
lauraporta 9709209
Change title
lauraporta 4cccabb
Linting
lauraporta 7fb8c19
Update docs/source/programming/port-fowarding.md
lauraporta 68ee87b
Update docs/source/programming/port-fowarding.md
lauraporta 42a8691
Update docs/source/programming/port-fowarding.md
lauraporta d51d9c0
Update docs/source/programming/port-fowarding.md
lauraporta 9035d37
Apply Igor's suggestions
lauraporta 4461e48
Suggest conda instead
lauraporta dc285b3
Remove unnecessary discussion
lauraporta ff2a515
Be a bit more explicit n how to find the link with the token
lauraporta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # Accessing HTTP servers running on the HPC with port forwarding | ||
|
|
||
| This guide explains how to securely and effectively forward ports from a compute node on the SWC HPC cluster to your local machine, enabling access to services like Jupyter Lab. This is particularly useful when `code tunnel` is unreliable or you prefer using a terminal-based workflow. | ||
|
|
||
| Port forwarding allows you to interact with services running on a compute node (e.g., a Jupyter server on port 8082) from your browser or other tools on your laptop. | ||
|
|
||
| ## Overview | ||
|
|
||
| The technique described below **does not involve SSHing into unallocated nodes**, which could interfere with other users or violate HPC usage policies. Instead, you'll **only access a node you've been assigned by SLURM**, and will **forward ports from that node to your laptop**, enabling tools like Jupyter Lab to work as expected without disconnection issues. | ||
|
|
||
| --- | ||
|
|
||
| ## Step-by-step Instructions | ||
|
|
||
| ### 1. Connect to the cluster and request an interactive job | ||
|
|
||
| ```bash | ||
| ssh <SWC-USERNAME>@ssh.swc.ucl.ac.uk | ||
| ssh hpc-gw2 | ||
| ``` | ||
|
|
||
| Then request a SLURM interactive job. For example: | ||
|
|
||
| ```bash | ||
| srun -p gpu --gres=gpu:1 --mem=16G --pty bash -i | ||
| ``` | ||
|
|
||
| This will assign you a compute node using one GPU and give you an interactive shell there. | ||
|
|
||
| --- | ||
|
|
||
| ### 2. Set up and launch Jupyter Lab | ||
|
|
||
| On the assigned node, activate your environment and navigate to your project folder: | ||
|
|
||
| ```bash | ||
| conda activate my_env | ||
| cd /path/to/your/project | ||
| ``` | ||
|
|
||
| Then launch Jupyter Lab, specifying a port (e.g., 8082) and disabling the browser: | ||
|
|
||
| ```bash | ||
| jupyter lab --no-browser --port=8082 | ||
| ``` | ||
|
|
||
| Jupyter will start and display output similar to this: | ||
|
|
||
| ``` | ||
| [I 2024-01-01 12:00:00.000 ServerApp] Jupyter Server 2.14.2 is running at: | ||
| [I 2024-01-01 12:00:00.000 ServerApp] http://localhost:8082/lab?token=abc123def456... | ||
| [I 2024-01-01 12:00:00.000 ServerApp] http://127.0.0.1:8082/lab?token=abc123def456... | ||
| ... | ||
| Or copy and paste one of these URLs: | ||
| http://localhost:8082/lab?token=abc123def456... | ||
| http://127.0.0.1:8082/lab?token=abc123def456... | ||
| ``` | ||
|
|
||
| **Look for the lines that say "Or copy and paste one of these URLs:"** - these contain the complete URLs with the authentication token that you'll need to access Jupyter Lab from your browser. | ||
|
|
||
| --- | ||
|
|
||
| ### 3. Forward the port from the compute node to your local machine | ||
|
|
||
| On **your local machine**, open a separate terminal and run: | ||
|
|
||
| ```bash | ||
| ssh -N <SWC-USERNAME>@<node-name> -J <SWC-USERNAME>@ssh.swc.ucl.ac.uk,<SWC-USERNAME>@hpc-gw2 -L 8082:localhost:8082 | ||
| ``` | ||
|
|
||
| Replace `<node-name>` with the actual name of the compute node assigned to you (e.g., `gpu-sr670-20`). This command establishes a secure tunnel between your laptop and the node. | ||
|
|
||
| Then, **in your browser**, copy one of the complete URLs from the Jupyter Lab output. For example, from the output above, you would copy: | ||
|
|
||
| ``` | ||
| http://localhost:8082/lab?token=abc123def456... | ||
| ``` | ||
|
|
||
| **Note:** Either URL works, but you can change `127.0.0.1` to `localhost` if needed. The important part is to **copy the entire URL including the `?token=` portion** - this token is what authenticates you to the Jupyter server. | ||
|
|
||
| --- | ||
| ## Troubleshooting | ||
|
|
||
| - **Port mismatch?** Ensure both commands use the same port number. | ||
| - **Connection drops?** Keep your SLURM session active on the assigned node. | ||
| - **Port in use?** Try a different port (e.g., `8888`, `8090`) in both commands. | ||
|
|
||
| --- | ||
|
|
||
| ## Complementary tools | ||
|
|
||
| If you prefer a fully integrated development environment see our guide on: | ||
|
|
||
| [Using VSCode with Interactive SLURM Jobs →](./vscode-with-slurm-job.md) | ||
|
|
||
| --- | ||
|
|
||
| ## Examples of Other Web Applications | ||
|
|
||
| ### Dash Applications | ||
|
|
||
| For Dash applications, you can follow the same port forwarding approach: | ||
|
|
||
| Create your `app.py`: | ||
|
|
||
| ```python | ||
| from dash import Dash, html, dcc | ||
| import dash_bootstrap_components as dbc | ||
|
|
||
| app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP]) | ||
|
|
||
| app.layout = html.Div([ | ||
| html.H1("My Dash App"), | ||
| dcc.Graph(id='example-graph') | ||
| ]) | ||
|
|
||
| if __name__ == '__main__': | ||
| app.run(debug=False, host='0.0.0.0', port=8050) | ||
| ``` | ||
|
|
||
| **On the compute node**, launch your Dash app: | ||
|
|
||
| ```bash | ||
| python app.py | ||
| ``` | ||
|
|
||
|
|
||
| ### Streamlit Applications | ||
|
|
||
| For Streamlit applications: | ||
|
|
||
| ```python | ||
| import streamlit as st | ||
|
|
||
| st.title("My Streamlit App") | ||
| st.write("This is a simple Streamlit app.") | ||
| ``` | ||
| **On the compute node**, launch Streamlit with a specific port: | ||
|
|
||
| ```bash | ||
| streamlit run app.py --server.port 8501 --server.address 0.0.0.0 | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.