File size: 1,900 Bytes
72f4be8
 
43ac953
 
 
 
 
 
 
 
72f4be8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43ac953
 
 
72f4be8
43ac953
 
 
72f4be8
 
 
43ac953
 
 
 
 
 
72f4be8
43ac953
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72f4be8
43ac953
 
 
72f4be8
 
 
43ac953
 
 
72f4be8
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /bin/env bash

LOG_FILE_NAME="call_history_bash.csv"

if [[ ! -f "$LOG_FILE_NAME" ]]; then
    # Creation of column names if the file does not exits
    echo "student_id;active_students;endpoint;inputs;outputs;started;finished" > $LOG_FILE_NAME
fi


data_list_1() {
  responses=(
    "one hundred forty five"
    "twenty thousand nine hundred fifty"
    "one hundred forty five"
    "nine hundred eighty three"
    "five million"
  )
  echo "${responses[$1]}"
}

data_list_2() {
  responses=(
    "Totally agree"
    "I like it"
    "No more"
    "I am not sure"
    "Never"
  )
  echo "${responses[$1]}"
}

# endpoints: "text2int" "text2int-preprocessed" "sentiment-analysis"
# selected endpoint to test
endpoint="text2int"

create_random_delay () {
  # creates a random delay for given arguments
  echo "scale=8; $RANDOM/32768*$1" | bc
}


simulate_student() {
  # Student simulator waits randomly between 0-10s after an interaction.
  # Based on 100 interactions per student
  for i in {1..100}; do
    start_=$(date +"%F %T.%6N")
    url="https://tangibleai-mathtext.hf.space/run/$3"

    response=$(curl --silent -X POST "$url" -H 'Content-Type: application/json' -d "$4")

    if [[ "$response" == *"504"* ]]; then
      response="504 Gateway Time-out"
    fi

    end_=$(date +"%F %T.%6N")
    printf "%s;%s;%s;%s;%s;%s;%s\n" "$1" "$2" "$3" "$4" "$response" "$start_" "$end_" >>$LOG_FILE_NAME
    sleep "$(create_random_delay 10)"
  done
}

echo "start: $(date)"

active_students=250  # the number of students using the system at the same time

i=1
while [[ "$i" -le "$active_students" ]]
do
  random_value=$((RANDOM % 5))
  text=$(data_list_2 $random_value)
  data='{"data": ["'$text'"]}'
  simulate_student "student$i" "$active_students" "$endpoint" "$data" &
  sleep "$(create_random_delay 1)"  # adding a random delay between students
  i=$(( "$i" + 1 ))
done

wait
echo "end: $(date)"