VSCode

From ScientificComputing
Revision as of 08:54, 23 April 2021 by Sfux (talk | contribs) (Workflow)

Jump to: navigation, search

Introduction

Visual Studio Code (VSCode) is a popular editor for developers. It has some plugins that allow users to run the editor on their local computer and connect via SSH to a remote system. In the case of an HPC cluster, this is suboptimal, as VSCode will just connect to one of the login nodes and start a large number of threads there. Our system administrators are regularly checking the login nodes and are warning users that are overloading a login node. Users that repeatedly overload login nodes will temporarily be banned from accessing the cluster.

Solution for using VSCode on an HPC cluster

The main (closed source) branch of VSCode cannot be integrated with the batch system and the developers refuse to implement such features (https://github.com/microsoft/vscode-remote-release/issues/1722). But there is also an opensource version of VSCode. A fork of the opensource version called code-server allows users to run VSCode in a browser window, which resolves most issues related to running it on an HPC cluster.

Preparation

The preparation steps only need to be executed once.

  • Login to the cluster
  • Switch to the new software stack, either using
env2lmod

for the current shell, or

set_software_stack.sh new

to set it as permanent default (when using this command, you need to logout and login again to make the change becoming active)

  • Load the modules required for code-server
module load gcc/6.3.0 code-server/3.9.3
  • Start the code-server once with the command code-server
[sfux@eu-g1-043-1 ~]$ code-server
[2021-04-21T12:27:29.229Z] info  code-server 3.9.3 fe2dc2deb08e378069891b622bb62ad1d261d1b1
[2021-04-21T12:27:29.235Z] info  Using user-data-dir ~/.local/share/code-server
[2021-04-21T12:27:29.249Z] info  Using config file ~/.config/code-server/config.yaml
[2021-04-21T12:27:29.249Z] info  HTTP server listening on http://127.0.0.1:8080
[2021-04-21T12:27:29.249Z] info    - Authentication is enabled
[2021-04-21T12:27:29.249Z] info      - Using password from ~/.config/code-server/config.yaml
[2021-04-21T12:27:29.249Z] info    - Not serving HTTPS

This will setup the local configuration (including a password for you) and store it in your home directory in $HOME/.config/code-server/config.yaml

  • After the server started, terminate it with ctrl+c

Workflow

  • Login to the Euler cluster
  • Switch to the new software stack, either using
env2lmod

for the current shell, or

set_software_stack.sh new

to set it as permanent default (when using this command, you need to logout and login again to make the change becoming active)

  • Load the modules required for code-server
module load gcc/6.3.0 code-server/3.9.3
  • Start a batch job running the following shell script
#!/bin/bash

port=$((20000 + $RANDOM % 45000))
local_port=8899
ip=$(hostname -i)
echo "ssh -N -f -L localhost:${local_port}:${ip}:${port} ${USER}@euler.ethz.ch" > $HOME/VSCode_tunnel
code-server --bind-addr=$(hostname -i):${port}
  • Setup an SSH tunnel using the command stored in the file $HOME/VSCode_tunnel in your home directory on the cluster. The command for setting up the SSH tunnel needs to be executed on your local computer
  • Open a browser on your local computer and connect to the URL
http://localhost:8899
  • Login with the password stored in your home directory $HOME/.config/code-server/config.yaml

Please note that after finishing your work with VSCode, you need to do some manual cleanup for terminating the SSH tunnel. For finding the process id of the SSH tunnel, you can use the command

ps -u | grep -m1 -- "-L" | grep -- "-N"

Once you know the process id of the SSH tunnel, you can terminate it with the command

kill PID

with PID being the process id of the SSH tunnel. Please also don't forget to terminate the batch job where the server is running, as it would otherwise continue to run until the runtime limit of the job is reached.