CoolFace
Apppublic

Hobson/mathtext-fastapi

sourceHugging Faceagpl-3.0updated 3y agoView on Hugging Face
1likes
api_scaling.sh84 linesDownload Raw Back to scripts
1#! /bin/env bash2 3LOG_FILE_NAME="call_history_bash.csv"4 5if [[ ! -f "$LOG_FILE_NAME" ]]; then6  # Creation of column names if the file does not exits7  echo "student_id;active_students;endpoint;inputs;outputs;started;finished" >$LOG_FILE_NAME8fi9 10data_list_1() {11  responses=(12    "one hundred forty five"13    "twenty thousand nine hundred fifty"14    "one hundred forty five"15    "nine hundred eighty three"16    "five million"17  )18  echo "${responses[$1]}"19}20 21data_list_2() {22  responses=(23    "Totally agree"24    "I like it"25    "No more"26    "I am not sure"27    "Never"28  )29  echo "${responses[$1]}"30}31 32# endpoints: "text2int" "sentiment-analysis"33# selected endpoint to test34endpoint="sentiment-analysis"35 36create_random_delay() {37  # creates a random delay for given arguments38  echo "scale=8; $RANDOM/32768*$1" | bc39}40 41simulate_student() {42  # Student simulator waits randomly between 0-10s after an interaction.43  # Based on 100 interactions per student44  for i in {1..100}; do45 46    random_value=$((RANDOM % 5))47    text=$(data_list_2 $random_value)48    data='{"data": ["'$text'"]}'49 50    start_=$(date +"%F %T.%6N")51 52    url="https://tangibleai-mathtext-fastapi.hf.space/$3"53    response=$(curl --silent --connect-timeout 30 --max-time 30 -X POST "$url" -H 'Content-Type: application/json' -d "$data")54 55    if [[ "$response" == *"Time-out"* ]]; then56      echo "$response" >>bad_response.txt57      response="504 Gateway Time-out"58    elif [[ -z "$response" ]]; then59      echo "No response" >>bad_response.txt60      response="504 Gateway Time-out"61    fi62 63    end_=$(date +"%F %T.%6N")64 65    printf "%s;%s;%s;%s;%s;%s;%s\n" "$1" "$2" "$3" "$data" "$response" "$start_" "$end_" >>$LOG_FILE_NAME66    sleep "$(create_random_delay 10)"67 68  done69}70 71echo "start: $(date)"72 73active_students=250 # the number of students using the system at the same time74 75i=176while [[ "$i" -le "$active_students" ]]; do77  simulate_student "student$i" "$active_students" "$endpoint" &78  sleep "$(create_random_delay 1)" # adding a random delay between students79  i=$(("$i" + 1))80done81 82wait83echo "end: $(date)"84