VSCode: Difference between revisions

From CMU -- Language Technologies Institute -- HPC Wiki
Jump to navigation Jump to search
Created page with "Category:Tips <span id="using-vscode"></span> '''Note:''' [VSCodium](https://github.com/VSCodium/vscodium) is an open-source variant of Visual Studio Code that provides the same powerful features and extensibility, but without the telemetry and branding associated with the official version. = Using VSCode = When developing on [https://code.visualstudio.com/ VSCode], it’s important to be cautious about its CPU usage, especially when working on the login node, as i..."
 
 
(15 intermediate revisions by 11 users not shown)
Line 2: Line 2:
<span id="using-vscode"></span>
<span id="using-vscode"></span>


'''Note:''' [VSCodium](https://github.com/VSCodium/vscodium) is an open-source variant of Visual Studio Code that provides the same powerful features and extensibility, but without the telemetry and branding associated with the official version.
'''Note:''' [https://github.com/VSCodium/vscodium VSCodium] is an open-source variant of Visual Studio Code that provides the same powerful features and extensibility, but without the telemetry and branding associated with the official version.


= Using VSCode =
= Using VSCode =
When developing on [https://code.visualstudio.com/ VSCode], it’s important to be cautious about its CPU usage, especially when working on the login node, as it can be CPU-intensive. Certain extensions, such as the GitHub co-pilot extension, can significantly increase CPU usage. To monitor and limit CPU usage while developing on the login node, you can refer to the following articles ([https://medium.com/good-robot/use-visual-studio-code-remote-ssh-sftp-without-crashing-your-server-a1dc2ef0936d 1], [https://github.com/Microsoft/vscode/wiki/Performance-Issues 2], [https://stackoverflow.com/questions/52251058/random-high-cpu-usage 3]).


Alternatively, you can host a VSCode server on a compute node and establish an SSH tunnel to access it. This approach mostly avoids over consumption on the login node. To set this up, follow these steps:
When using vscode on babel, you can use remote-ssh functionality of VSCode to connect directly to a compute node.
This requires that you first create an active job on the compute node, then use an ssh proxy to ssh through a login node to the compute node.
To set up the SSH configuration for connecting to the compute node, follow these steps:


1. Download the VSCode server release [https://github.com/microsoft/vscode/issues/135856#issuecomment-1172773063 here] and extract it in your home directory on the login node.
1. If you have not already, set up [https://wiki.babel.cs.cmu.edu/index.php/SSH?title=SSH_Login#Passwordless_Login passwordless login] using a public/private key pair. Take a note of the location on your local machine of the ssh private key (e.g. <code>~/.ssh/id_rsa</code>) that you are using for passwordless login, we will call it <code>identity_file</code> below.


2. Run the following command on the login node:
2. Run a job that allocates the resources that you need for vscode development (including a GPU if you need a GPU machine). Here is an example: <code>srun --cpus-per-task 2 --mem=8000 --wait=0 -t 02:00:00 -n 1 --pty bash --partition=debug</code>. Take a note of what machine it is running on, we will call this <code>node_id</code>.
  $ srun -c 8 --mem 64G --time 1-00:00:00 vscode-server-linux-x64-web/bin/code-server --accept-server-license-terms


3. Once the server starts, take note of the compute node your job lands on (e.g., babel-x-y)and the URL shown (e.g., **http://localhost:port/?tkn=...)**.
3. On your local machine, update your SSH configuration file (<code>~/.ssh/config</code>) with the following entries. :


4. On the cluster login node, run the following command:
  Host babel
   $ ssh -NL <an available port>:0.0.0.0:port babel-x-y
    HostName login.babel.cs.cmu.edu
    User <andrew_id>
    IdentityFile <identity_file>
    Compression no
    ForwardAgent yes
    ForwardX11 no
 
   Host babel-compute-node
    HostName <node_id>
    User <andrew_id>
    IdentityFile <identity_file>
    ProxyJump babel
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
    LogLevel ERROR


5. On your local machine, run the following command:
4. After configuring SSH, run VSCode natively on your local machine and use the command palette to type `Remote-SSH: Connect to Host....` Select `babel-compute-node` from the list.
  $ ssh -NL port:0.0.0.0:<an available port> babel


6. Open your browser and navigate to **http://localhost:port/?tkn=...** to access the VSCode server running on the compute node.
=== Alternative: VSCode Tunnel ===
The tunnel feature of VSCode CLI allows you to avoid setting up proxy jump with SSH Config, since the VSCode server talks directly to vscode.dev. Vscode.dev will then host an instance which can be accessed with a browser (even on your phone).


Another option is to use the remote-ssh functionality of VSCode to connect directly to a compute node. This requires an active job on the compute node. To set up the SSH configuration for connecting to the compute node, follow these steps:
Pros: Easy to set up. Cons: Occasional performance issues due to network bandwidth.


1. Obtain the IP address of the compute node using the <code>ifconfig</code> command.
==== Prerequisite ====
Download VSCode server for Linux x64. You can get a copy at `/data/tir/projects/tir6/general/vscode_server`.


2. Update your SSH configuration file (<code>~/.ssh/config</code>) with the following entries:
==== Steps ====


  Host babel
# Launch a job with command `./code tunnel --accept-server-license-terms`. Ensure that you request sufficient memory and cores.
    HostName babel.lti.cs.cmu.edu
# Wait for you job to be launched and the stdout should contain a url (starting with `vscode.dev`) and optionally an authentication method.
    User <username>
 
    IdentityFile <identityfile>
'''Sample stdout'''<syntaxhighlight lang="text" line="1">
*^M
* Visual Studio Code Server^M
*^M
* By using the software, you agree to^M
* the Visual Studio Code Server License Terms (https://aka.ms/vscode-server-license) and^M
* the Microsoft Privacy Statement (https://privacy.microsoft.com/en-US/privacystatement).^M
*
[2024-03-05 11:51:03] info Creating tunnel with the name: tir-1-32
 
Open this link in your browser https://vscode.dev/tunnel/tir-1-32/home/user
 
To grant access to the server, please log into https://github.com/login/device and use code AB04-0E14
</syntaxhighlight>
 
== Connecting to a Compute Node ==


  Host babel-compute-node
You can also ssh directly to a compute node where you have a job already running by doing:
    HostName <node ip addr>
    User <username>
    IdentityFile <identityfile>
    ProxyJump babel


3. After configuring SSH, run VSCode natively on your local machine and use the command palette to type `Remote-SSH: Connect to Host....` Select `babel-compute-node` from the list.
ssh -J babel babel-X-XX

Latest revision as of 22:17, 28 October 2025

Note: VSCodium is an open-source variant of Visual Studio Code that provides the same powerful features and extensibility, but without the telemetry and branding associated with the official version.

Using VSCode

[edit | edit source]

When using vscode on babel, you can use remote-ssh functionality of VSCode to connect directly to a compute node. This requires that you first create an active job on the compute node, then use an ssh proxy to ssh through a login node to the compute node. To set up the SSH configuration for connecting to the compute node, follow these steps:

1. If you have not already, set up passwordless login using a public/private key pair. Take a note of the location on your local machine of the ssh private key (e.g. ~/.ssh/id_rsa) that you are using for passwordless login, we will call it identity_file below.

2. Run a job that allocates the resources that you need for vscode development (including a GPU if you need a GPU machine). Here is an example: srun --cpus-per-task 2 --mem=8000 --wait=0 -t 02:00:00 -n 1 --pty bash --partition=debug. Take a note of what machine it is running on, we will call this node_id.

3. On your local machine, update your SSH configuration file (~/.ssh/config) with the following entries. :

 Host babel
   HostName login.babel.cs.cmu.edu
   User <andrew_id>
   IdentityFile <identity_file>
   Compression no
   ForwardAgent yes
   ForwardX11 no
 Host babel-compute-node
   HostName <node_id>
   User <andrew_id>
   IdentityFile <identity_file>
   ProxyJump babel
   StrictHostKeyChecking no
   UserKnownHostsFile /dev/null
   LogLevel ERROR

4. After configuring SSH, run VSCode natively on your local machine and use the command palette to type `Remote-SSH: Connect to Host....` Select `babel-compute-node` from the list.

Alternative: VSCode Tunnel

[edit | edit source]

The tunnel feature of VSCode CLI allows you to avoid setting up proxy jump with SSH Config, since the VSCode server talks directly to vscode.dev. Vscode.dev will then host an instance which can be accessed with a browser (even on your phone).

Pros: Easy to set up. Cons: Occasional performance issues due to network bandwidth.

Prerequisite

[edit | edit source]

Download VSCode server for Linux x64. You can get a copy at `/data/tir/projects/tir6/general/vscode_server`.

Steps

[edit | edit source]
  1. Launch a job with command `./code tunnel --accept-server-license-terms`. Ensure that you request sufficient memory and cores.
  2. Wait for you job to be launched and the stdout should contain a url (starting with `vscode.dev`) and optionally an authentication method.

Sample stdout<syntaxhighlight lang="text" line="1">

[2024-03-05 11:51:03] info Creating tunnel with the name: tir-1-32

Open this link in your browser https://vscode.dev/tunnel/tir-1-32/home/user

To grant access to the server, please log into https://github.com/login/device and use code AB04-0E14 </syntaxhighlight>

Connecting to a Compute Node

[edit | edit source]

You can also ssh directly to a compute node where you have a job already running by doing:

ssh -J babel babel-X-XX