Skip to content

Commit f2f8c70

Browse files
committed
Add make targets for benchmark tooling
1 parent 841b593 commit f2f8c70

File tree

3 files changed

+118
-41
lines changed

3 files changed

+118
-41
lines changed

Makefile

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,36 @@ else
1717
@echo "benchmark tool already installed..."
1818
endif
1919

20-
.PHONY: bench-put
21-
bench-put: build install-benchmark
22-
@echo "Running benchmark: put $(ARGS)"
23-
./scripts/benchmark_test.sh put $(ARGS)
20+
.PHONY: bench-lease-keepalive bench-put bench-txn-mixed bench-watch-latency bench-watch bench-range-key
21+
## ----------------------------------------------------------------------------
22+
## etcd Benchmark Operations
23+
## Run the corresponding operation with the relevant arguments set through ARGS, after setting up an etcd server to bench against.
24+
## Eg. make bench-put ARGS="--clients=100 --conns=10"
25+
## Targets:
26+
## bench-lease-keepalive: Run the benchmark lease-keepalive operation with optional ARGS.
27+
bench-lease-keepalive: TEST := lease-keepalive
28+
## bench-put: Run the benchmark put operation with optional ARGS.
29+
bench-put: TEST := put
30+
## bench-txn-mixed: Run the benchmark txn-mixed operation with optional ARGS.
31+
bench-txn-mixed: TEST := txn-mixed
32+
## bench-watch-latency: Run the benchmark watch-latency operation with optional ARGS.
33+
bench-watch-latency: TEST := watch-latency
34+
## bench-watch: Run the benchmark watch operation with optional ARGS.
35+
bench-watch: TEST := watch
36+
## bench-range-key: Run the benchmark range-key operation with optional ARGS.
37+
bench-range-key: TEST := range
38+
bench-range-key: ARGS := key
39+
40+
bench-lease-keepalive bench-put bench-txn-mixed bench-watch-latency bench-watch bench-range-key: build install-benchmark
41+
@echo "Running benchmark: $(TEST) $(ARGS)"
42+
./scripts/benchmark_test.sh "$(TEST):$(ARGS)"
43+
44+
## bench: Run a custom benchmark with TEST_ARGS which can be a combination of tests with arguments.
45+
## Eg. make bench TEST_ARGS='put:"--clients=1000" range:"key --conns=10"'
46+
## ----------------------------------------------------------------------------
47+
.PHONY: bench
48+
bench: build install-benchmark
49+
./scripts/benchmark_test.sh $(TEST_ARGS)
2450

2551
PLATFORMS=linux-amd64 linux-386 linux-arm linux-arm64 linux-ppc64le linux-s390x darwin-amd64 darwin-arm64 windows-amd64 windows-arm64
2652

@@ -253,3 +279,7 @@ markdown-diff-lint:
253279
.PHONY: update-go-workspace
254280
update-go-workspace:
255281
./scripts/update_go_workspace.sh
282+
283+
.PHONY: help
284+
help:
285+
@sed -ne '/@sed/!s/## //p' $(MAKEFILE_LIST)

pkg/report/perfdash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (r *report) writePerfDashReport(benchmarkOp string) {
7474
artifactsDir = "./_artifacts"
7575
}
7676

77-
fileName := fmt.Sprintf("EtcdAPI_benchmark_%s.json", time.Now().UTC().Format(time.RFC3339))
77+
fileName := fmt.Sprintf("EtcdAPI_benchmark_%s_%s.json", benchmarkOp, time.Now().UTC().Format(time.RFC3339))
7878
err := os.MkdirAll(artifactsDir, 0o755)
7979
if err != nil {
8080
fmt.Println("Error creating artifacts directory:", err)

scripts/benchmark_test.sh

Lines changed: 83 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,100 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
# This script runs a benchmark on a locally started etcd server
16+
# This utility script helps to set up the test environment for benchmark tests and runs the provided tests sequentially.
1717

1818
set -euo pipefail
1919

2020
source ./scripts/test_lib.sh
2121

22-
COMMON_BENCHMARK_FLAGS="--report-perfdash"
22+
declare -A BENCHMARK_FLAGS
23+
BENCHMARKS_TO_RUN=()
24+
COMMON_BENCHMARK_FLAGS=(--report-perfdash)
2325

24-
if [[ $# -lt 1 ]]; then
25-
echo "Usage: $0 <benchmark-name> [tester args...]"
26-
exit 1
27-
fi
26+
parse_args() {
27+
for arg in "$@"; do
28+
if [[ "$arg" == *:* ]]; then
29+
key="${arg%%:*}"
30+
value="${arg#*:}"
31+
BENCHMARKS_TO_RUN+=("$key")
32+
BENCHMARK_FLAGS["$key"]="$value"
33+
else
34+
BENCHMARKS_TO_RUN+=("$arg")
35+
BENCHMARK_FLAGS["$arg"]=""
36+
fi
37+
done
2838

29-
BENCHMARK_NAME="$1"
30-
ARGS="${*:2}"
39+
if [ ${#BENCHMARKS_TO_RUN[@]} -eq 0 ]; then
40+
log_error "Usage: ./benchmark_test.sh 'benchmark-operation:\"test_arguments\"'"
41+
log_error "Example: ./benchmark_test.sh 'put:\"--clients=1000\" range:\"--conns=100\"'"
42+
exit 1
43+
fi
44+
}
3145

32-
echo "Starting the etcd server..."
46+
start_etcd() {
47+
log_callout "Setup: Starting the etcd server..."
48+
# Create a directory for etcd data under /tmp/etcd
49+
mkdir -p /tmp/etcd
50+
DATA_DIR=$(mktemp -d /tmp/etcd/data-XXXXXX)
51+
ARTIFACTS_DIR="${ARTIFACTS:-./_artifacts}"
52+
mkdir -p "$ARTIFACTS_DIR"
53+
ETCD_LOG_FILE="${ARTIFACTS_DIR}/etcd-${bench}-$(date +%Y%m%d-%H%M%S).log"
54+
log_callout -e "Setup: etcd log file path set to $ETCD_LOG_FILE. DATA_DIR set to $DATA_DIR"
55+
./bin/etcd --data-dir="$DATA_DIR" > "${ETCD_LOG_FILE}" 2>&1 &
56+
ETCD_PID=$!
57+
RETRY=0
58+
MAX_RETRY_ATTEMPTS=10
3359

34-
# Create a directory for etcd data under /tmp/etcd
35-
mkdir -p /tmp/etcd
36-
DATA_DIR=$(mktemp -d /tmp/etcd/data-XXXXXX)
37-
./bin/etcd --data-dir="$DATA_DIR" > /tmp/etcd.log 2>&1 &
38-
etcd_pid=$!
60+
# Set up the trap to handle errors/interrupts which leads to cleaning up of the DATADIR and stopping the etcd server.
61+
trap 'stop_and_cleanup_etcd' EXIT
3962

40-
trap 'log_warning -e "Stopping etcd server - PID $etcd_pid";
41-
kill $etcd_pid 2>/dev/null;
42-
rm -rf $DATA_DIR;
43-
log_success "Deleted the contents from $DATA_DIR related to benchmark test"' EXIT
63+
# Poll until etcd is healthy
64+
until curl -fs http://127.0.0.1:2379/health | grep -q '"health":"true"'; do
65+
RETRY=$((RETRY + 1))
66+
if [[ $RETRY -gt $MAX_RETRY_ATTEMPTS ]]; then
67+
log_error -e "Setup: Failed to confirm etcd health after $MAX_RETRY_ATTEMPTS attempts."
68+
exit 1
69+
fi
70+
log_warning -e "Setup: Waiting for etcd to be healthy... (retry: $RETRY/$MAX_RETRY_ATTEMPTS)"
71+
sleep 1
72+
done
73+
log_success -e "Setup: etcd is healthy and running on pid $ETCD_PID"
74+
}
4475

45-
# Wait until etcd becomes healthy
46-
for retry in {1..10}; do
47-
if ./bin/etcdctl endpoint health --cluster> /dev/null 2>&1; then
48-
log_success -e "\\netcd is healthy"
49-
break
50-
fi
51-
log_warning -e "\\nWaiting for etcd to be healthy..."
52-
sleep 1
53-
if [[ $retry -eq 10 ]]; then
54-
log_error -e "\\nFailed to confirm etcd health after $retry attempts. Check /tmp/etcd.log for more information"
55-
exit 1
76+
stop_and_cleanup_etcd() {
77+
trap - EXIT
78+
log_warning -e "Cleanup: Stopping etcd server - PID $ETCD_PID"
79+
kill "$ETCD_PID" 2>/dev/null || true
80+
rm -rf "$DATA_DIR"
81+
log_success "Cleanup: Deleted the DATA_DIR contents from $DATA_DIR related to benchmark test"
82+
}
83+
84+
run_benchmark() {
85+
local bench=$1
86+
local args="${BENCHMARK_FLAGS[$bench]:-}"
87+
88+
if [[ -z "$args" ]]; then
89+
log_callout -e "\\nPerforming benchmark $bench with default arguments"
90+
benchmark "$bench" "${COMMON_BENCHMARK_FLAGS[@]}"
91+
else
92+
log_callout -e "\\nPerforming benchmark $bench with arguments: $args"
93+
read -r -a TESTER_OPTIONS <<< "$args"
94+
95+
printf "Running: benchmark %s %s %s\n" \
96+
"$bench" "${TESTER_OPTIONS[*]}" "${COMMON_BENCHMARK_FLAGS[*]}"
97+
98+
benchmark "$bench" "${TESTER_OPTIONS[@]}" "${COMMON_BENCHMARK_FLAGS[@]}"
5699
fi
57-
done
100+
}
101+
102+
main() {
103+
parse_args "$@"
58104

59-
log_success -e "etcd process is running with PID $etcd_pid"
105+
for bench in "${BENCHMARKS_TO_RUN[@]}"; do
106+
start_etcd
107+
run_benchmark "$bench"
108+
stop_and_cleanup_etcd
109+
done
110+
}
60111

61-
log_callout -e "\\nPerforming benchmark $BENCHMARK_NAME with arguments: $ARGS"
62-
read -r -a TESTER_OPTIONS <<< "$ARGS"
63-
log_callout "Running: benchmark $BENCHMARK_NAME ${TESTER_OPTIONS[*]} $COMMON_BENCHMARK_FLAGS"
64-
benchmark "$BENCHMARK_NAME" "${TESTER_OPTIONS[@]}" $COMMON_BENCHMARK_FLAGS
65-
log_callout "Completed: benchmark $BENCHMARK_NAME ${TESTER_OPTIONS[*]} $COMMON_BENCHMARK_FLAGS"
112+
main "$@"

0 commit comments

Comments
 (0)