VS Code and HPC#
Introduction#
Visual Studio Code (VS Code) is a code editor widely used for software development. Its integration with remote systems via the Remote-SSH extension allows users to work on HPC clusters directly from their local machines.
However, to facilitate this functionality VS Code runs a program called the vscode-server on the HPC login nodes, which can significantly degrade performance and negatively impact all other users. Moreover, the vscoder-server can remain even after users finish their work and disconnect.
Warning
Do not run vscode-server on login nodes. The additional processes can overload these shared resources, leading to slow response times and potential system instability.
Hint
On this page we present different strategies for working with VS Code in our cluster environments while avoiding negatively impacting the login node(s).
Solutions#
Instead of running VS Code remotely, consider a two-step workflow consisting of
Editing your code and then
Deploying your code only when ready.
This workflow offers several advantages:
Improved Performance: Work on your code without the added latency of a remote connections.
Version Control with Git: Collaborate with others, track changes and revert them if necessary.
Flexible Deployment Options: Deploy updates via git, scp, or sftp to the clusters.
For quick edits on the clusters, such as changing a parameter or a single string inside a file a number of command line editors such as vi or nano are available.
Hint
This approach is considered best practise.
A very usable web version of VS Code is available via Open OnDemand (OOD), on the AI Surrey and Eureka2 clusters.
To launch the OOD editor:
Log in to Open OnDemand (OOD) on either AI Surrey or Eureka2.
Navigate to the Dashboard and select
Code Server / System Installed App.Fill in the form asking you about number of hours, CPU cores, and amount of RAM.
A reasonable choice could be 5 hours, 4 cores, 8 GB. The lower your request for resources is, the faster it will be granted by the scheduler.
Click on
Launchto submit your request.Once the server has allocated your resources, click on
Connect to VS Code.
Hint
This approach is suitable for HPC newcomers.
Instead of pointing the Remote-SSH extension of VS code toward the login node, use the datamove servers instead.
These servers have access to the same filesystems as the AI Surrey cluster while offering much more compute capacity and should therefore be able to absorb the additional load of the vscode-server processes.
Hint
For now this solution is only available for users of the AI Surrey cluster as Eureka2’s filesystems are not (yet) directly mounted to the datamove servers.
The available datamove servers are:
datamove1.surrey.ac.ukdatamove2.surrey.ac.ukdatamove3.surrey.ac.uk
Steps to Add a New SSH Host:
- Open the Command Palette:
Press
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(macOS).
- Add a New SSH Host:
Type
Remote-SSH: Add New SSH Host...and press Enter.When prompted, enter the SSH connection string. For example:
ab1234@datamove1.surrey.ac.uk
- Select a Configuration File:
VS Code will prompt you to choose a configuration file. It will automatically create or update your SSH config behind the scenes. This means you don’t have to worry about file formatting or manual edits.
- Connect to the Host:
Open the Command Palette again and select
Remote-SSH: Connect to Host....Choose the newly added host from the list.
Instead of connecting to the login node, you can configure VS Code to connect directly to a compute node. This method ensures that the vscode-server process runs on a compute node, keeping the shared login nodes free from heavy load.
Warning
This solution is the technically most advanced option. It does require a certain understanding of SSH configuration and our cluster’s scheduler.
Step 1: Modify Your SSH Config File
Add the following entries to your SSH config file.
For macOS and Linux users:
Host eureka2
HostName eureka2.surrey.ac.uk
User ab1234
Host eureka2-vscode
ForwardAgent yes
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
ProxyCommand ssh eureka2 "/usr/bin/salloc --nodes=1 --ntasks-per-node=2 --time=8:00:00 /bin/bash -c 'nc \$SLURM_NODELIST 22'"
User ab1234
For Windows users, the configuration is nearly identical:
Host eureka2
HostName eureka2.surrey.ac.uk
User ab1234
Host eureka2-vscode
ForwardAgent yes
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
ProxyCommand ssh eureka2 "/usr/bin/salloc --nodes=1 --ntasks-per-node=2 --time=8:00:00 /bin/bash -c 'nc $SLURM_NODELIST 22'"
User ab1234
This setup creates a special SSH host entry called eureka2-vscode that, when connected to, automatically requests and further connects to a compute node via the scheduler.
Hint
For detailed instructions on locating and editing your SSH config file, please see our Generating SSH Keys page.
Replace
ab1234with your actual username .AI Surrey users should change the
Hosttoaisurrey, theHostNametoaisurrey-submit01.surrey.ac.uk, and update theProxyCommand.Change the requested resources, i.e., CPU cores, time (set to 2 and 8 hours in the example above) to your liking.
You might need to adjust the SSH connection timeout limit in VS Code (see Optional Steps below) to allow for the time the scheduler needs to allocate your job request.
Step 2: Connect with the VS Code Remote-SSH Extension
Open the Command Palette (
Ctrl+Shift+Pon Windows/Linux orCmd+Shift+Pon macOS).Run the command
Remote-SSH: Connect to Host....Select the
eureka2-vscodehost from the list.
Optional Steps
Increase the SSH Timeout:
Open VS Code settings (
File > Preferences > SettingsorCode > Settings.. > Settings).Search for
remote.SSH.connectTimeoutand set it to 180 seconds. This should give the scheduler enough time to allocate a compute node.
Set Up Passwordless SSH (optional):
Configure SSH key authentication for a smoother connection process. See Generating SSH Keys for details.