-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified load balancer for SLURM version. Should become a separate ba…
…ckend
- Loading branch information
1 parent
99424b4
commit a793c04
Showing
3 changed files
with
70 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
#SBATCH --partition=devel | ||
#SBATCH --ntasks=1 | ||
#SBATCH --time=00:05:00 | ||
|
||
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 | ||
|
||
# Assume that server sets the port according to the environment variable 'PORT'. | ||
# Otherwise the job script will be stuck waiting for model server's response. | ||
./testmodel & # CHANGE ME! | ||
|
||
|
||
host=$(hostname -I | awk '{print $1}') | ||
|
||
echo "Waiting for model server to respond at $host:$port..." | ||
while ! curl -s "http://$host:$port/Info" > /dev/null; do | ||
sleep 1 | ||
done | ||
echo "Model server responded" | ||
|
||
# Write server URL to file identified by HQ job ID. | ||
load_balancer_dir="." | ||
mkdir -p "$load_balancer_dir/urls" | ||
echo "http://$host:$port" > "$load_balancer_dir/urls/url-$SLURM_JOB_ID.txt" | ||
|
||
sleep infinity # keep the job occupied |