Created
August 7, 2019 11:35
-
-
Save tolbrino/235297690657eb9a5aaf44d030e9b384 to your computer and use it in GitHub Desktop.
Testing sync performance of the aeternity node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
FOLDER="$1" | |
OUTPUT_FILE="${OUTPUT_FILE:-blocks_synced.csv}" | |
check() { | |
if [[ -z "${FOLDER}" ]]; then | |
echo "ERROR: Specify aeternity node folder as first parameter"; | |
exit 1 | |
fi | |
} | |
start_aeternity_node() { | |
cd "${FOLDER}" | |
if [[ -f "aeternity.exe" ]]; then | |
./aeternity.exe & | |
else | |
./bin/aeternity start | |
fi | |
} | |
get_block_number() { | |
local FILE="$1" | |
local BLOCK=$(cat "${FILE}" | grep 'Synced blocks' | tail -n 1 | cut -d- -f 4) | |
echo ${BLOCK} | |
} | |
determine_block() { | |
local BLOCKS=$(for f in ./log/aeternity_sync.log*; do get_block_number "${f}"; done) | |
local HIGHEST_BLOCK=0 | |
for B in ${BLOCKS[@]}; do | |
if (( ${B} > ${HIGHEST_BLOCK} )); then | |
HIGHEST_BLOCK=${B} | |
fi | |
done | |
echo ${HIGHEST_BLOCK} | |
} | |
write_block() { | |
local BLOCK=$1 | |
local TIMESTAMP=$2 | |
if (( ${BLOCK} > 0 )); then | |
echo "${TIMESTAMP}, ${BLOCK}" >> "${OUTPUT_FILE}" | |
echo "wrote ${TIMESTAMP}, ${BLOCK} to ${OUTPUT_FILE}" | |
else | |
echo "found no block during timestamp ${TIMESTAMP}" | |
fi | |
} | |
determine_timestamp() { | |
local TIMESTAMP=0 | |
if [[ -f "${OUTPUT_FILE}" ]]; then | |
TIMESTAMP=$(cat "${OUTPUT_FILE}" | tail -n 1 | cut -d, -f 1) | |
fi | |
if [[ -z "${TIMESTAMP}" ]]; then | |
TIMESTAMP=0 | |
fi | |
echo ${TIMESTAMP} | |
} | |
measure_loop() { | |
local TIMESTAMP=$(determine_timestamp) | |
while true; do | |
local SYNCED_BLOCK=$(determine_block) | |
write_block ${SYNCED_BLOCK} ${TIMESTAMP} | |
sleep 10 | |
TIMESTAMP=$(( ${TIMESTAMP} + 10 )) | |
done | |
} | |
main() { | |
check | |
start_aeternity_node | |
measure_loop | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment