Skip to content

Instantly share code, notes, and snippets.

@ImBIOS
Created July 30, 2024 00:58
Show Gist options
  • Save ImBIOS/c49fe4c65bcc9be438887a3feb6e9013 to your computer and use it in GitHub Desktop.
Save ImBIOS/c49fe4c65bcc9be438887a3feb6e9013 to your computer and use it in GitHub Desktop.
Find Best PBS Node for VSCode Server
#!/bin/bash
# Function to assign a rank to a node based on its properties
get_node_rank() {
local properties="$1"
case "$properties" in
*xeon,spr,plat8480,ram512gb,netgbe,dual_gpu,hbm2e,gpu,max,max_1100*) echo 1 ;;
*xeon,spr,max9480,ram256gb,netgbe,batch,hbm*) echo 2 ;;
*xeon,icx,plat8380,ram2tb,net1gbe,batch*) echo 3 ;;
*xeon,icx,gold6348,ramgb,netgbe,jupyter,batch*) echo 4 ;;
*xeon,skl,ram384gb,net1gbe,renderkit*) echo 5 ;;
*xeon,spr,ram1024gb,netgbe,dnp50*) echo 6 ;;
*xeon,skl,gold6128,ram192gb,net1gbe,jupyter,batch,fpga_compile*) echo 7 ;;
*xeon,skl,gold6128,ram192gb,net1gbe,jupyter,batch*) echo 8 ;;
*xeon,skl,gold6128,ram192gb,net1gbe,fpga_runtime,fpga,agilex*) echo 9 ;;
*xeon,skl,gold6128,ram192gb,net1gbe,fpga_runtime,fpga,arria10*) echo 10 ;;
*xeon,emr,ram192gb,net1gbe,cpu_runtime*) echo 11 ;;
*xeon,clx,ram192gb,net1gbe,batch,extended,fpga,stratix10,fpga_runtime*) echo 12 ;;
*xeon,cfl,e-2176g,ram64gb,net1gbe,gpu,gen9*) echo 13 ;;
*core,tgl,i9-11900kb,ram32gb,netgbe,gpu,gen11*) echo 14 ;;
*) echo 99 ;; # Default rank if no match
esac
}
best_node=""
best_rank=99
for node in $(pbsnodes -l free | awk '{print $1}'); do
properties=$(pbsnodes "$node" | awk '/properties =/ {print $3}')
rank=$(get_node_rank "$properties")
if (( rank < best_rank )); then
best_rank=$rank
best_node=$node
fi
done
if [[ -n "$best_node" ]]; then
echo "Best node for VSCode Server: $best_node"
pbsnodes "$best_node" | awk '/state = free/ {state=$0} /properties =/ {prop=$0} END {print " " state; print " " prop}'
else
echo "No suitable nodes found."
fi
@ImBIOS
Copy link
Author

ImBIOS commented Jul 30, 2024

PBS Node Selector for VSCode Server

This script helps you find the most suitable node in your PBS cluster for running a VSCode Server instance, especially when working on large TypeScript codebases.

Usage:

  1. Save the script: Copy the script content and save it to a file (e.g., find_best_vscode_node.sh).
  2. Make it executable: Use the command chmod +x find_best_vscode_node.sh.
  3. Run the script: Execute the script with ./find_best_vscode_node.sh.

How it Works:

  • Node Ranking: The script uses a predefined ranking system (see script comments) that prioritizes nodes based on hardware specifications crucial for smooth VSCode Server performance with large TypeScript projects:
    • High RAM, fast network, powerful CPU, and GPU availability are given preference.
  • Free Node Analysis: It retrieves a list of free nodes from PBS using pbsnodes.
  • Property Extraction: For each free node, it extracts the properties string, which contains hardware information.
  • Rank Comparison: The script compares the rank of each node based on its properties and stores the node with the highest ranking.
  • Output: It prints the name of the best-ranked node along with its state and properties. If no suitable nodes are found, it displays a message indicating that.

Customization:

You can adjust the ranking system within the script to match your specific hardware preferences and cluster configuration.

Requirements:

  • PBS cluster environment
  • pbsnodes command accessible in your shell

This script streamlines the process of finding the optimal node for your VSCode Server, allowing you to focus on coding without manual node selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment