summaryrefslogtreecommitdiff
path: root/nlnet/task5/performance/start.sh
blob: 2cc917589a593c6e30658fd9265e5349c784bbc0 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash

# This script shows, via runnuing the benchmark, how
# the LibEuFin database connections are significantly
# shorter than the benchmark total time.

# For this reason, it can only be that LibEuFin opens
# and closes many PostgreSQL connections, as it is required
# by milestone #3.

set -eu

export HOW_MANY_WITHDRAWALS=100

service postgresql start
sudo -u postgres createuser -s root

# Activating the disconnection logs.
sudo -u postgres psql -q -c "ALTER SYSTEM SET log_disconnections = 'on'" -c "SELECT pg_reload_conf()" > /dev/null

# Converts AA:BB:CC.DDD to milliseconds.
convert_pg_time_to_ms () {
  awk -F[.:] '{SECS=(60*60*$1)+(60*$2)+$3; MILLI=$4; TOTAL_MS=(SECS*1000)+MILLI; print TOTAL_MS}'
}

createdb talercheck
export LD_LIBRARY_PATH=/usr/local/lib

prepare_and_run () {
  taler-unified-setup.sh \
    -Wwemtns \
    -c /exchange/src/benchmark/benchmark-cs.conf \
    -u exchange-account-2 &> /check_ready.txt &
  # Wait that the prep. went through.
  echo -n Waiting the unified setup to complete..
  READY="NO"
  for i in `seq 100` true; do
    if grep -q "<<READY>>" /check_ready.txt; then
    READY="YES"
    break
    fi
    echo -n "."; sleep 1
  done
  
  if test $READY = "YES"; then
    echo "DONE"
  else
    cat /check_ready.txt
    echo FAIL
    exit 1
  fi

  echo Running the benchmark..
  taler-exchange-benchmark \
    -c /exchange/src/benchmark/benchmark-cs.conf.edited \
    -u exchange-account-2 \
    -L WARNING \
    -n 1 \
    -r $HOW_MANY_WITHDRAWALS
}

export -f prepare_and_run
/usr/bin/time -o /benchmark-wall-clock-time.txt --format=%e bash -c "prepare_and_run"

NEXUS_PID=$(cat /libeufin-nexus.pid)
SANDBOX_PID=$(cat /libeufin-sandbox.pid)

if test -z $NEXUS_PID; then
  echo Could not find Nexus PID, failing.
  exit 1
fi

if test -z $SANDBOX_PID; then
  echo Could not find Sandbox PID, failing.
  exit 1
fi

# Convert the wall clock time to milliseconds, to make
# it compatible with the format as GREPped through Postgres logs.
BENCHMARK_TOT_MS=$(awk -F. '{t=($1 * 1000 + $2 * 10)} END {print t}' /benchmark-wall-clock-time.txt)

NEXUS_LONGEST_DB_SESSION_MS=$(grep disconnection < /var/log/postgresql/postgresql-15-main.log   | grep $NEXUS_PID | grep -o "session time:.*$" | grep -o [0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9][0-9][0-9] | convert_pg_time_to_ms | sort -n | tail -n 1)

SANDBOX_LONGEST_DB_SESSION_MS=$(grep disconnection < /var/log/postgresql/postgresql-15-main.log   | grep $SANDBOX_PID | grep -o "session time:.*$" | grep -o [0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9][0-9][0-9] | convert_pg_time_to_ms | sort -n | tail -n 1)

if test $NEXUS_LONGEST_DB_SESSION_MS -gt $BENCHMARK_TOT_MS; then
  echo Nexus had a DB session longer than the benchmark itself, failing.
  exit 1
fi

if test $SANDBOX_LONGEST_DB_SESSION_MS -gt $BENCHMARK_TOT_MS; then
  echo Sandbox had a DB session longer than the benchmark itself, failing.
  exit 1
fi

NEXUS_TIME_PORTION=$(echo "($NEXUS_LONGEST_DB_SESSION_MS / $BENCHMARK_TOT_MS) * 100" | bc -lq | sed 's/^\./0./')
SANDBOX_TIME_PORTION=$(echo "($SANDBOX_LONGEST_DB_SESSION_MS / $BENCHMARK_TOT_MS) * 100" | bc -lq | sed 's/^\./0./')

# Here: the further from 1 the better.
echo Nexus longest DB session is $NEXUS_TIME_PORTION percent of the total benchmark time.
echo Sandbox longest DB session is $SANDBOX_TIME_PORTION percent of the total benchmark time.

# Now show the total space occupied by the database.
# Although that's a _total_ estimate, it'll anyhow show
# that _also_ libeufin has reasonable data usage.
TOTAL_DB_SPACE=$(echo "SELECT pg_size_pretty(pg_database_size('talercheck'))" | psql -d talercheck | grep "^ [0-9]" | tr -d "[:blank:]")
echo "The total space occupied by the database for $HOW_MANY_WITHDRAWALS withdrawals is $TOTAL_DB_SPACE"