Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 1325b58

Browse files
committed
use grafana dashboard for benchmarks
Signed-off-by: Sahil Yeole <[email protected]>
1 parent d5e8c9b commit 1325b58

File tree

7 files changed

+49
-81
lines changed

7 files changed

+49
-81
lines changed

.github/workflows/bench.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ jobs:
1818
if: github.event.head_commit.message != 'Update performance results in README.md'
1919
env:
2020
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21-
K6_CLOUD_API_TOKEN: ${{ secrets.K6_CLOUD_API_TOKEN }}
21+
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }}
22+
INFLUXDB_TOKEN: ${{ secrets.INFLUXDB_TOKEN }}
23+
INFLUXDB_ORG: ${{ secrets.INFLUXDB_ORG }}
24+
INFLUXDB_URL: ${{ secrets.INFLUXDB_URL }}
2225
steps:
2326
- name: Checkout (GitHub)
2427
uses: actions/checkout@v4
@@ -35,15 +38,18 @@ jobs:
3538
- name: Setup k6
3639
uses: grafana/setup-k6-action@v1
3740

38-
- name: Setup k6 cloud environment
41+
- name: Setup influxdb-cli
3942
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
4043
run: |
41-
if [ -z "$K6_CLOUD_API_TOKEN" ]; then
42-
echo "K6_CLOUD_API_TOKEN is not set, results will not be uploaded to k6 cloud"
43-
else
44-
k6 login cloud --token $K6_CLOUD_API_TOKEN
45-
echo "IS_K6_CLOUD_ENABLED=true" >> $GITHUB_ENV
46-
fi
44+
echo "UPLOAD_TO_CLOUD=true" >> $GITHUB_ENV
45+
mkdir -p influxdb
46+
cd influxdb
47+
wget https://download.influxdata.com/influxdb/releases/influxdb2-client-2.7.5-linux-amd64.tar.gz
48+
tar xvzf influxdb2-client-2.7.5-linux-amd64.tar.gz
49+
cp influx /usr/local/bin/
50+
influx config create --config-name benchmark --host-url $INFLUXDB_URL --org $INFLUXDB_ORG --token $INFLUXDB_TOKEN --active
51+
cd ..
52+
rm -rf influxdb
4753
4854
- name: Run benchmarks
4955
run: |

analyze.sh

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ for idx in "${!servers[@]}"; do
4141
avgLatencies[${servers[$idx]}]=$(average "${latencyVals[@]}")
4242
done
4343

44-
# Generating data files for gnuplot
45-
reqSecData="/tmp/reqSec.dat"
46-
latencyData="/tmp/latency.dat"
47-
4844
echo "Server Value" >"$reqSecData"
4945
for server in "${servers[@]}"; do
5046
echo "$server ${avgReqSecs[$server]}" >>"$reqSecData"
@@ -62,36 +58,6 @@ elif [[ $1 == bench3* ]]; then
6258
whichBench=3
6359
fi
6460

65-
reqSecHistogramFile="req_sec_histogram${whichBench}.png"
66-
latencyHistogramFile="latency_histogram${whichBench}.png"
67-
68-
# Plotting using gnuplot
69-
gnuplot <<-EOF
70-
set term pngcairo size 1280,720 enhanced font "Courier,12"
71-
set output "$reqSecHistogramFile"
72-
set style data histograms
73-
set style histogram cluster gap 1
74-
set style fill solid border -1
75-
set xtics rotate by -45
76-
set boxwidth 0.9
77-
set title "Requests/Sec"
78-
stats "$reqSecData" using 2 nooutput
79-
set yrange [0:STATS_max*1.2]
80-
set key outside right top
81-
plot "$reqSecData" using 2:xtic(1) title "Req/Sec"
82-
83-
set output "$latencyHistogramFile"
84-
set title "Latency (in ms)"
85-
stats "$latencyData" using 2 nooutput
86-
set yrange [0:STATS_max*1.2]
87-
plot "$latencyData" using 2:xtic(1) title "Latency"
88-
EOF
89-
90-
# Move PNGs to assets
91-
mkdir -p assets
92-
mv $reqSecHistogramFile assets/
93-
mv $latencyHistogramFile assets/
94-
9561
# Declare an associative array for server RPS
9662
declare -A serverRPS
9763

@@ -120,6 +86,11 @@ fi
12086
for server in "${sortedServers[@]}"; do
12187
formattedReqSecs=$(printf "%.2f" ${avgReqSecs[$server]} | perl -pe 's/(?<=\d)(?=(\d{3})+(\.\d*)?$)/,/g')
12288
formattedLatencies=$(printf "%.2f" ${avgLatencies[$server]} | perl -pe 's/(?<=\d)(?=(\d{3})+(\.\d*)?$)/,/g')
89+
echo "Writing to influx for $server and benchmark $whichBench with ${avgReqSecs[$server]} and ${avgLatencies[$server]}"
90+
influx write -b bench "
91+
http_reqs,test_name=$server,benchmark=$whichBench value=${avgReqSecs[$server]}
92+
latency,test_name=$server,benchmark=$whichBench value=${avgLatencies[$server]}
93+
"
12394
# Calculate the relative performance
12495
relativePerformance=$(echo "${avgReqSecs[$server]} $lastServerReqSecs" | awk '{printf "%.2f", $1 / $2}')
12596

@@ -154,10 +125,6 @@ if [[ $whichBench == 3 ]]; then
154125
fi
155126
fi
156127

157-
# Move the generated images to the assets folder
158-
mv $reqSecHistogramFile assets/
159-
mv $latencyHistogramFile assets/
160-
161128
# Delete the result TXT files
162129
for file in "${resultFiles[@]}"; do
163130
rm "$file"

k6/bench.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ import http from 'k6/http';
22
import { check } from 'k6';
33

44
const whichBenchmark = Number(__ENV.BENCHMARK);
5-
const benchmarkName = whichBenchmark === 2 ? 'posts' : 'posts+users';
5+
const benchmarkName = whichBenchmark === 1 ? 'posts_users' : 2 ? 'posts' : 'greet';
6+
const duration = whichBenchmark === 1 ? '30' : '10';
67

78
export const options = {
89
scenarios: {
9-
posts: {
10+
[__ENV.TEST_NAME + '-' + benchmarkName]: {
1011
executor: 'constant-vus',
11-
duration: whichBenchmark === 2 ? '10s' : '30s',
12+
duration: duration+'s',
1213
gracefulStop: '0s',
1314
vus: 100,
14-
}
15-
},
16-
cloud: {
17-
name: __ENV.TEST_NAME + '-' + benchmarkName,
15+
},
1816
},
1917
};
2018

@@ -31,7 +29,7 @@ export default function() {
3129
const payload = JSON.stringify({
3230
operationName: null,
3331
variables: {},
34-
query: whichBenchmark === 2 ? '{posts{title}}' : '{posts{id,userId,title,user{id,name,email}}}',
32+
query: whichBenchmark === 1 ? '{posts{id,userId,title,user{id,name,email}}}' : 2 ? '{posts{title}}' : '{greet}',
3533
});
3634

3735
const res = http.post(url, payload, params);
@@ -41,7 +39,7 @@ export default function() {
4139
}
4240

4341
export function handleSummary(data) {
44-
const requestCount = data.metrics.http_reqs.values.count;
42+
const requestCount = (data.metrics.http_reqs.values.count/duration).toFixed(0);
4543
const avgLatency = Math.round(data.metrics.http_req_duration.values.avg * 100) / 100;
4644
const requestCountMessage = `Requests/sec: ${requestCount}\n`;
4745
const latencyMessage = `Latency: ${avgLatency} ms\n`;

k6/bench.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
graphql_endpoint=$1
2-
type=$2
3-
test_name=$3
4-
benchmark=$4
2+
test_name=$2
3+
benchmark=$3
54

6-
if [ "$IS_K6_CLOUD_ENABLED" == "true" ] && [ "$type" == "upload" ]; then
7-
k6 run k6/bench.js --quiet --out cloud --env TEST_NAME=$test_name --env BENCHMARK=$benchmark --env GRAPHQL_ENDPOINT=$graphql_endpoint
8-
else
9-
k6 run k6/bench.js --quiet --env TEST_NAME=$test_name --env BENCHMARK=$benchmark --env GRAPHQL_ENDPOINT=$graphql_endpoint
10-
fi
5+
k6 run k6/bench.js --env TEST_NAME=$test_name --env BENCHMARK=$benchmark --env GRAPHQL_ENDPOINT=$graphql_endpoint --quiet

run_benchmarks.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ sh nginx/run.sh
2121
function runBenchmark() {
2222
killServerOnPort 8000
2323
sleep 5
24-
local serviceScript="$1"
24+
local service="$1"
25+
local serviceScript="graphql/${service}/run.sh"
2526
local benchmarks=(1 2 3)
2627

2728
if [[ "$service" == "hasura" ]]; then
@@ -45,7 +46,7 @@ function runBenchmark() {
4546

4647
local resultFiles=("result1_${sanitizedServiceScriptName}.txt" "result2_${sanitizedServiceScriptName}.txt" "result3_${sanitizedServiceScriptName}.txt")
4748

48-
bash "test_query${bench}.sh" "$graphqlEndpoint"
49+
bash "test_query${bench}.sh" "$graphqlEndpoint"
4950

5051
# Warmup run
5152
bash "$benchmarkScript" "$graphqlEndpoint" "$bench" >/dev/null
@@ -58,7 +59,7 @@ function runBenchmark() {
5859
# 3 benchmark runs
5960
for resultFile in "${resultFiles[@]}"; do
6061
echo "Running benchmark $bench for $serviceScript"
61-
bash "$benchmarkScript" "$graphqlEndpoint" "$bench" >"bench${bench}_${resultFile}"
62+
bash "$benchmarkScript" "$graphqlEndpoint" "$service" "$bench" > "bench${bench}_${resultFile}"
6263
if [ "$bench" == "1" ]; then
6364
bench1Results+=("bench1_${resultFile}")
6465
elif [ "$bench" == "2" ]; then
@@ -73,7 +74,7 @@ function runBenchmark() {
7374
rm "results.md"
7475

7576
for service in "apollo_server" "caliban" "netflix_dgs" "gqlgen" "tailcall" "async_graphql" "hasura" "graphql_jit"; do
76-
runBenchmark "graphql/${service}/run.sh"
77+
runBenchmark "$service"
7778
if [ "$service" == "apollo_server" ]; then
7879
cd graphql/apollo_server/
7980
npm stop
@@ -86,3 +87,18 @@ done
8687
bash analyze.sh "${bench1Results[@]}"
8788
bash analyze.sh "${bench2Results[@]}"
8889
bash analyze.sh "${bench3Results[@]}"
90+
91+
if [[ "$UPLOAD_TO_CLOUD" == "true" ]]; then
92+
# Wait for 5 seconds to ensure the results are uploaded to influxdb
93+
sleep 5
94+
95+
# Get rendered panels from grafana
96+
from=$(date -u -d "-30 minutes" +"%Y-%m-%dT%H:%M:%S.%3NZ")
97+
now=$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")
98+
curl -o assets/posts_users_req.png -H "Authorization: Bearer $GRAFANA_API_KEY" "https://tailcall.grafana.net/render/d-solo/cdqucydulbfggb?tab=queries&from=$from&to=$now&panelId=panel-1&__feature.dashboardSceneSolo&width=1000&height=500&tz=Asia%2FCalcutta" --connect-timeout 120
99+
curl -o assets/posts_users_latency.png -H "Authorization: Bearer $GRAFANA_API_KEY" "https://tailcall.grafana.net/render/d-solo/cdqucydulbfggb?tab=queries&from=$from&to=$now&panelId=panel-2&__feature.dashboardSceneSolo&width=1000&height=500&tz=Asia%2FCalcutta" --connect-timeout 120
100+
curl -o assets/posts_req.png -H "Authorization: Bearer $GRAFANA_API_KEY" "https://tailcall.grafana.net/render/d-solo/cdqucydulbfggb?tab=queries&from=$from&to=$now&panelId=panel-3&__feature.dashboardSceneSolo&width=1000&height=500&tz=Asia%2FCalcutta" --connect-timeout 120
101+
curl -o assets/posts_latency.png -H "Authorization: Bearer $GRAFANA_API_KEY" "https://tailcall.grafana.net/render/d-solo/cdqucydulbfggb?tab=queries&from=$from&to=$now&panelId=panel-4&__feature.dashboardSceneSolo&width=1000&height=500&tz=Asia%2FCalcutta" --connect-timeout 120
102+
curl -o assets/greet_req.png -H "Authorization: Bearer $GRAFANA_API_KEY" "https://tailcall.grafana.net/render/d-solo/cdqucydulbfggb?tab=queries&from=$from&to=$now&panelId=panel-5&__feature.dashboardSceneSolo&width=1000&height=500&tz=Asia%2FCalcutta" --connect-timeout 120
103+
curl -o assets/greet_latency.png -H "Authorization: Bearer $GRAFANA_API_KEY" "https://tailcall.grafana.net/render/d-solo/cdqucydulbfggb?tab=queries&from=$from&to=$now&panelId=panel-6&__feature.dashboardSceneSolo&width=1000&height=500&tz=Asia%2FCalcutta" --connect-timeout 120
104+
fi

wrk/bench.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

wrk/wrk3.lua

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)