Certainly! Let’s break down your request:
-
URL Analysis:
The URL you provided:
https://microsoft.github.io/garnet/docs/benchmarking/results-resp-bench
This is the documentation page for benchmarking the Garnet key-value store, specifically using the RESP (Redis protocol) benchmark tool. The page provides example commands and expected results for benchmarking Garnet.
-
Goal:
You want a Bash script to test a locally installed Garnet server running in a Docker container, listening on the default port (usually 6379 for RESP/Redis protocol).
Bash Script for Benchmarking Garnet in Docker
Below is a Bash script that:
- Assumes you have a Garnet Docker container running (or will start one).
- Uses the RESP.bench benchmarking tool (or
redis-benchmark as a fallback).
- Runs a simple benchmark against the Garnet server on the default port (
6379).
Script: garnet_benchmark.sh
#!/bin/bash
# Configuration
GARNET_CONTAINER_NAME="garnet-server"
GARNET_IMAGE="mcr.microsoft.com/garnet"
GARNET_PORT=6379
# Check if Garnet container is running, if not, start it
if ! docker ps --format '{{.Names}}' | grep -q "^${GARNET_CONTAINER_NAME}$"; then
echo "Starting Garnet Docker container..."
docker run -d --name $GARNET_CONTAINER_NAME -p $GARNET_PORT:6379 $GARNET_IMAGE
sleep 5 # Give it a few seconds to start
else
echo "Garnet Docker container is already running."
fi
# Check if RESP.bench is available, otherwise use redis-benchmark
if command -v RESP.bench &> /dev/null; then
BENCH_CMD="RESP.bench"
elif command -v redis-benchmark &> /dev/null; then
BENCH_CMD="redis-benchmark"
else
echo "Neither RESP.bench nor redis-benchmark is installed. Please install one of them."
exit 1
fi
# Run the benchmark
echo "Running benchmark against Garnet on port $GARNET_PORT using $BENCH_CMD..."
if [ "$BENCH_CMD" = "RESP.bench" ]; then
RESP.bench -h 127.0.0.1 -p $GARNET_PORT -n 100000 -c 50
else
redis-benchmark -h 127.0.0.1 -p $GARNET_PORT -n 100000 -c 50
fi
# Optionally, stop and remove the container after test
# docker stop $GARNET_CONTAINER_NAME && docker rm $GARNET_CONTAINER_NAME
How to Use
- Save the script as
garnet_benchmark.sh.
- Make it executable:
chmod +x garnet_benchmark.sh
- Run the script:
./garnet_benchmark.sh
Notes
- The script checks if the Garnet Docker container is running; if not, it starts one.
- It tries to use
RESP.bench (the official tool), but falls back to redis-benchmark if not available.
- You can uncomment the last line to automatically stop and remove the container after the test.
- Adjust the number of requests (
-n) and concurrency (-c) as needed.
Let me know if you need a version that builds RESP.bench from source, or if you want to run the benchmark from inside the Docker container!