<commit_before>#!/bin/bash

# Demonstrate the scaling up and down of analysers in response to the
# length of the queue.

clear
echo "Starting one producer and one analyzer"
echo "======================================================================================="
echo ""
docker-compose scale producer=1
docker-compose scale analyzer=1
docker-compose up -d 
docker-compose ps

echo ""
read -p "Press [Enter] key to see the effect on the queue"
clear

echo "Output the status of the queue every 5 seconds"
echo "======================================================================================="
for i in {1..3}
do
    docker run -it rgardler/acs-logging-test-cli summary
    echo ""
    docker-compose ps
    echo "======================================================================================="
    echo ""
    sleep 5
done

echo "Notice how a number of the analyzers have stopped (queue length went to 0)"
echo "But, queue is starting to grow again"
read -p "Press [Enter] key to turn on an auto-scaling algorithm"
clear 

for i in {1..10}
do
    length=$(docker run -i rgardler/acs-logging-test-cli length)

    echo ""

    if [ "$length" -gt 50 ]
    then
	echo "Queue is too long ($length)"
	docker-compose scale analyzer=10
    else 
	echo "Queue is an acceptable length ($length)"
    fi
    docker-compose ps
    echo "======================================================================================="
    echo ""
    sleep 5
done

<commit_msg>Add some more parameterization and make scaling a little more intelligent (more consumers for a longer queue)<commit_after>#!/bin/bash

# Demonstrate the scaling up and down of analysers in response to the
# length of the queue.

SCALE_SET_NAME=swarm-agent-94077C7vmss-0

PRODUCERS=1
MAX_PRODUCERS=20
ANALYZERS=1
MAX_ANALYZERS=100

STATUS_REPEATS=3
STATUS_DELAY=5

CONTAINER_SCALE_REPEATS=5
CONTAINER_SCALE_DELAY=5

clear
echo "Starting $PRODUCERS producer and $ANALYZERS analyzer"
echo "======================================================================================="
echo ""
docker-compose scale producer=$PRODUCERS
docker-compose scale analyzer=$ANALYZERS
docker-compose up -d 
docker-compose ps

echo ""
read -p "Press [Enter] key to see the effect on the queue"
clear

echo "Output the status of the queue every $STATUS_DELAY seconds"
echo "======================================================================================="
for i in $(seq "$STATUS_REPEATS")
do
    docker run -it rgardler/acs-logging-test-cli summary
    echo ""
    docker-compose ps
    echo "======================================================================================="
    echo ""
    sleep $STATUS_DELAY
done

echo "Notice how the queue is starting to grow again"
read -p "Press [Enter] key to turn on an auto-scaling algorithm"
clear 

for i in $(seq "$CONTAINER_SCALE_REPEATS")
do
    LENGTH=$(docker run -i rgardler/acs-logging-test-cli length)

    echo ""

    if [ "$LENGTH" -gt 50 ]
    then
	echo "Queue is too long ($LENGTH)"
	NUM_ANALYZERS=expr $LENGTH / 100
	if [ "$LENGTH" -gt "$MAX_ANALYZERS" ]
	then
	    case  in
	    esac
	    
	    NUM_ANALYZERS=$MAX_ANALYZERS
	fi
	echo "Scaling to $NUM_ANALYZERS"
	docker-compose scale analyzer=$NUM_ANALYZERS
    else 
	echo "Queue is an acceptable length ($length)"
    fi
    docker-compose ps
    echo "======================================================================================="
    echo ""
    sleep $CONTAINER_SCALE_DELAY
done

echo "That's all for our demo just now..."
{'fraction_non_alphanumeric': 0.2676136363636364, 'fraction_numerical': 0.010795454545454546, 'mean_word_length': 4.544881889763779, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4457909', 'n_tokens_mistral': 1099, 'n_tokens_neox': 964, 'n_words': 353}