From 359954f6fd4a6535fb495fc6b75acadc308fcb96 Mon Sep 17 00:00:00 2001 From: Lev Gromov Date: Fri, 22 Dec 2023 18:34:05 +0100 Subject: [PATCH 1/2] Add port finder to job submission script --- hpc/hq_scripts/job.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/hpc/hq_scripts/job.sh b/hpc/hq_scripts/job.sh index af0d7a6..aae949c 100755 --- a/hpc/hq_scripts/job.sh +++ b/hpc/hq_scripts/job.sh @@ -6,12 +6,31 @@ #HQ --stdout none #HQ --stderr none -# Launch model server, send back slurm job ID -# and wait to ensure that HQ won't schedule any more jobs to this allocation +# Launch model server, send back server URL +# and wait to ensure that HQ won't schedule any more jobs to this allocation. -/your/model/server/call & # CHANGE ME! +function get_avaliable_port { + # Define the range of ports to select from + MIN_PORT=1024 + MAX_PORT=65535 + + # Generate a random port number + port=$(shuf -i $MIN_PORT-$MAX_PORT -n 1) + + # Check if the port is in use + while lsof -Pi :$port -sTCP:LISTEN -t >/dev/null; do + # If the port is in use, generate a new random port number + port=$(shuf -i $MIN_PORT-$MAX_PORT -n 1) + done -port=4242 + echo $port +} + +port=$(get_avaliable_port) +export PORT=$port + +# Assume that server sets the port according to the environment variable 'PORT'. +/your/model/server/call & # CHANGE ME! load_balancer_dir="/load/balancer/directory" # CHANGE ME! @@ -23,6 +42,7 @@ while ! curl -s "http://$host:$port/Info" > /dev/null; do sleep 1 done +# Write server URL to file identified by HQ job ID. mkdir -p "$load_balancer_dir/urls" echo "http://$host:$port" > "$load_balancer_dir/urls/url-$HQ_JOB_ID.txt" From 97a7cd1c4ff67719efa6892863c6bd1f5a3e8606 Mon Sep 17 00:00:00 2001 From: Lev Gromov Date: Fri, 22 Dec 2023 18:34:46 +0100 Subject: [PATCH 2/2] Remove now unused setup_model.sh --- hpc/hq_scripts/setup_model.sh | 47 ----------------------------------- 1 file changed, 47 deletions(-) delete mode 100755 hpc/hq_scripts/setup_model.sh diff --git a/hpc/hq_scripts/setup_model.sh b/hpc/hq_scripts/setup_model.sh deleted file mode 100755 index 1714a4a..0000000 --- a/hpc/hq_scripts/setup_model.sh +++ /dev/null @@ -1,47 +0,0 @@ -#! /bin/bash - -# Path to the directory of the load balancer executable, e.g. "$HOME/xxx" -# WARNING: This has to be an absolute path because this script -# will run in the .hq-server directory NOT in the CWD. -load_balancer_dir="..." # CHANGE ME! - -# Path to the model executable/source, e.g. "$HOME/xxx/server" or "$HOME/xxx/server.py" -# WARNING: This has to be an absolute path because this script -# will run in the .hq-server directory NOT in the CWD. -server_file="..." # CHANGE ME! - -function get_avaliable_port { - # Define the range of ports to select from - MIN_PORT=1024 - MAX_PORT=65535 - - # Generate a random port number - port=$(shuf -i $MIN_PORT-$MAX_PORT -n 1) - - # Check if the port is in use - while lsof -Pi :$port -sTCP:LISTEN -t >/dev/null; do - # If the port is in use, generate a new random port number - port=$(shuf -i $MIN_PORT-$MAX_PORT -n 1) - done - - echo $port -} - -port=$(get_avaliable_port) -export PORT=$port - -# Send the model URL to the load balancer -mkdir -p "$load_balancer_dir/urls" -echo "http://$(hostname):$port" > "$load_balancer_dir/urls/url-$SLURM_JOB_ID.txt" - -# Load any dependencies (e.g. activate a conda environment) -# ... - -# Start the model -# For an executable binary (e.g. C++) -$server_file & - -# For a Python model -#python $server_file & - -# May want to add a check here if the model is ready to be used, e.g. by sending a basic request. \ No newline at end of file