Last active
February 19, 2018 13:54
-
-
Save groundnuty/2e00805f577c745a948b9ca8f92db79c to your computer and use it in GitHub Desktop.
bash redis barrier
This file contains hidden or 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
| # exec 3<>/dev/tcp/j-redis/6379 | |
| # printf %b "*2\r\n\$4\r\nINCR\r\n\$25\r\noneclients_ready_count\r\n" >&3 | |
| # read -r oneclients_ready_count <&3 | |
| # msg_in=$(printf %b "$oneclients_ready_count" | cut -f2 -d$ | tr -d '\r') | |
| # echo "oneclients_ready_count: <${oneclients_ready_count}>" | |
| # exec 3<>/dev/tcp/j-redis/6379 | |
| # printf %b "*2\r\n\$3\r\nGET\r\n\$23\r\noneclients_ready_count\r\n" >&3 | |
| # read -r oneclients_ready_count <&3 | |
| # read -r oneclients_ready_count <&3 | |
| # msg_in=$(printf %b "$oneclients_ready_count" | cut -f2 -d$ | tr -d '\r') | |
| # echo "oneclients_ready_count: <${oneclients_ready_count}>" | |
| # while [[ $msg_in -le 55 ]] ; do sleep 1; printf %b "*2\r\n\$3\r\nGET\r\n\$23\r\noneclients_ready_count\r\n" >&3 ; read -r oneclients_ready_count <&3 ; read -r msg_in <&3 ; oneclients_ready_count=$(printf %b "$oneclients_ready_count" | cut -f2 -d$ | tr -d '\r') ; echo "oneclients_ready_count: $oneclients_ready_count" ; done | |
| # echo "done!" | |
| command: | |
| - "bash" | |
| - "-c" | |
| - > | |
| printf "$(date)" ; echo "Opening port to redis server." ; | |
| exec 3<>/dev/tcp/${REDIS_HOST}/${REDIS_PORT} ; | |
| printf "$(date)" ; echo "/dev/tcp/${REDIS_HOST}/${REDIS_PORT}" ; | |
| printf "$(date)" ; echo "Waiting for this pod to reach a compute point." ; | |
| while [ ! -f /monitor/wait-for-compute-barrier ] ; do sleep 2 ; done ; | |
| oneclients_ready_count="" ; | |
| while : ; do printf %b "*2\r\n\$4\r\nINCR\r\n\$22\r\noneclients_ready_count\r\n" >&3 ; | |
| read -r oneclients_ready_count <&3 ; | |
| oneclients_ready_count=$(printf %b "$oneclients_ready_count" | cut -f2 -d$ | tr -d "\r:\'") ; | |
| printf "$(date)" ; echo "Redy count increased. oneclients_ready_count: <${oneclients_ready_count}>" ; | |
| [ oneclients_ready_count = "" ] && sleep 1 || break ; | |
| done ; | |
| oneclients_ready_count="" ; | |
| while : ; do printf %b "*2\r\n\$3\r\nGET\r\n\$22\r\noneclients_ready_count\r\n" >&3 ; | |
| read -r oneclients_ready_count <&3 ; | |
| read -r oneclients_ready_count <&3 ; | |
| oneclients_ready_count=$(printf %b "$oneclients_ready_count" | cut -f2 -d$ | tr -d "\r:\'") ; | |
| printf "$(date)" ; echo "Redy count is oneclients_ready_count: <${oneclients_ready_count}>" ; | |
| [ oneclients_ready_count = "" ] && sleep 1 || break ; | |
| done ; | |
| printf "$(date)" ; echo "Waiting for all ($TOTAL_JOBS_COUNT) pods to reach a compute point." ; | |
| while [[ $oneclients_ready_count -lt $TOTAL_JOBS_COUNT ]] ; do sleep 1; | |
| oneclients_ready_count="" ; | |
| while : ; do printf %b "*2\r\n\$3\r\nGET\r\n\$22\r\noneclients_ready_count\r\n" >&3 ; | |
| read -r oneclients_ready_count <&3 ; read -r oneclients_ready_count <&3 ; | |
| oneclients_ready_count=$(printf %b "$oneclients_ready_count" | cut -f2 -d$ | tr -d "\r:\'") ; | |
| echo "oneclients_ready_count: <$oneclients_ready_count> is less then $TOTAL_JOBS_COUNT" ; | |
| [ oneclients_ready_count = "" ] && sleep || break ; | |
| done ; | |
| done ; | |
| while : ; do printf %b "*2\r\n\$3\r\nGET\r\n\$22\r\noneclients_ready_count\r\n" >&3 ; | |
| read -r oneclients_ready_count <&3 ; | |
| read -r oneclients_ready_count <&3 ; | |
| oneclients_ready_count=$(printf %b "$oneclients_ready_count" | cut -f2 -d$ | tr -d "\r:\'") ; | |
| [ oneclients_ready_count = "" ] && sleep 1 || break ; | |
| done ; | |
| printf "$(date)" ; echo "All $TOTAL_JOBS_COUNT pods reached compute point." ; | |
| sleep 36000 ; | |
| echo 1 > /monitor/wait-for-all-jobs-barrier ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment