summaryrefslogtreecommitdiff
path: root/nlnet/task5/performance/start.sh
diff options
context:
space:
mode:
Diffstat (limited to 'nlnet/task5/performance/start.sh')
-rwxr-xr-xnlnet/task5/performance/start.sh107
1 files changed, 107 insertions, 0 deletions
diff --git a/nlnet/task5/performance/start.sh b/nlnet/task5/performance/start.sh
new file mode 100755
index 0000000..2cc9175
--- /dev/null
+++ b/nlnet/task5/performance/start.sh
@@ -0,0 +1,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"