#!/bin/bash # # What 0005's resolution costs: one throwaway gateway from the given binary on # 127.0.0.1:${BENCH_PORT:-7395}, posix on ${BENCH_DIR:-/var/tmp/s3gw-nf-bench}, internal IAM. # # sudo bash bench.sh /path/to/versitygw [count] # # Times (default 500) PUT, GET, HEAD and DELETE calls of 1 KiB objects # four directories deep, and ten listings of them (bench.py), then counts the # gateway's system calls (strace -f -c) for 100 GETs and 100 HEADs of one of # them. Run it with the patched build and with a stock one on the same node, one # after the other. Nothing installed is touched; the directory is removed at # exit. set -uo pipefail VGW=${1:?usage: bench.sh /path/to/versitygw [count]} COUNT=${2:-500} HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) export S3REQ=${S3REQ:-$HERE/../owner-scope/s3req.py} PORT=${BENCH_PORT:-7395} W=${BENCH_DIR:-/var/tmp/s3gw-nf-bench} export S3_ENDPOINT=http://127.0.0.1:$PORT S3_REGION=us-east-1 [ -x "$VGW" ] || { echo "FATAL: $VGW is not an executable" >&2; exit 2; } rm -rf "$W" && mkdir -p "$W/iam" "$W/data" || exit 2 RK=benchroot RS=$(python3 -c 'import secrets; print(secrets.token_hex(16))') export S3_KEY=bench S3_SECRET=$(python3 -c 'import secrets; print(secrets.token_hex(16))') "$VGW" --access "$RK" --secret "$RS" --region "$S3_REGION" --port "127.0.0.1:$PORT" --iam-dir "$W/iam" \ posix "$W/data" >"$W/gateway.log" 2>&1 & GW=$! trap 'kill $GW 2>/dev/null; wait $GW 2>/dev/null; rm -rf "$W"' EXIT for _ in $(seq 1 50); do (exec 3<>"/dev/tcp/127.0.0.1/$PORT") 2>/dev/null && break; sleep 0.2; done admin() { ADMIN_ACCESS_KEY_ID=$RK ADMIN_SECRET_ACCESS_KEY=$RS "$VGW" admin --region "$S3_REGION" --endpoint-url "$S3_ENDPOINT" "$@"; } admin create-user --access "$S3_KEY" --secret "$S3_SECRET" --role user --user-id 74990 --group-id 74990 >/dev/null && admin create-bucket --owner "$S3_KEY" --bucket bench >/dev/null || { echo "FATAL: setup failed" >&2; exit 2; } echo "versitygw sha256 $(sha256sum "$VGW" | cut -c1-16), $(uname -r), $(df -T "$W" | awk 'NR==2 {print $2}')" python3 "$HERE/bench.py" bench "$COUNT" || exit 1 if command -v strace >/dev/null; then printf 'x' >"$W/one" && python3 "$S3REQ" PUT /bench/s/a/b/c/one.txt --body "$W/one" >/dev/null for method in GET HEAD; do strace -f -c -o "$W/strace.$method" -p "$GW" 2>/dev/null & ST=$! sleep 1 for _ in $(seq 1 100); do python3 "$S3REQ" "$method" /bench/s/a/b/c/one.txt -o /dev/null >/dev/null; done sleep 0.5 kill -INT "$ST"; wait "$ST" 2>/dev/null # rows: % time, seconds, usecs/call, calls, [errors,] syscall total=$(awk '$1 ~ /^[0-9.]+$/ && $NF != "total" {s += $4} END {print s + 0}' "$W/strace.$method") top=$(awk '$1 ~ /^[0-9.]+$/ && $NF != "total" {print $NF ":" $4}' "$W/strace.$method" | sort -t: -k2 -rn | head -8 | tr '\n' ' ') echo "$method x100: $total system calls in the gateway ($((total / 100)) a call); most: $top" done fi