Skip to content

Commit de588e7

Browse files
authored
Merge pull request #175349 from ekpgh/hpc-add-fstab-script
Add load balancing script from vfxt doc
2 parents 55c7047 + 9339be9 commit de588e7

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

articles/hpc-cache/client-load-balancing.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ Read [Mount the Azure HPC Cache](hpc-cache-mount.md) for details.
3232

3333
## Use scripted load balancing
3434

35-
There are several ways to programmatically rotate client mounts among the available IP addresses.
35+
There are several ways to programmatically rotate client mounts among the available IP addresses. Here are two examples.
36+
37+
### Mount command script cksum example
3638

3739
This example mount command uses the hash function ``cksum`` and the client host name to automatically distribute the client connections among all available IP addresses on your HPC Cache. If all of the client machines have unique host names, you can run this command on each client to ensure that all available mount points are used.
3840

@@ -64,6 +66,35 @@ Here is an example of a populated client mount command:
6466
mount -o hard,proto=tcp,mountproto=tcp,retry=30 $(X=(10.7.0.{1..3});echo ${X[$(($(hostname|cksum|cut -f 1 -d ' ')%3))]}):/blob-target-1 /hpc-cache/blob1
6567
```
6668

69+
### Round robin function example
70+
71+
This code example uses client IP addresses as a randomizing element to distribute clients to all of the HPC Cache's available IP addresses.
72+
73+
```bash
74+
function mount_round_robin() {
75+
76+
# to ensure the clients are spread out somewhat evenly the default
77+
# mount point is based on this client's IP octet4 % number of HPC cache mount IPs.
78+
79+
declare -a MOUNT_IPS="($(echo ${NFS_IP_CSV} | sed "s/,/ /g"))"
80+
HASH=$(hostname | cksum | cut -f 1 -d ' ')
81+
DEFAULT_MOUNT_INDEX=$((${HASH} % ${#MOUNT_IPS[@]}))
82+
ROUND_ROBIN_IP=${MOUNT_IPS[${DEFAULT_MOUNT_INDEX}]}
83+
84+
DEFAULT_MOUNT_POINT="${BASE_DIR}/default"
85+
86+
# no need to write again if it is already there
87+
if ! grep --quiet "${DEFAULT_MOUNT_POINT}" /etc/fstab; then
88+
echo "${ROUND_ROBIN_IP}:${NFS_PATH} ${DEFAULT_MOUNT_POINT} nfs hard,proto=tcp,mountproto=tcp,retry=30 0 0" >> /etc/fstab
89+
mkdir -p "${DEFAULT_MOUNT_POINT}"
90+
chown nfsnobody:nfsnobody "${DEFAULT_MOUNT_POINT}"
91+
fi
92+
if ! grep -qs "${DEFAULT_MOUNT_POINT} " /proc/mounts; then
93+
retrycmd_if_failure 12 20 mount "${DEFAULT_MOUNT_POINT}" || exit 1
94+
fi
95+
}
96+
```
97+
6798
## Use DNS load balancing
6899

69100
This section explains the basics of configuring a DNS system to distribute client connections to all of the mount points on your Azure HPC Cache. This method doesn't account for the amount of traffic each client generates, but it does make sure that clients are evenly spread out over all of the cache's interfaces instead of just using one or two.

0 commit comments

Comments
 (0)