Skip to content

Commit

Permalink
add missing script for benchmark (#250)
Browse files Browse the repository at this point in the history
* add benchmark workflow

* add missing benchmark scripts
  • Loading branch information
bz888 committed Apr 19, 2024
1 parent a58b2c0 commit a4a3550
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/scripts/benchmark/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
23 changes: 23 additions & 0 deletions .github/workflows/scripts/benchmark/benchmarking.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions .github/workflows/scripts/benchmark/cleanHistory.sh
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 24 additions & 0 deletions .github/workflows/scripts/benchmark/queryMeta.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit a4a3550

Please sign in to comment.