-
Notifications
You must be signed in to change notification settings - Fork 0
1173 lines (1049 loc) · 46.1 KB
/
benchmark.yml
File metadata and controls
1173 lines (1049 loc) · 46.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: Benchmark
run-name: Benchmark Run ${{ github.run_number }}
on:
schedule:
# Daily at 21:00 UTC
- cron: '0 21 * * *'
workflow_dispatch:
inputs:
gateway:
description: 'Gateway to benchmark'
required: false
default: 'all'
type: choice
options:
- all
- apollo-gateway
- apollo-router
- cosmo
- grafbase
- hive-gateway
- hive-gateway-router-runtime
- hive-router
- hotchocolate
benchmark:
description: 'Benchmark mode'
required: false
default: 'all'
type: choice
options:
- all
- constant
- latency
- burst
runs:
description: 'Number of benchmark runs per gateway'
required: false
default: '9'
duration:
description: 'Duration per run in seconds'
required: false
default: '120'
diagnostic_run:
description: 'Diagnostic run (collect diagnostics artifacts, skip result documents)'
required: false
default: false
type: boolean
concurrency:
group: gateway-benchmarks
cancel-in-progress: false
permissions:
actions: read
contents: write
jobs:
prepare-matrix:
runs-on: ubuntu-latest
outputs:
gateways: ${{ steps.build.outputs.gateways }}
gateways_net: ${{ steps.build.outputs.gateways_net }}
gateway_builds: ${{ steps.build.outputs.gateway_builds }}
subgraph_builds: ${{ steps.build.outputs.subgraph_builds }}
is_diagnostic: ${{ steps.flags.outputs.is_diagnostic }}
should_publish: ${{ steps.flags.outputs.should_publish }}
run_constant: ${{ steps.flags.outputs.run_constant }}
run_burst: ${{ steps.flags.outputs.run_burst }}
run_latency: ${{ steps.flags.outputs.run_latency }}
steps:
- name: Compute run flags
id: flags
run: |
BENCHMARK="${{ inputs.benchmark || 'all' }}"
GATEWAY="${{ inputs.gateway || 'all' }}"
DIAGNOSTIC="${{ inputs.diagnostic_run }}"
IS_DIAGNOSTIC="false"
if [[ "$DIAGNOSTIC" == "true" ]]; then
IS_DIAGNOSTIC="true"
fi
SHOULD_PUBLISH="false"
if [[ "$GATEWAY" == "all" && "$BENCHMARK" == "all" && "$IS_DIAGNOSTIC" == "false" ]]; then
SHOULD_PUBLISH="true"
fi
RUN_CONSTANT="false"
if [[ "$BENCHMARK" == "all" || "$BENCHMARK" == "constant" ]]; then
RUN_CONSTANT="true"
fi
RUN_BURST="false"
if [[ "$BENCHMARK" == "all" || "$BENCHMARK" == "burst" ]]; then
RUN_BURST="true"
fi
RUN_LATENCY="false"
if [[ "$BENCHMARK" == "all" || "$BENCHMARK" == "latency" ]]; then
RUN_LATENCY="true"
fi
{
echo "is_diagnostic=$IS_DIAGNOSTIC"
echo "should_publish=$SHOULD_PUBLISH"
echo "run_constant=$RUN_CONSTANT"
echo "run_burst=$RUN_BURST"
echo "run_latency=$RUN_LATENCY"
} >> "$GITHUB_OUTPUT"
- name: Build gateway matrix
id: build
env:
SELECTED_GATEWAY: ${{ inputs.gateway || 'all' }}
run: |
python3 - <<'PY'
import json
import os
import sys
selected = os.environ.get("SELECTED_GATEWAY", "all")
aliases = {
"hc": "hotchocolate",
"hc-rust": "hotchocolate-rust",
"hc-net": "hotchocolate-net",
}
selected = aliases.get(selected, selected)
selected_gateway = selected
selected_subgraph_tech = None
if selected.endswith("-rust"):
selected_gateway = selected[:-5]
selected_subgraph_tech = "rust"
elif selected.endswith("-net"):
selected_gateway = selected[:-4]
selected_subgraph_tech = ".net"
base_gateways = [
{
"path": "apollo-federation/gateways/apollo-gateway",
"name": "apollo-gateway",
"gateway_artifact": "prebuilt-gateway-apollo-gateway",
},
{
"path": "apollo-federation/gateways/apollo-router",
"name": "apollo-router",
"gateway_artifact": "prebuilt-gateway-apollo-router",
},
{
"path": "apollo-federation/gateways/cosmo",
"name": "cosmo",
"gateway_artifact": "prebuilt-gateway-cosmo",
},
{
"path": "apollo-federation/gateways/grafbase",
"name": "grafbase",
"gateway_artifact": "prebuilt-gateway-grafbase",
},
{
"path": "apollo-federation/gateways/hive-gateway",
"name": "hive-gateway",
"gateway_artifact": "prebuilt-gateway-hive-gateway",
},
{
"path": "apollo-federation/gateways/hive-gateway-router-runtime",
"name": "hive-gateway-router-runtime",
"gateway_artifact": "prebuilt-gateway-hive-gateway-router-runtime",
},
{
"path": "apollo-federation/gateways/hive-router",
"name": "hive-router",
"gateway_artifact": "prebuilt-gateway-hive-router",
},
{
"path": "composite-schema/gateways/hotchocolate",
"name": "hotchocolate",
"gateway_artifact": "prebuilt-gateway-hotchocolate",
},
]
subgraph_variants_by_category = {
"apollo-federation": [
{
"dir": "subgraphs-rust",
"tech": "rust",
"artifact": "prebuilt-apollo-federation-subgraphs-rust",
"suffix": "rust",
},
{
"dir": "subgraphs-net",
"tech": ".net",
"artifact": "prebuilt-apollo-federation-subgraphs-net",
"suffix": "net",
},
],
"composite-schema": [
{
"dir": "subgraphs-rust",
"tech": "rust",
"artifact": "prebuilt-composite-schema-subgraphs-rust",
"suffix": "rust",
},
{
"dir": "subgraphs-net",
"tech": ".net",
"artifact": "prebuilt-composite-schema-subgraphs-net",
"suffix": "net",
},
],
}
gateways = []
for gateway in base_gateways:
category = gateway["path"].split("/", 1)[0]
variants = subgraph_variants_by_category.get(category, [])
for variant in variants:
gateways.append({
"path": gateway["path"],
"name": f"{gateway['name']}-{variant['suffix']}",
"base_name": gateway["name"],
"subgraphs": variant["dir"],
"subgraph_tech": variant["tech"],
"display_name": f"{gateway['name']} ({variant['tech']} subgraphs)",
"subgraphs_artifact": variant["artifact"],
"gateway_artifact": gateway["gateway_artifact"],
})
if selected == "all":
chosen = gateways
else:
chosen = [entry for entry in gateways if entry["base_name"] == selected_gateway]
if selected_subgraph_tech:
chosen = [entry for entry in chosen if entry["subgraph_tech"] == selected_subgraph_tech]
if not chosen:
print(f"Error: no gateway entries match selection {selected!r}", file=sys.stderr)
sys.exit(1)
matrix_json = json.dumps(chosen, separators=(",", ":"))
chosen_net = [e for e in chosen if e["subgraph_tech"] == ".net"]
matrix_net_json = json.dumps(chosen_net, separators=(",", ":"))
builds_by_artifact = {}
for entry in chosen:
artifact = entry["gateway_artifact"]
if artifact in builds_by_artifact:
continue
builds_by_artifact[artifact] = {
"path": entry["path"],
"artifact": artifact,
}
build_matrix_json = json.dumps(list(builds_by_artifact.values()), separators=(",", ":"))
subgraphs_by_artifact = {}
for entry in chosen:
artifact = entry["subgraphs_artifact"]
if artifact in subgraphs_by_artifact:
continue
category = entry["path"].split("/", 1)[0]
subgraphs_by_artifact[artifact] = {
"path": f"{category}/{entry['subgraphs']}",
"artifact": artifact,
}
subgraph_matrix_json = json.dumps(list(subgraphs_by_artifact.values()), separators=(",", ":"))
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fh:
fh.write(f"gateways={matrix_json}\n")
fh.write(f"gateways_net={matrix_net_json}\n")
fh.write(f"gateway_builds={build_matrix_json}\n")
fh.write(f"subgraph_builds={subgraph_matrix_json}\n")
print("Selected gateway entries:")
for entry in chosen:
print(f" - {entry['base_name']} [{entry['subgraph_tech']}]")
print("Subgraph builds:")
for sub in subgraphs_by_artifact.values():
print(f" - {sub['path']} ({sub['artifact']})")
PY
build-subgraphs:
needs: prepare-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
subgraphs: ${{ fromJson(needs.prepare-matrix.outputs.subgraph_builds) }}
name: build-${{ matrix.subgraphs.path }}
steps:
- uses: actions/checkout@v6
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5
with:
global-json-file: global.json
- name: Build subgraphs
run: |
chmod +x "${{ matrix.subgraphs.path }}/build.sh"
(cd "${{ matrix.subgraphs.path }}" && bash build.sh)
- name: Pack prebuilt subgraphs
run: |
tar -czf "prebuilt-subgraphs-${{ matrix.subgraphs.artifact }}.tar.gz" "${{ matrix.subgraphs.path }}"
- name: Upload prebuilt subgraphs
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.subgraphs.artifact }}
path: prebuilt-subgraphs-${{ matrix.subgraphs.artifact }}.tar.gz
build-gateways:
needs: prepare-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
gateway: ${{ fromJson(needs.prepare-matrix.outputs.gateway_builds) }}
name: build-${{ matrix.gateway.artifact }}
steps:
- uses: actions/checkout@v6
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5
with:
global-json-file: global.json
- name: Build gateway
run: |
chmod +x "${{ matrix.gateway.path }}/install.sh"
(cd "${{ matrix.gateway.path }}" && bash install.sh)
touch "${{ matrix.gateway.path }}/.prebuilt-gateway-ready"
- name: Pack prebuilt gateway
run: |
tar -czf "prebuilt-gateway-${{ matrix.gateway.artifact }}.tar.gz" "${{ matrix.gateway.path }}"
- name: Upload prebuilt gateway
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.gateway.artifact }}
path: prebuilt-gateway-${{ matrix.gateway.artifact }}.tar.gz
benchmark-constant:
needs:
- prepare-matrix
- build-subgraphs
- build-gateways
- benchmark-constant-latency
if: ${{ always() && !cancelled() && needs.prepare-matrix.outputs.run_constant == 'true' }}
strategy:
fail-fast: false
matrix:
gateway: ${{ fromJson(needs.prepare-matrix.outputs.gateways) }}
runs-on:
group: benchmarking-1
name: ${{ matrix.gateway.name }} (constant)
env:
BENCH_RUNS: ${{ inputs.runs || '9' }}
MEASURE_SECONDS: ${{ inputs.duration || '120' }}
steps:
- uses: actions/checkout@v6
- name: Download prebuilt gateway
uses: actions/download-artifact@v8
with:
name: ${{ matrix.gateway.gateway_artifact }}
path: prebuilt-gateway/
- name: Restore prebuilt gateway
run: |
GATEWAY_ARCHIVE="$(find prebuilt-gateway -type f -name '*.tar.gz' | head -n1)"
if [[ -z "$GATEWAY_ARCHIVE" ]]; then
echo "Error: prebuilt gateway archive not found"
find prebuilt-gateway -maxdepth 3 -print
exit 1
fi
tar -xzf "$GATEWAY_ARCHIVE" -C .
if [[ -f apollo-federation/gateways/apollo-router/router ]]; then
chmod +x apollo-federation/gateways/apollo-router/router
fi
if [[ -f apollo-federation/gateways/cosmo/cosmo ]]; then
chmod +x apollo-federation/gateways/cosmo/cosmo
fi
if [[ -f apollo-federation/gateways/grafbase/grafbase-gateway ]]; then
chmod +x apollo-federation/gateways/grafbase/grafbase-gateway
fi
if [[ -f apollo-federation/gateways/hive-router/hive_router ]]; then
chmod +x apollo-federation/gateways/hive-router/hive_router
fi
- name: Download prebuilt subgraphs
continue-on-error: true
uses: actions/download-artifact@v8
with:
name: ${{ matrix.gateway.subgraphs_artifact }}
path: prebuilt-subgraphs/
- name: Restore prebuilt subgraphs
env:
GH_TOKEN: ${{ github.token }}
GATEWAY_PATH: ${{ matrix.gateway.path }}
SUBGRAPHS_DIR: ${{ matrix.gateway.subgraphs }}
SUBGRAPHS_ARTIFACT: ${{ matrix.gateway.subgraphs_artifact }}
run: |
set -euo pipefail
find_subgraphs_archive() {
find prebuilt-subgraphs -type f -name '*.tar.gz' | head -n1
}
redownload_subgraphs_artifact() {
rm -rf prebuilt-subgraphs
mkdir -p prebuilt-subgraphs
gh run download "$GITHUB_RUN_ID" --repo "$GITHUB_REPOSITORY" --name "$SUBGRAPHS_ARTIFACT" --dir prebuilt-subgraphs
}
ATTEMPTS=3
for attempt in $(seq 1 "$ATTEMPTS"); do
SUBGRAPHS_ARCHIVE="$(find_subgraphs_archive)"
if [[ -z "$SUBGRAPHS_ARCHIVE" ]]; then
echo "Subgraphs archive not found (attempt $attempt/$ATTEMPTS)"
elif tar -tzf "$SUBGRAPHS_ARCHIVE" >/dev/null 2>&1; then
tar -xzf "$SUBGRAPHS_ARCHIVE" -C .
if [[ -f apollo-federation/subgraphs-rust/target/release/subgraphs ]]; then
chmod +x apollo-federation/subgraphs-rust/target/release/subgraphs
fi
if [[ -f composite-schema/subgraphs-rust/target/release/subgraphs ]]; then
chmod +x composite-schema/subgraphs-rust/target/release/subgraphs
fi
exit 0
else
echo "Subgraphs archive integrity check failed (attempt $attempt/$ATTEMPTS): $SUBGRAPHS_ARCHIVE"
ls -lh "$SUBGRAPHS_ARCHIVE" || true
fi
if [[ "$attempt" -lt "$ATTEMPTS" ]]; then
echo "Re-downloading artifact '$SUBGRAPHS_ARTIFACT' for retry..."
if ! redownload_subgraphs_artifact; then
echo "Artifact re-download failed (attempt $((attempt + 1))/$ATTEMPTS)."
fi
sleep $((attempt * 5))
fi
done
find prebuilt-subgraphs -maxdepth 3 -print || true
SUBGRAPHS_ROOT="${GATEWAY_PATH%%/*}"
SUBGRAPHS_PATH="${SUBGRAPHS_ROOT}/${SUBGRAPHS_DIR}"
echo "Archive restore failed after $ATTEMPTS attempts; falling back to local rebuild: $SUBGRAPHS_PATH"
if [[ ! -f "$SUBGRAPHS_PATH/build.sh" ]]; then
echo "Error: fallback build script not found: $SUBGRAPHS_PATH/build.sh"
exit 1
fi
chmod +x "$SUBGRAPHS_PATH/build.sh"
(cd "$SUBGRAPHS_PATH" && bash build.sh)
if [[ -f apollo-federation/subgraphs-rust/target/release/subgraphs ]]; then
chmod +x apollo-federation/subgraphs-rust/target/release/subgraphs
fi
if [[ -f composite-schema/subgraphs-rust/target/release/subgraphs ]]; then
chmod +x composite-schema/subgraphs-rust/target/release/subgraphs
fi
- name: Kill stale perfrunner processes
run: |
sudo pkill -u perfrunner || true
sleep 1
sudo pkill -9 -u perfrunner || true
- name: Prepare workspace for perfrunner
run: |
# Both users need write access during a run:
# - perfrunner writes dependency artifacts (node_modules, target, etc.)
# - github-runner writes benchmark outputs (results/, summaries)
sudo chmod -R a+rX,g+rwX .
sudo chown -R perfrunner:github-runner .
# Preserve github-runner as group owner for newly created files/dirs.
sudo find . -type d -exec chmod g+s {} +
- name: Prepare diagnostics directory
if: ${{ needs.prepare-matrix.outputs.is_diagnostic == 'true' }}
run: |
mkdir -p "${{ matrix.gateway.path }}/diagnostics"
{
echo "diagnostic_run=true"
echo "mode=constant"
echo "gateway=${{ matrix.gateway.name }}"
echo "started_utc=${{ github.run_started_at || 'n/a' }}"
echo "run_id=${{ github.run_id }}"
} > "${{ matrix.gateway.path }}/diagnostics/run-info.txt"
sudo chown -R perfrunner:github-runner "${{ matrix.gateway.path }}/diagnostics"
sudo chmod -R u+rwX,g+rwX "${{ matrix.gateway.path }}/diagnostics"
- name: Run benchmark
run: ./k6/benchmark.sh ${{ matrix.gateway.path }} ${{ matrix.gateway.subgraphs }} constant
env:
BENCH_DISPLAY_NAME: ${{ matrix.gateway.display_name || '' }}
BENCH_SUBGRAPH_TECH: ${{ matrix.gateway.subgraph_tech || '' }}
BENCH_DIAGNOSTIC_RUN: ${{ needs.prepare-matrix.outputs.is_diagnostic == 'true' && '1' || '0' }}
BENCH_DIAGNOSTICS_DIR: ${{ github.workspace }}/${{ matrix.gateway.path }}/diagnostics
USE_PREBUILT_SUBGRAPHS: "1"
USE_PREBUILT_GATEWAY: "1"
- name: Kill all perfrunner processes
if: always()
run: |
echo "Killing all perfrunner processes..."
sudo pkill -u perfrunner || true
sleep 2
sudo pkill -9 -u perfrunner || true
echo "Done."
- name: Reclaim workspace ownership
if: always()
run: sudo chown -R $(id -u):$(id -g) .
- name: Upload results
if: always()
uses: actions/upload-artifact@v7
with:
name: results-${{ matrix.gateway.name }}-constant
path: ${{ matrix.gateway.path }}/results/
- name: Inspect diagnostics directory
if: ${{ always() && needs.prepare-matrix.outputs.is_diagnostic == 'true' }}
run: |
echo "Diagnostics directory: ${{ matrix.gateway.path }}/diagnostics"
ls -la "${{ matrix.gateway.path }}/diagnostics" || true
find "${{ matrix.gateway.path }}/diagnostics" -maxdepth 2 -type f -print | sort || true
- name: Upload diagnostics
if: ${{ always() && needs.prepare-matrix.outputs.is_diagnostic == 'true' }}
uses: actions/upload-artifact@v7
with:
name: diagnostics-${{ matrix.gateway.name }}-constant
path: ${{ matrix.gateway.path }}/diagnostics/
if-no-files-found: ignore
benchmark-burst:
needs:
- prepare-matrix
- build-subgraphs
- build-gateways
- benchmark-constant
if: ${{ always() && !cancelled() && needs.prepare-matrix.outputs.run_burst == 'true' }}
strategy:
fail-fast: false
matrix:
gateway: ${{ fromJson(needs.prepare-matrix.outputs.gateways) }}
runs-on:
group: benchmarking-1
name: ${{ matrix.gateway.name }} (burst)
env:
BENCH_RUNS: ${{ inputs.runs || '9' }}
MEASURE_SECONDS: ${{ inputs.duration || '120' }}
steps:
- uses: actions/checkout@v6
- name: Download prebuilt gateway
uses: actions/download-artifact@v8
with:
name: ${{ matrix.gateway.gateway_artifact }}
path: prebuilt-gateway/
- name: Restore prebuilt gateway
run: |
GATEWAY_ARCHIVE="$(find prebuilt-gateway -type f -name '*.tar.gz' | head -n1)"
if [[ -z "$GATEWAY_ARCHIVE" ]]; then
echo "Error: prebuilt gateway archive not found"
find prebuilt-gateway -maxdepth 3 -print
exit 1
fi
tar -xzf "$GATEWAY_ARCHIVE" -C .
if [[ -f apollo-federation/gateways/apollo-router/router ]]; then
chmod +x apollo-federation/gateways/apollo-router/router
fi
if [[ -f apollo-federation/gateways/cosmo/cosmo ]]; then
chmod +x apollo-federation/gateways/cosmo/cosmo
fi
if [[ -f apollo-federation/gateways/grafbase/grafbase-gateway ]]; then
chmod +x apollo-federation/gateways/grafbase/grafbase-gateway
fi
if [[ -f apollo-federation/gateways/hive-router/hive_router ]]; then
chmod +x apollo-federation/gateways/hive-router/hive_router
fi
- name: Download prebuilt subgraphs
continue-on-error: true
uses: actions/download-artifact@v8
with:
name: ${{ matrix.gateway.subgraphs_artifact }}
path: prebuilt-subgraphs/
- name: Restore prebuilt subgraphs
env:
GH_TOKEN: ${{ github.token }}
GATEWAY_PATH: ${{ matrix.gateway.path }}
SUBGRAPHS_DIR: ${{ matrix.gateway.subgraphs }}
SUBGRAPHS_ARTIFACT: ${{ matrix.gateway.subgraphs_artifact }}
run: |
set -euo pipefail
find_subgraphs_archive() {
find prebuilt-subgraphs -type f -name '*.tar.gz' | head -n1
}
redownload_subgraphs_artifact() {
rm -rf prebuilt-subgraphs
mkdir -p prebuilt-subgraphs
gh run download "$GITHUB_RUN_ID" --repo "$GITHUB_REPOSITORY" --name "$SUBGRAPHS_ARTIFACT" --dir prebuilt-subgraphs
}
ATTEMPTS=3
for attempt in $(seq 1 "$ATTEMPTS"); do
SUBGRAPHS_ARCHIVE="$(find_subgraphs_archive)"
if [[ -z "$SUBGRAPHS_ARCHIVE" ]]; then
echo "Subgraphs archive not found (attempt $attempt/$ATTEMPTS)"
elif tar -tzf "$SUBGRAPHS_ARCHIVE" >/dev/null 2>&1; then
tar -xzf "$SUBGRAPHS_ARCHIVE" -C .
if [[ -f apollo-federation/subgraphs-rust/target/release/subgraphs ]]; then
chmod +x apollo-federation/subgraphs-rust/target/release/subgraphs
fi
if [[ -f composite-schema/subgraphs-rust/target/release/subgraphs ]]; then
chmod +x composite-schema/subgraphs-rust/target/release/subgraphs
fi
exit 0
else
echo "Subgraphs archive integrity check failed (attempt $attempt/$ATTEMPTS): $SUBGRAPHS_ARCHIVE"
ls -lh "$SUBGRAPHS_ARCHIVE" || true
fi
if [[ "$attempt" -lt "$ATTEMPTS" ]]; then
echo "Re-downloading artifact '$SUBGRAPHS_ARTIFACT' for retry..."
if ! redownload_subgraphs_artifact; then
echo "Artifact re-download failed (attempt $((attempt + 1))/$ATTEMPTS)."
fi
sleep $((attempt * 5))
fi
done
find prebuilt-subgraphs -maxdepth 3 -print || true
SUBGRAPHS_ROOT="${GATEWAY_PATH%%/*}"
SUBGRAPHS_PATH="${SUBGRAPHS_ROOT}/${SUBGRAPHS_DIR}"
echo "Archive restore failed after $ATTEMPTS attempts; falling back to local rebuild: $SUBGRAPHS_PATH"
if [[ ! -f "$SUBGRAPHS_PATH/build.sh" ]]; then
echo "Error: fallback build script not found: $SUBGRAPHS_PATH/build.sh"
exit 1
fi
chmod +x "$SUBGRAPHS_PATH/build.sh"
(cd "$SUBGRAPHS_PATH" && bash build.sh)
if [[ -f apollo-federation/subgraphs-rust/target/release/subgraphs ]]; then
chmod +x apollo-federation/subgraphs-rust/target/release/subgraphs
fi
if [[ -f composite-schema/subgraphs-rust/target/release/subgraphs ]]; then
chmod +x composite-schema/subgraphs-rust/target/release/subgraphs
fi
- name: Kill stale perfrunner processes
run: |
sudo pkill -u perfrunner || true
sleep 1
sudo pkill -9 -u perfrunner || true
- name: Prepare workspace for perfrunner
run: |
# Both users need write access during a run:
# - perfrunner writes dependency artifacts (node_modules, target, etc.)
# - github-runner writes benchmark outputs (results/, summaries)
sudo chmod -R a+rX,g+rwX .
sudo chown -R perfrunner:github-runner .
# Preserve github-runner as group owner for newly created files/dirs.
sudo find . -type d -exec chmod g+s {} +
- name: Prepare diagnostics directory
if: ${{ needs.prepare-matrix.outputs.is_diagnostic == 'true' }}
run: |
mkdir -p "${{ matrix.gateway.path }}/diagnostics"
{
echo "diagnostic_run=true"
echo "mode=burst"
echo "gateway=${{ matrix.gateway.name }}"
echo "started_utc=${{ github.run_started_at || 'n/a' }}"
echo "run_id=${{ github.run_id }}"
} > "${{ matrix.gateway.path }}/diagnostics/run-info.txt"
sudo chown -R perfrunner:github-runner "${{ matrix.gateway.path }}/diagnostics"
sudo chmod -R u+rwX,g+rwX "${{ matrix.gateway.path }}/diagnostics"
- name: Run benchmark
run: ./k6/benchmark.sh ${{ matrix.gateway.path }} ${{ matrix.gateway.subgraphs }} burst
env:
BENCH_DISPLAY_NAME: ${{ matrix.gateway.display_name || '' }}
BENCH_SUBGRAPH_TECH: ${{ matrix.gateway.subgraph_tech || '' }}
BENCH_DIAGNOSTIC_RUN: ${{ needs.prepare-matrix.outputs.is_diagnostic == 'true' && '1' || '0' }}
BENCH_DIAGNOSTICS_DIR: ${{ github.workspace }}/${{ matrix.gateway.path }}/diagnostics
USE_PREBUILT_SUBGRAPHS: "1"
USE_PREBUILT_GATEWAY: "1"
- name: Kill all perfrunner processes
if: always()
run: |
echo "Killing all perfrunner processes..."
sudo pkill -u perfrunner || true
sleep 2
sudo pkill -9 -u perfrunner || true
echo "Done."
- name: Reclaim workspace ownership
if: always()
run: sudo chown -R $(id -u):$(id -g) .
- name: Upload results
if: always()
uses: actions/upload-artifact@v7
with:
name: results-${{ matrix.gateway.name }}-burst
path: ${{ matrix.gateway.path }}/results/
- name: Inspect diagnostics directory
if: ${{ always() && needs.prepare-matrix.outputs.is_diagnostic == 'true' }}
run: |
echo "Diagnostics directory: ${{ matrix.gateway.path }}/diagnostics"
ls -la "${{ matrix.gateway.path }}/diagnostics" || true
find "${{ matrix.gateway.path }}/diagnostics" -maxdepth 2 -type f -print | sort || true
- name: Upload diagnostics
if: ${{ always() && needs.prepare-matrix.outputs.is_diagnostic == 'true' }}
uses: actions/upload-artifact@v7
with:
name: diagnostics-${{ matrix.gateway.name }}-burst
path: ${{ matrix.gateway.path }}/diagnostics/
if-no-files-found: ignore
benchmark-constant-latency:
needs:
- prepare-matrix
- build-subgraphs
- build-gateways
if: ${{ always() && !cancelled() && needs.prepare-matrix.outputs.run_latency == 'true' }}
strategy:
fail-fast: false
matrix:
gateway: ${{ fromJson(needs.prepare-matrix.outputs.gateways_net) }}
runs-on:
group: benchmarking-1
name: ${{ matrix.gateway.name }} (constant-latency)
env:
BENCH_RUNS: ${{ inputs.runs || '9' }}
MEASURE_SECONDS: ${{ inputs.duration || '120' }}
steps:
- uses: actions/checkout@v6
- name: Download prebuilt gateway
uses: actions/download-artifact@v8
with:
name: ${{ matrix.gateway.gateway_artifact }}
path: prebuilt-gateway/
- name: Restore prebuilt gateway
run: |
GATEWAY_ARCHIVE="$(find prebuilt-gateway -type f -name '*.tar.gz' | head -n1)"
if [[ -z "$GATEWAY_ARCHIVE" ]]; then
echo "Error: prebuilt gateway archive not found"
find prebuilt-gateway -maxdepth 3 -print
exit 1
fi
tar -xzf "$GATEWAY_ARCHIVE" -C .
if [[ -f apollo-federation/gateways/apollo-router/router ]]; then
chmod +x apollo-federation/gateways/apollo-router/router
fi
if [[ -f apollo-federation/gateways/cosmo/cosmo ]]; then
chmod +x apollo-federation/gateways/cosmo/cosmo
fi
if [[ -f apollo-federation/gateways/grafbase/grafbase-gateway ]]; then
chmod +x apollo-federation/gateways/grafbase/grafbase-gateway
fi
if [[ -f apollo-federation/gateways/hive-router/hive_router ]]; then
chmod +x apollo-federation/gateways/hive-router/hive_router
fi
- name: Download prebuilt subgraphs
continue-on-error: true
uses: actions/download-artifact@v8
with:
name: ${{ matrix.gateway.subgraphs_artifact }}
path: prebuilt-subgraphs/
- name: Restore prebuilt subgraphs
env:
GH_TOKEN: ${{ github.token }}
GATEWAY_PATH: ${{ matrix.gateway.path }}
SUBGRAPHS_DIR: ${{ matrix.gateway.subgraphs }}
SUBGRAPHS_ARTIFACT: ${{ matrix.gateway.subgraphs_artifact }}
run: |
set -euo pipefail
find_subgraphs_archive() {
find prebuilt-subgraphs -type f -name '*.tar.gz' | head -n1
}
redownload_subgraphs_artifact() {
rm -rf prebuilt-subgraphs
mkdir -p prebuilt-subgraphs
gh run download "$GITHUB_RUN_ID" --repo "$GITHUB_REPOSITORY" --name "$SUBGRAPHS_ARTIFACT" --dir prebuilt-subgraphs
}
ATTEMPTS=3
for attempt in $(seq 1 "$ATTEMPTS"); do
SUBGRAPHS_ARCHIVE="$(find_subgraphs_archive)"
if [[ -z "$SUBGRAPHS_ARCHIVE" ]]; then
echo "Subgraphs archive not found (attempt $attempt/$ATTEMPTS)"
elif tar -tzf "$SUBGRAPHS_ARCHIVE" >/dev/null 2>&1; then
tar -xzf "$SUBGRAPHS_ARCHIVE" -C .
if [[ -f apollo-federation/subgraphs-rust/target/release/subgraphs ]]; then
chmod +x apollo-federation/subgraphs-rust/target/release/subgraphs
fi
if [[ -f composite-schema/subgraphs-rust/target/release/subgraphs ]]; then
chmod +x composite-schema/subgraphs-rust/target/release/subgraphs
fi
exit 0
else
echo "Subgraphs archive integrity check failed (attempt $attempt/$ATTEMPTS): $SUBGRAPHS_ARCHIVE"
ls -lh "$SUBGRAPHS_ARCHIVE" || true
fi
if [[ "$attempt" -lt "$ATTEMPTS" ]]; then
echo "Re-downloading artifact '$SUBGRAPHS_ARTIFACT' for retry..."
if ! redownload_subgraphs_artifact; then
echo "Artifact re-download failed (attempt $((attempt + 1))/$ATTEMPTS)."
fi
sleep $((attempt * 5))
fi
done
find prebuilt-subgraphs -maxdepth 3 -print || true
SUBGRAPHS_ROOT="${GATEWAY_PATH%%/*}"
SUBGRAPHS_PATH="${SUBGRAPHS_ROOT}/${SUBGRAPHS_DIR}"
echo "Archive restore failed after $ATTEMPTS attempts; falling back to local rebuild: $SUBGRAPHS_PATH"
if [[ ! -f "$SUBGRAPHS_PATH/build.sh" ]]; then
echo "Error: fallback build script not found: $SUBGRAPHS_PATH/build.sh"
exit 1
fi
chmod +x "$SUBGRAPHS_PATH/build.sh"
(cd "$SUBGRAPHS_PATH" && bash build.sh)
if [[ -f apollo-federation/subgraphs-rust/target/release/subgraphs ]]; then
chmod +x apollo-federation/subgraphs-rust/target/release/subgraphs
fi
if [[ -f composite-schema/subgraphs-rust/target/release/subgraphs ]]; then
chmod +x composite-schema/subgraphs-rust/target/release/subgraphs
fi
- name: Kill stale perfrunner processes
run: |
sudo pkill -u perfrunner || true
sleep 1
sudo pkill -9 -u perfrunner || true
- name: Prepare workspace for perfrunner
run: |
sudo chmod -R a+rX,g+rwX .
sudo chown -R perfrunner:github-runner .
sudo find . -type d -exec chmod g+s {} +
- name: Prepare diagnostics directory
if: ${{ needs.prepare-matrix.outputs.is_diagnostic == 'true' }}
run: |
mkdir -p "${{ matrix.gateway.path }}/diagnostics"
{
echo "diagnostic_run=true"
echo "mode=constant-latency"
echo "gateway=${{ matrix.gateway.name }}"
echo "started_utc=${{ github.run_started_at || 'n/a' }}"
echo "run_id=${{ github.run_id }}"
} > "${{ matrix.gateway.path }}/diagnostics/run-info.txt"
sudo chown -R perfrunner:github-runner "${{ matrix.gateway.path }}/diagnostics"
sudo chmod -R u+rwX,g+rwX "${{ matrix.gateway.path }}/diagnostics"
- name: Run benchmark
run: ./k6/benchmark.sh ${{ matrix.gateway.path }} ${{ matrix.gateway.subgraphs }} constant-latency
env:
BENCH_DISPLAY_NAME: ${{ matrix.gateway.display_name || '' }}
BENCH_SUBGRAPH_TECH: ${{ matrix.gateway.subgraph_tech || '' }}
BENCH_DIAGNOSTIC_RUN: ${{ needs.prepare-matrix.outputs.is_diagnostic == 'true' && '1' || '0' }}
BENCH_DIAGNOSTICS_DIR: ${{ github.workspace }}/${{ matrix.gateway.path }}/diagnostics
USE_PREBUILT_SUBGRAPHS: "1"
USE_PREBUILT_GATEWAY: "1"
- name: Kill all perfrunner processes
if: always()
run: |
echo "Killing all perfrunner processes..."
sudo pkill -u perfrunner || true
sleep 2
sudo pkill -9 -u perfrunner || true
echo "Done."
- name: Reclaim workspace ownership
if: always()
run: sudo chown -R $(id -u):$(id -g) .
- name: Upload results
if: always()
uses: actions/upload-artifact@v7
with:
name: results-${{ matrix.gateway.name }}-constant-latency
path: ${{ matrix.gateway.path }}/results/
- name: Inspect diagnostics directory
if: ${{ always() && needs.prepare-matrix.outputs.is_diagnostic == 'true' }}
run: |
echo "Diagnostics directory: ${{ matrix.gateway.path }}/diagnostics"
ls -la "${{ matrix.gateway.path }}/diagnostics" || true
find "${{ matrix.gateway.path }}/diagnostics" -maxdepth 2 -type f -print | sort || true
- name: Upload diagnostics
if: ${{ always() && needs.prepare-matrix.outputs.is_diagnostic == 'true' }}
uses: actions/upload-artifact@v7
with:
name: diagnostics-${{ matrix.gateway.name }}-constant-latency
path: ${{ matrix.gateway.path }}/diagnostics/
if-no-files-found: ignore
generate-results-constant:
needs:
- prepare-matrix
- benchmark-constant
- generate-results-constant-latency
if: ${{ always() && !cancelled() && needs.prepare-matrix.outputs.should_publish == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.ref_name }}
- uses: actions/download-artifact@v8
with:
pattern: results-*-constant
path: artifacts/
- name: Generate constant result document
env:
EXPECTED_GATEWAYS_JSON: ${{ needs.prepare-matrix.outputs.gateways }}
EXPECTED_GATEWAYS_NET_JSON: ${{ needs.prepare-matrix.outputs.gateways_net }}
RESULT_MODES: constant
run: python3 k6/generate-results.py artifacts/ benchmark-runs/${{ github.run_number }}
- name: Write constant summary
run: |
RUN_RESULTS_DIR="benchmark-runs/${{ github.run_number }}"
CONSTANT_RESULTS_FILE="$RUN_RESULTS_DIR/RESULTS_CONSTANT.md"
echo "# Benchmark Results (Constant)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ -f "$CONSTANT_RESULTS_FILE" ]]; then
cat "$CONSTANT_RESULTS_FILE" >> $GITHUB_STEP_SUMMARY
else
echo "No constant results were generated." >> $GITHUB_STEP_SUMMARY
fi
- name: Commit constant results
run: |
RUN_RESULTS_DIR="benchmark-runs/${{ github.run_number }}"
CONSTANT_RESULTS_FILE="$RUN_RESULTS_DIR/RESULTS_CONSTANT.md"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if [[ -f "$CONSTANT_RESULTS_FILE" ]]; then
git add "$CONSTANT_RESULTS_FILE"
fi
git diff --cached --quiet || git commit -m "Add constant benchmark results for run #${{ github.run_number }}"
git push
- name: Upload combined constant results
if: always()
uses: actions/upload-artifact@v7
with:
name: all-results-constant
path: artifacts/
generate-results-burst:
needs:
- prepare-matrix
- benchmark-burst
- generate-results-constant
if: ${{ !cancelled() && needs.prepare-matrix.outputs.should_publish == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.ref_name }}
- uses: actions/download-artifact@v8
with:
pattern: results-*-burst
path: artifacts/
- name: Generate burst result document
env:
EXPECTED_GATEWAYS_JSON: ${{ needs.prepare-matrix.outputs.gateways }}