diff --git a/.github/workflows/scripts/benchmark/Dockerfile b/.github/workflows/scripts/benchmark/Dockerfile new file mode 100644 index 000000000..3eeb834c8 --- /dev/null +++ b/.github/workflows/scripts/benchmark/Dockerfile @@ -0,0 +1,28 @@ +FROM node:18 + +# Define build-time arguments + +ARG input_indexer_version +ENV INDEXER_VERSION=${input_indexer_version} + +ENV DB_USER=postgres +ENV DB_PASS=postgres +ENV DB_DATABASE=postgres +ENV DB_HOST=postgres +ENV DB_PORT=5432 + +# Set the working directory in the container +WORKDIR /app + +# Install app dependencies +RUN npm i @subql/node-cosmos@$INDEXER_VERSION -g + +# Copy the rest of the app's code to the container +COPY . . + +# Custom script to run the Node.js app and handle other tasks +COPY benchmarking.sh /app/benchmarking.sh +RUN chmod +x /app/benchmarking.sh + +# Set the entrypoint to the script +ENTRYPOINT ["/bin/bash", "/app/benchmarking.sh"] diff --git a/.github/workflows/scripts/benchmark/benchmarking.sh b/.github/workflows/scripts/benchmark/benchmarking.sh new file mode 100755 index 000000000..8c7cde42f --- /dev/null +++ b/.github/workflows/scripts/benchmark/benchmarking.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Get input parameters passed from the GitHub Action workflow +# Testing time +input_duration=$1 +input_deployment=$2 +input_endpoint=$3 +input_batch_size=$4 +input_workers=$5 +input_disableHistorical=$6 +input_others=$7 + +# Start the Node.js app in the background and save its PID +subql-node-cosmos -f ipfs://$input_deployment --network-endpoint=$input_endpoint --batch-size=$input_batch_size --workers=$input_workers --disable-historical=$input_disableHistorical $input_others --ipfs='https://unauthipfs.subquery.network/ipfs/api/v0' --db-schema=app | sed "s|${input_endpoint}|***|g" > output/benchmark/indexing.log 2>&1 & + +APP_PID=$! + +echo "Benchmarking, please wait $input_duration." +# Wait for timeout +sleep $input_duration + +# Terminate the Node.js app +pkill -P $APP_PID || true diff --git a/.github/workflows/scripts/benchmark/cleanHistory.sh b/.github/workflows/scripts/benchmark/cleanHistory.sh new file mode 100644 index 000000000..3fc5e6ffc --- /dev/null +++ b/.github/workflows/scripts/benchmark/cleanHistory.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +output_dir=$1 + +if [ -d "$output_dir" ]; then + echo "Removing existing directory: $output_dir" + rm -rf "$output_dir" +fi +# Create the new directory +echo "Creating new directory: ${PWD}/$output_dir" +mkdir -p "$output_dir" diff --git a/.github/workflows/scripts/benchmark/queryMeta.sh b/.github/workflows/scripts/benchmark/queryMeta.sh new file mode 100644 index 000000000..304357c72 --- /dev/null +++ b/.github/workflows/scripts/benchmark/queryMeta.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +input_duration=$1 + +# Function to convert time string to seconds +t2s() { + sed 's/d/*24*3600 +/g; s/h/*3600 +/g; s/m/*60 +/g; s/s/\+/g; s/+[ ]*$//g' <<< "$1" | bc +} + +# Query the database and store the result in variables +runner_node=$(psql -h postgres -d postgres -U postgres -c "SELECT value FROM app._metadata WHERE key = 'runnerNode';" | awk 'NR == 3 {print $1}' | tr -d '"') +indexer_version=$(psql -h postgres -d postgres -U postgres -c "SELECT value FROM app._metadata WHERE key = 'indexerNodeVersion';" | awk 'NR == 3 {print $1}' | tr -d '"') +start_height=$(psql -h postgres -d postgres -U postgres -c "SELECT value::integer FROM app._metadata WHERE key = 'startHeight';" | awk 'NR == 3 {print $1}') +last_processed_height=$(psql -h postgres -d postgres -U postgres -c "SELECT value::integer FROM app._metadata WHERE key = 'lastProcessedHeight';" | awk 'NR == 3 {print $1}') +total_height=$((last_processed_height-start_height+1)) +time_in_seconds=$(t2s "$input_duration") +bps=$(awk "BEGIN {printf \"%.2f\", $total_height / $time_in_seconds}") +# Set outputs for subsequent steps +echo "::set-output name=runner_node::$runner_node" +echo "::set-output name=indexer_version::$indexer_version" +echo "::set-output name=start_height::$start_height" +echo "::set-output name=last_processed_height::$last_processed_height" +echo "::set-output name=total_height::$total_height" +echo "::set-output name=bps::$bps"