From fd23f6bfb3bad294c89330fbeafd653345ef5536 Mon Sep 17 00:00:00 2001 From: Dmytro Kozlov Date: Tue, 2 Sep 2025 14:37:18 +0200 Subject: [PATCH] benchmark: add gnuplot to show write speed (#9490) ### Describe Your Changes Implemented the script that generates graphs using `gnuplot`. Those graphs show the write speed to the db. How to use it: 1. From the root run `make tsbs`; 2. The file will be generated automatically `/tmp/tsbs-load-100000-2025-07-22T00:00:00Z-2025-07-23T00:00:00Z-80s.csv` 4. From the root run `make tsbs-plot-load` and observe the result 5. If you have two files with the `tsbs_load_victoriametrics` output, just define the second in the `TSBS_LOAD_RESULT_CSV_FILE_COMPARE=/tmp/tsbs-load-10 0000-2025-07-22T01:00:00Z-2025-07-23T01:00:00Z-80s.csv ` To plot the measurements from some other benchmark, run `make tsbs-plot-load TSBS_LOAD_RESULT_CSV_FILE=/path/to/file.csv` To plot the measurements from two benchmarks, run `make tsbs-plot-load TSBS_LOAD_RESULT_CSV_FILE=/path/to/file1.csv TSBS_LOAD_RESULT_CSV_FILE_COMPARE=/path/to/file2.csv` This command should generate a graph like described in the picture Screenshot 2025-07-25 at 15 35 42 ### Checklist The following checks are **mandatory**: - [x] My change adheres to [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/victoriametrics/contributing/#pull-request-checklist). - [x] My change adheres to [VictoriaMetrics development goals](https://docs.victoriametrics.com/victoriametrics/goals/). --------- Signed-off-by: Artem Fetishev Co-authored-by: Artem Fetishev Co-authored-by: Artem Fetishev <149964189+rtm0@users.noreply.github.com> --- benchmarks/Makefile | 21 +++++++++++++++- benchmarks/plot-load.sh | 55 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100755 benchmarks/plot-load.sh diff --git a/benchmarks/Makefile b/benchmarks/Makefile index 51aa0942ab..cb66613105 100644 --- a/benchmarks/Makefile +++ b/benchmarks/Makefile @@ -48,6 +48,9 @@ TSBS_WORKERS ?= 4 TSBS_QUERY_TYPE := cpu-max-all-8 TSBS_DATA_FILE := /tmp/tsbs-data-$(TSBS_SCALE)-$(TSBS_START)-$(TSBS_END)-$(TSBS_STEP).gz TSBS_QUERY_FILE := /tmp/tsbs-queries-$(TSBS_QUERY_TYPE)-$(TSBS_SCALE)-$(TSBS_START)-$(TSBS_END)-$(TSBS_QUERIES).gz +TSBS_LOAD_RESULT_CSV_FILE := /tmp/tsbs-load-$(TSBS_SCALE)-$(TSBS_START)-$(TSBS_END)-$(TSBS_STEP).csv +TSBS_LOAD_RESULT_CSV_FILE_COMPARE ?= +TSBS_PLOT_SCRIPT := $(shell pwd)/benchmarks/plot-load.sh # For cluster setup use http://vminsert:8480/insert/0/influx/write TSBS_WRITE_URLS ?= http://localhost:8428/write # For cluster setup use http://vmselect:8481/select/0/prometheus @@ -76,7 +79,10 @@ tsbs-generate-data: # Load data into VictoriaMetrics tsbs-load-data: - cat $(TSBS_DATA_FILE) | gunzip | /tmp/tsbs/bin/tsbs_load_victoriametrics --workers=$(TSBS_WORKERS) --urls=$(TSBS_WRITE_URLS) + cat $(TSBS_DATA_FILE) | gunzip | /tmp/tsbs/bin/tsbs_load_victoriametrics \ + --workers=$(TSBS_WORKERS) \ + --urls=$(TSBS_WRITE_URLS) \ + 2>/dev/tty | tee $(TSBS_LOAD_RESULT_CSV_FILE) curl -s $(TSBS_METRICS_URL) | grep \ -e process_cpu_seconds_user_total \ -e process_cpu_seconds_system_total \ @@ -133,3 +139,16 @@ tsbs-run-queries-all: # Too heavy: retrieves 1B samples # $(MAKE) tsbs-run-queries TSBS_QUERY_TYPE=double-groupby-all + +# Plot the data load `per interval metrics/s` measurements +# +# To plot measurements collected during the recent benchmark, run +# make tsbs-plot-load +# +# To plot the measurements from some other benchmark, run +# make tsbs-plot-load TSBS_LOAD_RESULT_CSV_FILE=/path/to/file.csv +# +# To plot the measurements from two benchmarks, run +# make tsbs-plot-load TSBS_LOAD_RESULT_CSV_FILE=/path/to/file1.csv TSBS_LOAD_RESULT_CSV_FILE_COMPARE=/path/to/file2.csv +tsbs-plot-load: + $(TSBS_PLOT_SCRIPT) $(TSBS_LOAD_RESULT_CSV_FILE) $(TSBS_LOAD_RESULT_CSV_FILE_COMPARE) diff --git a/benchmarks/plot-load.sh b/benchmarks/plot-load.sh new file mode 100755 index 0000000000..2692978f3a --- /dev/null +++ b/benchmarks/plot-load.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# Check the number of arguments +if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then + echo "Usage: $(basename $0) file1.csv [file2.csv]" + exit 1 +fi + +file1="$1" +file2="$2" + +# Check if the files exist +if [ ! -f "$file1" ]; then + echo "File not found: $file1" + exit 1 +fi + +if [ -n "$file2" ] && [ ! -f "$file2" ]; then + echo "File not found: $file2" + exit 1 +fi + +# Temporary file for plot data +plotdata="/tmp/tsbs_plot.dat" + +if [ -z "$file2" ]; then + # === One file === + awk -F, '/^Summary:/ {exit} NR > 1 {print $1, $2}' "$file1" > "$plotdata" +else + # === Two files === + + # Get time and per.metric/s from file1 + awk -F, '/^Summary:/ {exit} NR > 1 {print $1, $2}' "$file1" > /tmp/file1.dat + # Get per.metric/s from file2 + awk -F, '/^Summary:/ {exit} NR > 1 {print $2}' "$file2" > /tmp/file2.dat + # Merge by rows: time, val1, val2 + paste /tmp/file1.dat /tmp/file2.dat | awk '{print $1, $2, $3}' > "$plotdata" +fi + +# === Build plot dynamically === +gnuplot -persist <<-EOF + set datafile separator " " + set title "per.metric/s" + set xlabel "Timestamp" + set xdata time + set timefmt "%s" + set format x "%H:%M:%S" + set ylabel "per. metric/s" + set format y "%'.0f" + set grid + + plot "$plotdata" using 1:2 with lines title "$(basename "$file1")" \ + $( [[ -n "$file2" ]] && echo ", \\ + \"$plotdata\" using 1:3 with lines title \"$(basename "$file2")\"" ) +EOF