-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblockchain_node_benchmark.sh
More file actions
executable file
Β·978 lines (809 loc) Β· 34.7 KB
/
blockchain_node_benchmark.sh
File metadata and controls
executable file
Β·978 lines (809 loc) Β· 34.7 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
#!/bin/bash
# =====================================================================
# Blockchain Node Performance Benchmark Framework Entry Point
# =====================================================================
# Deployment environment check
check_deployment() {
local current_path="$(pwd)"
local script_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "π Verifying deployment environment..." >&2
echo " Current location: $script_path" >&2
# Basic permission check
if [[ ! -r "$script_path" ]]; then
echo "β Error: Cannot read framework directory" >&2
echo "π‘ Solution: Check directory permissions" >&2
return 1
fi
echo "β
Deployment environment verification passed" >&2
}
# Display framework information
show_framework_info() {
echo "π Blockchain Node Performance Benchmark Framework"
echo ""
echo "π Supported test modes:"
echo " β’ Quick verification test - Basic performance verification"
echo " β’ Standard performance test - Comprehensive performance evaluation"
echo " β’ Intensive stress test - Intelligent bottleneck detection"
echo ""
echo "π Monitoring capabilities:"
echo " β’ 73 - 79 performance metrics real-time monitoring"
echo " β’ CPU, Memory, EBS storage, Network, ENA limitations"
echo " β’ Intelligent bottleneck detection and root cause analysis"
echo " β’ Bottleneck-log time correlation analysis"
echo ""
echo "π Analysis features:"
echo " β’ Machine learning anomaly detection"
echo " β’ Multi-dimensional performance correlation analysis"
echo " β’ HTML report and PNG chart generation"
echo " β’ Historical test comparison and trend analysis"
echo ""
}
# Execute deployment check
if ! check_deployment; then
exit 1
fi
# If no parameters, display framework information
if [[ $# -eq 0 ]]; then
show_framework_info
echo "π‘ Use ./blockchain_node_benchmark.sh --help to view detailed usage instructions"
echo ""
exit 0
fi
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Load configuration and shared functions
source "${SCRIPT_DIR}/config/config_loader.sh"
source "${SCRIPT_DIR}/utils/error_handler.sh"
source "${SCRIPT_DIR}/core/common_functions.sh"
# Clean or create memory sharing directory
if [[ -d "$MEMORY_SHARE_DIR" ]]; then
echo "π§Ή Cleaning old cached data in memory sharing directory..." >&2
# Clean all possible residual files
rm -f "$MEMORY_SHARE_DIR"/*.json 2>/dev/null || true
rm -f "$MEMORY_SHARE_DIR"/sample_count 2>/dev/null || true
rm -f "$MEMORY_SHARE_DIR"/*cache* 2>/dev/null || true
rm -f "$MEMORY_SHARE_DIR"/*.pid 2>/dev/null || true
rm -f "$MEMORY_SHARE_DIR"/*.lock 2>/dev/null || true
else
echo "π Creating memory sharing directory..." >&2
mkdir -p "$MEMORY_SHARE_DIR" 2>/dev/null || true
chmod 755 "$MEMORY_SHARE_DIR" 2>/dev/null || true
fi
echo "β
Memory sharing directory prepared" >&2
# Set up error handling
setup_error_handling "$(basename "$0")" "Blockchain Node Benchmark Framework"
log_script_start "$(basename "$0")"
# Global variables
MONITORING_PIDS=()
TEST_SESSION_ID="session_${SESSION_TIMESTAMP}"
BOTTLENECK_DETECTED=false
BOTTLENECK_INFO=""
# Cleanup function
cleanup_framework() {
echo "π§Ή Executing framework cleanup..."
# Stop monitoring system
stop_monitoring_system
# Clean up temporary files
cleanup_temp_files
echo "β
Framework cleanup completed"
}
# Set cleanup trap
trap cleanup_framework EXIT INT TERM
# Prepare Benchmark data
prepare_benchmark_data() {
echo "π Preparing Benchmark data..."
# Check if account file exists
if [[ ! -f "$ACCOUNTS_OUTPUT_FILE" ]]; then
echo "π Fetching active accounts..."
if [[ -f "${SCRIPT_DIR}/tools/fetch_active_accounts.py" ]]; then
python3 "${SCRIPT_DIR}/tools/fetch_active_accounts.py" \
--output "$ACCOUNTS_OUTPUT_FILE" \
--count "$ACCOUNT_COUNT" \
--verbose
if [[ $? -eq 0 && -f "$ACCOUNTS_OUTPUT_FILE" ]]; then
echo "β
Account fetching successful: $(wc -l < "$ACCOUNTS_OUTPUT_FILE") accounts"
else
echo "β Account fetching failed"
return 1
fi
else
echo "β Account fetching script does not exist: ${SCRIPT_DIR}/tools/fetch_active_accounts.py"
echo " Please check if file exists and path is correct"
return 1
fi
else
echo "β
Account file already exists: $(wc -l < "$ACCOUNTS_OUTPUT_FILE") accounts"
fi
# Generate vegeta target files
echo "π― Generating Vegeta target files (RPC mode: $RPC_MODE)..."
if [[ -f "${SCRIPT_DIR}/tools/target_generator.sh" ]]; then
"${SCRIPT_DIR}/tools/target_generator.sh" \
--accounts-file "$ACCOUNTS_OUTPUT_FILE" \
--rpc-url "$LOCAL_RPC_URL" \
--rpc-mode "$RPC_MODE" \
--output-single "$SINGLE_METHOD_TARGETS_FILE" \
--output-mixed "$MIXED_METHOD_TARGETS_FILE"
if [[ $? -eq 0 ]]; then
echo "β
Vegeta target file generation successful (RPC mode: $RPC_MODE)"
if [[ "$RPC_MODE" == "mixed" ]]; then
echo " Mixed method target: $MIXED_METHOD_TARGETS_FILE"
else
echo " Single method target: $SINGLE_METHOD_TARGETS_FILE"
fi
else
echo "β Vegeta target file generation failed"
return 1
fi
else
echo "β Target generation script does not exist: tools/target_generator.sh"
return 1
fi
return 0
}
# Start monitoring system
start_monitoring_system() {
echo "π Starting monitoring system..."
# Clean up block height continuous exceeded flag file from last test
rm -f "${MEMORY_SHARE_DIR}/block_height_time_exceeded.flag" 2>/dev/null || true
# Create framework running status file before starting monitoring
echo "running" > "$TMP_DIR/qps_test_status.tmp"
mv "$TMP_DIR/qps_test_status.tmp" "$TMP_DIR/qps_test_status"
echo "[STATUS] Framework lifecycle marker created: $TMP_DIR/qps_test_status"
# Export monitoring PID file path for subprocess use
export MONITOR_PIDS_FILE="${TMP_DIR}/monitor_pids.txt"
export MONITOR_STATUS_FILE="${TMP_DIR}/monitoring_status.json"
# Start monitoring coordinator
if [[ -f "${SCRIPT_DIR}/monitoring/monitoring_coordinator.sh" ]]; then
echo "π Starting monitoring coordinator..."
"${SCRIPT_DIR}/monitoring/monitoring_coordinator.sh" start &
local coordinator_pid=$!
MONITORING_PIDS+=($coordinator_pid)
echo "β
Monitoring coordinator started (PID: $coordinator_pid)"
# Wait for monitoring system initialization
sleep 5
# Verify monitoring system status
if kill -0 $coordinator_pid 2>/dev/null; then
echo "β
Monitoring system running normally"
return 0
else
echo "β Monitoring system startup failed"
return 1
fi
else
echo "β Monitoring coordinator does not exist: monitoring/monitoring_coordinator.sh"
return 1
fi
}
# Stop monitoring system
stop_monitoring_system() {
echo "π Stopping monitoring system..."
# Check if there are monitoring processes to stop
if [[ ${#MONITORING_PIDS[@]} -eq 0 ]]; then
echo "βΉοΈ No monitoring processes to stop"
return 0
fi
# Stop monitoring coordinator
if [[ -f "${SCRIPT_DIR}/monitoring/monitoring_coordinator.sh" ]]; then
"${SCRIPT_DIR}/monitoring/monitoring_coordinator.sh" stop
fi
# Stop all monitoring processes
for pid in "${MONITORING_PIDS[@]}"; do
if kill -0 $pid 2>/dev/null; then
echo "π Stopping monitoring process PID: $pid"
kill -TERM $pid 2>/dev/null
sleep 2
if kill -0 $pid 2>/dev/null; then
kill -KILL $pid 2>/dev/null
fi
fi
done
MONITORING_PIDS=()
echo "β
Monitoring system stopped"
}
# Execute core QPS test
execute_core_qps_test() {
echo "[START] Executing core QPS test (RPC mode: $RPC_MODE)..."
# π§ Verify framework status file exists (created when monitoring started)
if [[ ! -f "$TMP_DIR/qps_test_status" ]]; then
echo "[ERROR] Framework status file not found. Monitoring system may not be running."
return 1
fi
echo "[STATUS] Framework lifecycle marker verified: $TMP_DIR/qps_test_status"
# Build parameter array, filter out RPC mode parameters as we will add them separately
local executor_args=()
# Add non-RPC mode parameters
for arg in "$@"; do
case $arg in
--single|--mixed)
# Skip RPC mode parameters, we will add based on RPC_MODE variable
;;
*)
executor_args+=("$arg")
;;
esac
done
# Add correct RPC mode parameter based on RPC_MODE variable
executor_args+=("--$RPC_MODE")
# Call master_qps_executor.sh
"${SCRIPT_DIR}/core/master_qps_executor.sh" "${executor_args[@]}"
local test_result=$?
# Wait for monitoring system to collect final data, ensure data integrity
echo "[STATUS] QPS test completed, waiting for monitoring data collection..."
sleep 3
# Delete QPS test status marker file - safe deletion
if [[ -f "$TMP_DIR/qps_test_status" ]]; then
rm -f "$TMP_DIR/qps_test_status"
echo "[STATUS] QPS test status marker deleted"
else
echo "[WARN] QPS test status marker file does not exist, may have been deleted"
fi
# Check if bottleneck detected - intelligently merge multiple bottleneck data sources
local bottleneck_sources=(
"${QPS_STATUS_FILE}" # Prioritize bottlenecks during QPS test
"${MEMORY_SHARE_DIR}/bottleneck_status.json" # Then bottlenecks during monitoring
)
local bottleneck_found=false
local all_bottleneck_info=""
for bottleneck_file in "${bottleneck_sources[@]}"; do
if [[ -f "$bottleneck_file" ]]; then
local status_data=$(cat "$bottleneck_file" 2>/dev/null)
if [[ -n "$status_data" ]] && echo "$status_data" | grep -q "bottleneck_detected.*true"; then
local source_info=$(echo "$status_data" | jq -r '.bottleneck_summary // "Unknown bottleneck"' 2>/dev/null || echo "Unknown bottleneck")
local source_name=$(basename "$bottleneck_file")
if [[ "$bottleneck_found" == "false" ]]; then
BOTTLENECK_DETECTED=true
BOTTLENECK_INFO="$source_info"
all_bottleneck_info="$source_name: $source_info"
bottleneck_found=true
else
all_bottleneck_info="$all_bottleneck_info; $source_name: $source_info"
fi
echo "π¨ Performance bottleneck detected: $source_info (source: $source_name)"
fi
fi
done
# If multiple bottleneck sources found, record complete information
if [[ "$bottleneck_found" == "true" ]]; then
echo "[INFO] Complete bottleneck information: $all_bottleneck_info"
fi
return $test_result
}
# Process test results
process_test_results() {
echo "π Processing test results..."
# AWS baseline conversion
echo "π Executing AWS baseline conversion..."
if [[ -f "${SCRIPT_DIR}/utils/ebs_converter.sh" ]]; then
# Note: ebs_converter.sh is a function library, does not support direct parameter execution
# Actual EBS conversion is implemented through source call in iostat_collector.sh
echo "β
EBS conversion library loaded, conversion executed automatically during data collection"
else
echo "β οΈ EBS conversion script does not exist, skipping conversion"
fi
# Unit conversion
if [[ -f "${SCRIPT_DIR}/utils/unit_converter.py" ]]; then
python3 "${SCRIPT_DIR}/utils/unit_converter.py" --auto-process
echo "β
Unit conversion completed"
else
echo "β οΈ Unit conversion script does not exist, skipping conversion"
fi
return 0
}
# Execute data analysis
execute_data_analysis() {
echo "π Executing data analysis..."
# Parse benchmark_mode parameter
local benchmark_mode=""
for arg in "$@"; do
case $arg in
--quick) benchmark_mode="quick" ;;
--standard) benchmark_mode="standard" ;;
--intensive) benchmark_mode="intensive" ;;
esac
done
if [[ -z "$benchmark_mode" ]]; then
benchmark_mode="quick"
fi
# Use symlink to get latest performance data file
local latest_csv="${LOGS_DIR}/performance_latest.csv"
if [[ ! -f "$latest_csv" ]]; then
echo "[ERROR] Performance data file not found: $latest_csv"
echo "[DEBUG] Available CSV files:"
ls -la "$LOGS_DIR"/*.csv 2>/dev/null || echo " No CSV files found"
echo "[DEBUG] LOGS_DIR = $LOGS_DIR"
return 1
fi
# Verify file integrity and symlink target
if [[ -L "$latest_csv" ]]; then
local target_file=$(readlink "$latest_csv")
local full_target="${LOGS_DIR}/$target_file"
if [[ ! -f "$full_target" ]]; then
echo "[ERROR] Symlink target does not exist: $full_target"
return 1
fi
echo "[INFO] Using symlinked file: $target_file"
fi
local line_count=$(wc -l < "$latest_csv")
if [[ $line_count -lt 2 ]]; then
echo "[ERROR] Performance data file is empty or only contains header: $line_count lines"
return 1
fi
# Verify CSV header integrity and required fields
local header=$(head -1 "$latest_csv")
local field_count=$(echo "$header" | tr ',' '\n' | wc -l)
if [[ $field_count -lt 10 ]]; then
echo "[ERROR] CSV header appears incomplete: only $field_count fields"
return 1
fi
# Verify critical fields exist
local required_fields=("timestamp" "cpu_usage" "mem_usage")
local missing_fields=()
for field in "${required_fields[@]}"; do
if ! echo "$header" | grep -q "$field"; then
missing_fields+=("$field")
fi
done
if [[ ${#missing_fields[@]} -gt 0 ]]; then
echo "[ERROR] Required fields missing from CSV: ${missing_fields[*]}"
echo "[DEBUG] Available fields: $header"
return 1
fi
# Check existence of device-related fields (for analysis script compatibility)
local has_data_device=false
local has_accounts_device=false
local has_ena_fields=false
if echo "$header" | grep -q "data_.*_util"; then
has_data_device=true
echo "[INFO] DATA device fields detected"
fi
if echo "$header" | grep -q "accounts_.*_util"; then
has_accounts_device=true
echo "[INFO] ACCOUNTS device fields detected"
fi
if echo "$header" | grep -q "ena_"; then
has_ena_fields=true
echo "[INFO] ENA fields detected (AWS environment)"
fi
# Warning: If no device fields, some analysis may be limited
if [[ "$has_data_device" == "false" && "$has_accounts_device" == "false" ]]; then
echo "[WARN] No EBS device fields detected - storage analysis may be limited"
fi
echo "[INFO] Using monitoring data file: $(basename "$latest_csv")"
echo "[INFO] File size: $line_count lines, $field_count fields"
echo "[INFO] Required fields verified: ${required_fields[*]}"
# If bottleneck detected, execute bottleneck-specific analysis
if [[ "$BOTTLENECK_DETECTED" == "true" ]]; then
echo "π¨ Executing bottleneck-specific analysis..."
# Read bottleneck detailed information
local bottleneck_details=""
if [[ -f "$QPS_STATUS_FILE" ]]; then
bottleneck_details=$(cat "$QPS_STATUS_FILE")
local bottleneck_qps=$(echo "$bottleneck_details" | jq -r '.bottleneck_qps // 0')
local max_qps=$(echo "$bottleneck_details" | jq -r '.max_successful_qps // 0')
local severity=$(echo "$bottleneck_details" | jq -r '.severity // "medium"')
echo "π Bottleneck details: QPS=$bottleneck_qps, Max successful QPS=$max_qps, Severity=$severity"
fi
# EBS bottleneck-specific analysis completed through real-time monitoring
# ebs_bottleneck_detector.sh runs in real-time through monitoring_coordinator.sh during testing
# Bottleneck detection results recorded in ebs_analyzer.log, no need to call again
echo "πΎ EBS bottleneck detection completed through real-time monitoring"
# Bottleneck time window analysis
execute_bottleneck_window_analysis "$latest_csv" "$bottleneck_details"
# Performance cliff analysis
execute_performance_cliff_analysis "$latest_csv" "$bottleneck_details"
fi
# Execute EBS performance analysis (generate ebs_analyzer.log)
if [[ -f "${SCRIPT_DIR}/tools/ebs_analyzer.sh" ]]; then
echo "π Executing EBS performance analysis: ebs_analyzer.sh"
if ! bash "${SCRIPT_DIR}/tools/ebs_analyzer.sh" "$latest_csv"; then
echo "β οΈ EBS analysis execution failed, HTML report may be missing EBS analysis section"
fi
else
echo "β οΈ EBS analysis script does not exist: tools/ebs_analyzer.sh"
fi
# Execute all standard analysis scripts
local analysis_scripts=(
"analysis/comprehensive_analysis.py"
"analysis/cpu_ebs_correlation_analyzer.py"
"analysis/qps_analyzer.py"
"analysis/rpc_deep_analyzer.py"
)
for script in "${analysis_scripts[@]}"; do
if [[ -f "${SCRIPT_DIR}/$script" ]]; then
local script_name=$(basename "$script")
# If bottleneck detected, some scripts already handled by specific analysis, skip to avoid duplication
if [[ "$BOTTLENECK_DETECTED" == "true" ]]; then
case "$script_name" in
"comprehensive_analysis.py")
echo "βοΈ Skipping $script_name (already handled by bottleneck time window analysis)"
continue
;;
"qps_analyzer.py")
echo "βοΈ Skipping $script_name (already handled by performance cliff analysis)"
continue
;;
esac
fi
echo "π Executing analysis: $script_name"
# If bottleneck detected, pass bottleneck mode parameter
if [[ "$BOTTLENECK_DETECTED" == "true" ]]; then
if ! python3 "${SCRIPT_DIR}/$script" "$latest_csv" --benchmark-mode "$benchmark_mode" --bottleneck-mode --output-dir "$BASE_DATA_DIR"; then
echo "β οΈ Analysis script execution failed: $script_name"
fi
else
# Execute basic analysis even without bottleneck, ensure chart generation
if ! python3 "${SCRIPT_DIR}/$script" "$latest_csv" --benchmark-mode "$benchmark_mode" --output-dir "$BASE_DATA_DIR"; then
echo "β οΈ Analysis script execution failed: $script_name"
fi
fi
else
echo "β οΈ Analysis script does not exist: $script"
fi
done
echo "β
Data analysis completed"
return 0
}
# Execute bottleneck time window analysis
execute_bottleneck_window_analysis() {
local csv_file="$1"
local bottleneck_info="$2"
echo "π Executing bottleneck time window analysis..."
if [[ -z "$bottleneck_info" ]]; then
echo "β οΈ No bottleneck information, skipping time window analysis"
return
fi
# Extract bottleneck time information
local bottleneck_time=$(echo "$bottleneck_info" | jq -r '.detection_time // ""')
local window_start=$(echo "$bottleneck_info" | jq -r '.analysis_window.start_time // ""')
local window_end=$(echo "$bottleneck_info" | jq -r '.analysis_window.end_time // ""')
if [[ -n "$bottleneck_time" ]]; then
echo "π Bottleneck time window: $window_start to $window_end"
# Call time window analysis tool
if [[ -f "${SCRIPT_DIR}/analysis/comprehensive_analysis.py" ]]; then
python3 "${SCRIPT_DIR}/analysis/comprehensive_analysis.py" \
"$csv_file" \
--benchmark-mode "$benchmark_mode" \
--output-dir "$BASE_DATA_DIR" \
--time-window \
--start-time "$window_start" \
--end-time "$window_end" \
--bottleneck-time "$bottleneck_time"
fi
fi
}
# Execute performance cliff analysis
execute_performance_cliff_analysis() {
local csv_file="$1"
local bottleneck_info="$2"
echo "π Executing performance cliff analysis..."
# Call performance cliff analysis tool - execute basic analysis even without bottleneck information
if [[ -f "${SCRIPT_DIR}/analysis/qps_analyzer.py" ]]; then
if [[ -n "$bottleneck_info" ]]; then
# Complete analysis when bottleneck information available
local max_qps=$(echo "$bottleneck_info" | jq -r '.max_successful_qps // 0')
local bottleneck_qps=$(echo "$bottleneck_info" | jq -r '.bottleneck_qps // 0')
if [[ $max_qps -gt 0 && $bottleneck_qps -gt 0 ]]; then
local performance_drop=$(awk "BEGIN {printf \"%.2f\", ($bottleneck_qps - $max_qps) * 100 / $max_qps}")
echo "π Performance cliff: from ${max_qps} QPS to ${bottleneck_qps} QPS (${performance_drop}%)"
python3 "${SCRIPT_DIR}/analysis/qps_analyzer.py" \
"$csv_file" \
--benchmark-mode "$benchmark_mode" \
--cliff-analysis \
--max-qps "$max_qps" \
--bottleneck-qps "$bottleneck_qps" \
--output-dir "$BASE_DATA_DIR"
else
echo "π Executing basic performance analysis (incomplete bottleneck data)"
python3 "${SCRIPT_DIR}/analysis/qps_analyzer.py" \
"$csv_file" \
--benchmark-mode "$benchmark_mode" \
--output-dir "$BASE_DATA_DIR"
fi
else
echo "π Executing basic performance analysis (no bottleneck information)"
python3 "${SCRIPT_DIR}/analysis/qps_analyzer.py" \
"$csv_file" \
--benchmark-mode "$benchmark_mode" \
--output-dir "$BASE_DATA_DIR"
fi
fi
}
# Archive test results
archive_test_results() {
echo "π¦ Archiving test results..."
# Determine benchmark mode - parse from passed parameters
local benchmark_mode=""
for arg in "$@"; do
case $arg in
--quick) benchmark_mode="quick" ;;
--standard) benchmark_mode="standard" ;;
--intensive) benchmark_mode="intensive" ;;
esac
done
# If no mode parameter found, use default value
if [[ -z "$benchmark_mode" ]]; then
benchmark_mode="quick" # Default mode, consistent with master_qps_executor.sh
echo "β οΈ Benchmark mode parameter not detected, using default mode: $benchmark_mode"
fi
echo "π Detected benchmark mode: $benchmark_mode"
# Read maximum QPS from QPS status file
local max_qps=0
if [[ -f "$QPS_STATUS_FILE" ]]; then
max_qps=$(jq -r '.max_successful_qps // 0' "$QPS_STATUS_FILE" 2>/dev/null)
fi
# Call professional archiving tool
if [[ -f "${SCRIPT_DIR}/tools/benchmark_archiver.sh" ]]; then
"${SCRIPT_DIR}/tools/benchmark_archiver.sh" --archive \
--benchmark-mode "$benchmark_mode" \
--max-qps "$max_qps"
if [[ $? -eq 0 ]]; then
echo "β
Test results archiving completed"
else
echo "β οΈ Test results archiving failed"
fi
else
echo "β οΈ Archiving script does not exist, skipping archiving"
fi
}
# Generate final reports
generate_final_reports() {
echo "π Generating final reports..."
# Use symlink to get latest performance data file
local latest_csv="${LOGS_DIR}/performance_latest.csv"
if [[ ! -f "$latest_csv" ]]; then
echo "β οΈ Warning: Performance data file not found: $latest_csv"
return 1
fi
# Prepare report generation parameters
local report_params=("$latest_csv")
# If bottleneck detected, add bottleneck mode parameter
if [[ "$BOTTLENECK_DETECTED" == "true" ]]; then
report_params+=("--bottleneck-mode")
# Add bottleneck information file
if [[ -f "$QPS_STATUS_FILE" ]]; then
report_params+=("--bottleneck-info" "$QPS_STATUS_FILE")
fi
echo "π¨ Bottleneck mode report generation"
fi
# Generate HTML report (bilingual: English and Chinese)
if [[ -f "${SCRIPT_DIR}/visualization/report_generator.py" ]]; then
echo "π Generating HTML report (bilingual)..."
# Generate English report
echo " π Generating English report..."
if ! python3 "${SCRIPT_DIR}/visualization/report_generator.py" "${report_params[@]}" --language en; then
echo " β English report generation failed"
return 1
fi
echo " β
English report generated"
# Generate Chinese report
echo " π Generating Chinese report..."
if ! python3 "${SCRIPT_DIR}/visualization/report_generator.py" "${report_params[@]}" --language zh; then
echo " β Chinese report generation failed"
return 1
fi
echo " β
Chinese report generated"
echo "β
Bilingual HTML report generated"
else
echo "β οΈ HTML report generator does not exist"
fi
# Generate advanced charts
if [[ -f "${SCRIPT_DIR}/visualization/advanced_chart_generator.py" ]]; then
echo "π Generating advanced charts..."
if ! python3 "${SCRIPT_DIR}/visualization/advanced_chart_generator.py" "${report_params[@]}"; then
echo "β οΈ Advanced chart generation failed"
else
echo "β
Advanced charts generated"
fi
else
echo "β οΈ Advanced chart generator does not exist"
fi
# Generate bottleneck-specific report
if [[ "$BOTTLENECK_DETECTED" == "true" ]]; then
generate_bottleneck_summary_report
fi
# Display report location and summary
display_final_report_summary
# Archive test results - execute after all analysis and report generation completed
archive_test_results "$@"
return 0
}
# Generate bottleneck summary report
generate_bottleneck_summary_report() {
echo "π¨ Generating bottleneck summary report..."
local bottleneck_summary_file="${REPORTS_DIR}/bottleneck_summary_${SESSION_TIMESTAMP}.md"
# Read bottleneck information
local bottleneck_info=""
if [[ -f "$QPS_STATUS_FILE" ]]; then
bottleneck_info=$(cat "$QPS_STATUS_FILE")
fi
# Generate Markdown format bottleneck summary
cat > "$bottleneck_summary_file" << EOF
# π¨ Performance Bottleneck Detection Report
## π Test Summary
- **Test time**: $(date)
- **Test session**: $TEST_SESSION_ID
- **Bottleneck status**: β
Performance bottleneck detected
## π― Bottleneck Details
EOF
if [[ -n "$bottleneck_info" ]]; then
local max_qps=$(echo "$bottleneck_info" | jq -r '.max_successful_qps // 0')
local bottleneck_qps=$(echo "$bottleneck_info" | jq -r '.bottleneck_qps // 0')
local severity=$(echo "$bottleneck_info" | jq -r '.severity // "unknown"')
local reasons=$(echo "$bottleneck_info" | jq -r '.bottleneck_reasons // "Unknown"')
local detection_time=$(echo "$bottleneck_info" | jq -r '.detection_time // "Unknown"')
cat >> "$bottleneck_summary_file" << EOF
- **Maximum successful QPS**: $max_qps
- **Bottleneck trigger QPS**: $bottleneck_qps
- **Severity**: $severity
- **Detection time**: $detection_time
- **Bottleneck reasons**: $reasons
## π System Recommendations
EOF
# Add recommendations
local recommendations=$(echo "$bottleneck_info" | jq -r '.recommendations[]?' 2>/dev/null)
if [[ -n "$recommendations" ]]; then
echo "$recommendations" | while read -r recommendation; do
echo "- $recommendation" >> "$bottleneck_summary_file"
done
else
echo "- Please refer to detailed analysis report for optimization recommendations" >> "$bottleneck_summary_file"
fi
fi
cat >> "$bottleneck_summary_file" << EOF
## π Related Files
- **Detailed bottleneck analysis**: $QPS_STATUS_FILE
- **Bottleneck event log**: ${LOGS_DIR}/bottleneck_events.jsonl
- **Performance data**: ${LOGS_DIR}/performance_latest.csv
## π― Next Steps
1. View HTML report for detailed performance analysis
2. Check bottleneck analysis file to understand root cause
3. Optimize system configuration based on recommendations
4. Re-run test to verify improvement effects
---
*Report generation time: $(date)*
EOF
echo "π Bottleneck summary report: $(basename "$bottleneck_summary_file")"
}
# Display final report summary
display_final_report_summary() {
echo ""
echo "π Test completed! Report summary:"
echo "================================"
echo "π Report directory: $REPORTS_DIR"
# HTML report
local html_report=$(find "$REPORTS_DIR" -name "*.html" -type f | head -1)
if [[ -n "$html_report" ]]; then
echo "π HTML report: $(basename "$html_report")"
fi
# Chart files
local chart_count=$(find "$REPORTS_DIR" -name "*.png" -type f | wc -l)
echo "π Chart files: $chart_count PNG files"
# Bottleneck-related reports
if [[ "$BOTTLENECK_DETECTED" == "true" ]]; then
echo ""
echo "π¨ Bottleneck detection results:"
if [[ -f "$QPS_STATUS_FILE" ]]; then
local max_qps=$(jq -r '.max_successful_qps // 0' "$QPS_STATUS_FILE" 2>/dev/null)
local bottleneck_qps=$(jq -r '.bottleneck_qps // 0' "$QPS_STATUS_FILE" 2>/dev/null)
echo "π Maximum successful QPS: $max_qps"
echo "π¨ Bottleneck trigger QPS: $bottleneck_qps"
fi
local bottleneck_summary=$(find "$REPORTS_DIR" -name "bottleneck_summary_*.md" -type f | head -1)
if [[ -n "$bottleneck_summary" ]]; then
echo "π Bottleneck summary: $(basename "$bottleneck_summary")"
fi
fi
echo ""
echo "π― Recommended next steps:"
echo "1. Open HTML report to view detailed analysis"
echo "2. Check PNG charts to understand performance trends"
if [[ "$BOTTLENECK_DETECTED" == "true" ]]; then
echo "3. View bottleneck summary report for optimization recommendations"
echo "4. Re-test after optimizing system based on recommendations"
else
echo "3. Consider running intensive test mode to find performance limits"
fi
}
# Clean up temporary files
cleanup_temp_files() {
echo "π§Ή Cleaning up temporary files..."
# Clean up session temporary directory
if [[ -d "$TEST_SESSION_DIR" ]]; then
rm -rf "$TEST_SESSION_DIR"
fi
# Clean up temporary files in memory sharing directory
if [[ -d "$MEMORY_SHARE_DIR" ]]; then
rm -f "$MEMORY_SHARE_DIR"/*.json 2>/dev/null || true
rm -f "$MEMORY_SHARE_DIR"/sample_count 2>/dev/null || true
rm -f "$MEMORY_SHARE_DIR"/*cache* 2>/dev/null || true
rm -f "$MEMORY_SHARE_DIR"/*.pid 2>/dev/null || true
rm -f "$MEMORY_SHARE_DIR"/*.lock 2>/dev/null || true
rm -f "$MEMORY_SHARE_DIR"/*.flag 2>/dev/null || true
fi
# Do not delete qps_status.json, keep for archiving
# if [[ -f "$QPS_STATUS_FILE" ]]; then
# rm -f "$QPS_STATUS_FILE"
# fi
}
# Parse RPC mode parameters
parse_rpc_mode_args() {
while [[ $# -gt 0 ]]; do
case $1 in
--single)
RPC_MODE="single"
shift
;;
--mixed)
RPC_MODE="mixed"
shift
;;
*)
# Other parameters continue to pass
shift
;;
esac
done
}
# Main execution function
main() {
# Save original parameters for subsequent passing
local original_args=("$@")
# Parse RPC mode parameters
parse_rpc_mode_args "$@"
echo "π Starting Blockchain Node Performance Benchmark Framework"
echo " RPC mode: $RPC_MODE"
echo " Test session ID: $TEST_SESSION_ID"
echo ""
# Display framework information
show_framework_info
# Check deployment environment
if ! check_deployment; then
exit 1
fi
# Note: Directory initialization completed in config.sh, no need to repeat
# Phase 1: Prepare Benchmark data
echo "π Phase 1: Prepare Benchmark data"
if ! prepare_benchmark_data; then
echo "β Benchmark data preparation failed"
exit 1
fi
# Phase 2: Start monitoring system
echo "π Phase 2: Start monitoring system"
if ! start_monitoring_system; then
echo "β Monitoring system startup failed"
exit 1
fi
# Phase 3: Execute core QPS test
echo "π Phase 3: Execute core QPS test"
if ! execute_core_qps_test "${original_args[@]}"; then
echo "β QPS test execution failed"
exit 1
fi
# Phase 4: Stop monitoring system
echo "π Phase 4: Stop monitoring system"
stop_monitoring_system
# Phase 5: Process test results
echo "π Phase 5: Process test results"
process_test_results "${original_args[@]}"
# Phase 6: Execute data analysis
echo "π Phase 6: Execute data analysis"
if ! execute_data_analysis "${original_args[@]}"; then
echo "β Data analysis failed, test terminated"
exit 1
fi
# Phase 7: Generate final reports
echo "π Phase 7: Generate final reports"
if ! generate_final_reports "${original_args[@]}"; then
echo "β Report generation failed, test terminated"
exit 1
fi
echo ""
echo "π Blockchain Node Performance Benchmark completed!"
if [[ "$BOTTLENECK_DETECTED" == "true" ]]; then
echo "π¨ Performance bottleneck detected: $BOTTLENECK_INFO"
echo "π Bottleneck-specific analysis report generated"
fi
return 0
}
# Execute main function
main "$@"