bench_rest_api.sh
1 #!/bin/bash 2 3 ########################################################### 4 # Measures the performance of a node's REST API 5 ########################################################### 6 7 set -eo pipefail # error on any command failure 8 9 network_id=1 10 11 # The size of the validator set. 12 num_validators=40 13 14 # Adjust this to show more/less log messages 15 log_filter="info,snarkos_node_sync=debug,snarkos_node_tcp=warn,snarkos_node_rest=warn" 16 17 #shellcheck source=SCRIPTDIR/utils.sh 18 . ./.ci/utils.sh 19 20 branch_name=$(git rev-parse --abbrev-ref HEAD) 21 echo "On branch: ${branch_name}" 22 23 network_name=$(get_network_name $network_id) 24 echo "Using network: $network_name (ID: $network_id)" 25 26 snapshot_info=$(<info.txt) 27 echo "Snapshot_info: ${snapshot_info}" 28 29 # Create log directory 30 log_dir=".logs-$(date +"%Y%m%d%H%M%S")" 31 mkdir -p "$log_dir" 32 33 # Define a trap handler that cleans up all processes on exit. 34 trap stop_nodes EXIT 35 36 # Define a trap handler that prints a message when an error occurs. 37 trap 'echo "⛔️ Error in $BASH_SOURCE at line $LINENO: \"$BASH_COMMAND\" failed (exit $?)"' ERR 38 39 # Shared flags between all nodes 40 common_flags=( 41 --nodisplay --nobanner --noupdater # reduce clutter in the output 42 "--log-filter=$log_filter" # only show the logs we care about 43 "--network=$network_id" 44 --nocdn # don't sync from CDN, so we only benchmark p2p sync 45 "--dev-num-validators=$num_validators" 46 "--dev-num-clients=0" # no clients, so no need to populate the validators list 47 "--no-dev-txs" # disable developemnt transaction generation 48 --rest-rps=1000000 # ensure benchmarks don't fail due to rate limiting 49 ) 50 51 # The node that has the ledger (runs on the first two cores) 52 $TASKSET1 snarkos start --dev 0 --validator "${common_flags[@]}" \ 53 --logfile="$log_dir/validator-0.log" --validators="127.0.0.1:5001"& # the node will populate the validators list, if not at least one is set. 54 PIDS[0]=$! 55 56 # Block until node is running. 57 wait_for_nodes 0 1 58 59 python ./.ci/rest_api_helper.py "get-block" "$CORES_PER_NODE" 60 60 python ./.ci/rest_api_helper.py "block-height" "$CORES_PER_NODE" 10000 61 python ./.ci/rest_api_helper.py "get-latest-block" "$CORES_PER_NODE" 100 62 63 exit 0