- Live job card widget (progress bar, in-widget cancel via widget_query) and live invoice widget (QR drawn from a bitmap, countdown, paid state), Bot API 10.4 sendWidget, private chats only - Automatic fallback to the ordinary message when sendWidget fails, with a breaker that pauses widgets after repeated failures or on servers without the method; TELEGRAM_WIDGETS - Prometheus metrics on the core (/metrics) and on every worker: queue depth and wait, slots, heartbeats, job outcomes, errors per site, deliveries, cache, invoices, Lightning, ledger check, widgets - Example Prometheus config and alert rules, Caddyfile, dashboard notes - Load test: cmd/loadtest and deploy/loadtest (make loadtest) - Browser check of the widgets' HTML, including decoding a drawn QR - docs/DEPLOY.md (production in under an hour) and docs/MONITORING.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
4.4 KiB
Bash
Executable File
103 lines
4.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Load test: many simulated users against a real core and real workers,
|
|
# with Telegram replaced by cmd/faketelegram and yt-dlp by a stand-in that
|
|
# takes a set time per download and never touches the network. What it
|
|
# measures is the bot itself: the queue, the workers, the cache, delivery.
|
|
#
|
|
# deploy/loadtest/run.sh # 50 users, embedded worker
|
|
# USERS=200 LINKS=5 WORKERS=4 deploy/loadtest/run.sh
|
|
#
|
|
# Settings (environment):
|
|
# USERS (50), LINKS (3), RAMP (20s), SHARE (0.2) the load
|
|
# WORKERS (0) remote workers; 0 uses the core's embedded worker
|
|
# SLOTS (4) downloads at once, per worker
|
|
# LOAD_TIME (2) seconds one download takes
|
|
# LOAD_SIZE (2000000) bytes per file
|
|
# DB (sqlite) or postgres, with PG_DSN set
|
|
# KEEP=1 keep logs and the database afterwards
|
|
#
|
|
# Needs: go, curl. Prints a summary, and the core's /metrics for the queue.
|
|
set -euo pipefail
|
|
|
|
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
|
WORK=$(mktemp -d "${TMPDIR:-/tmp}/dlbot-load.XXXXXX")
|
|
FAKE_PORT=${FAKE_PORT:-18190}
|
|
CORE_PORT=${CORE_PORT:-18180}
|
|
USERS=${USERS:-50}
|
|
LINKS=${LINKS:-3}
|
|
RAMP=${RAMP:-20s}
|
|
SHARE=${SHARE:-0.2}
|
|
WORKERS=${WORKERS:-0}
|
|
SLOTS=${SLOTS:-4}
|
|
FAKE="http://127.0.0.1:$FAKE_PORT"
|
|
CORE="http://127.0.0.1:$CORE_PORT"
|
|
PIDS=()
|
|
|
|
cleanup() {
|
|
for pid in "${PIDS[@]:-}"; do kill "$pid" 2>/dev/null || true; done
|
|
wait 2>/dev/null || true
|
|
if [ -n "${KEEP:-}" ]; then echo "logs kept in $WORK"; else rm -rf "$WORK"; fi
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
echo "==> building"
|
|
(cd "$ROOT" && go build -o "$WORK/bin/" ./cmd/core ./cmd/worker ./cmd/faketelegram ./cmd/loadtest)
|
|
|
|
db_env=(DB_DRIVER=sqlite DB_DSN="$WORK/core.db")
|
|
if [ "${DB:-sqlite}" = postgres ]; then
|
|
: "${PG_DSN:?set PG_DSN to an empty Postgres database}"
|
|
db_env=(DB_DRIVER=postgres DB_DSN="$PG_DSN")
|
|
fi
|
|
|
|
embedded=true
|
|
tokens=""
|
|
if [ "$WORKERS" -gt 0 ]; then
|
|
embedded=false
|
|
for i in $(seq 1 "$WORKERS"); do
|
|
tokens="${tokens:+$tokens,}load-$i:dlw_load_test_token_for_worker_${i}_0000000000"
|
|
done
|
|
fi
|
|
|
|
echo "==> starting the fake Telegram and the core ($([ "$WORKERS" -gt 0 ] && echo "$WORKERS remote workers" || echo "embedded worker"), $SLOTS slots each)"
|
|
"$WORK/bin/faketelegram" -listen "127.0.0.1:$FAKE_PORT" >"$WORK/fake.log" 2>&1 &
|
|
PIDS+=($!)
|
|
(cd "$WORK" && exec env -i PATH="$PATH" HOME="$WORK" \
|
|
BOT_TOKEN="123456789:FAKEfakeFAKEfakeFAKEfakeFAKEfake-01" TELEGRAM_API_URL="$FAKE" \
|
|
HTTP_LISTEN="127.0.0.1:$CORE_PORT" "${db_env[@]}" STORAGE_LOCAL_DIR="$WORK/files" \
|
|
WORKER_EMBEDDED=$embedded WORKER_TOKENS="$tokens" WORKER_CONCURRENCY="$SLOTS" WORKER_TEMP_DIR="$WORK/tmp-core" \
|
|
YTDLP_PATH="$ROOT/deploy/loadtest/fake-yt-dlp.sh" YTDLP_AUTO_UPDATE=0 PROBE_MODE=$([ "$WORKERS" -gt 0 ] && echo worker || echo local) \
|
|
LOAD_TIME="${LOAD_TIME:-2}" LOAD_SIZE="${LOAD_SIZE:-2000000}" \
|
|
FREE_DAILY_DOWNLOADS=100000 FREE_DAILY_MB=0 FREE_ACTIVE_JOBS=1 FREE_MAX_SIZE_MB=50 \
|
|
RATE_USER_PER_MINUTE=600 RATE_GROUP_PER_MINUTE=600 QUEUE_FREE_MAX_LEN=100000 \
|
|
TELEGRAM_UPDATE_WORKERS=32 TELEGRAM_WIDGETS=false TELEGRAM_SET_PROFILE=false \
|
|
LOG_FORMAT=text LOG_LEVEL=warn \
|
|
"$WORK/bin/core" >"$WORK/core.log" 2>&1) &
|
|
PIDS+=($!)
|
|
|
|
for _ in $(seq 1 100); do curl -fsS "$CORE/healthz" >/dev/null 2>&1 && break; sleep 0.3; done
|
|
curl -fsS "$CORE/healthz" >/dev/null || { echo "the core did not start:"; tail -20 "$WORK/core.log"; exit 1; }
|
|
|
|
for i in $(seq 1 "$WORKERS"); do
|
|
(cd "$WORK" && exec env -i PATH="$PATH" HOME="$WORK" \
|
|
CORE_URL="$CORE" WORKER_TOKEN="dlw_load_test_token_for_worker_${i}_0000000000" WORKER_CONCURRENCY="$SLOTS" \
|
|
WORKER_TEMP_DIR="$WORK/tmp-$i" WORKER_HEALTH_LISTEN=off YTDLP_PATH="$ROOT/deploy/loadtest/fake-yt-dlp.sh" \
|
|
YTDLP_AUTO_UPDATE=0 LOAD_TIME="${LOAD_TIME:-2}" LOAD_SIZE="${LOAD_SIZE:-2000000}" LOG_FORMAT=text LOG_LEVEL=warn \
|
|
"$WORK/bin/worker" >"$WORK/worker-$i.log" 2>&1) &
|
|
PIDS+=($!)
|
|
done
|
|
|
|
echo "==> $USERS users, $LINKS links each, started over $RAMP, $(awk "BEGIN{print $SHARE*100}")% for one popular link"
|
|
status=0
|
|
"$WORK/bin/loadtest" -fake "$FAKE" -users "$USERS" -links "$LINKS" -ramp "$RAMP" -share "$SHARE" || status=$?
|
|
|
|
echo
|
|
echo "==> core metrics"
|
|
curl -fsS "$CORE/metrics" | grep -E '^dlbot_(queue_wait_seconds_(sum|count)|jobs_finished_total|cache_hits_total|cache_misses_total|deliveries_total|download_errors_total|worker_heartbeat_age_seconds)' || true
|
|
if grep -q 'level=ERROR' "$WORK/core.log"; then
|
|
echo
|
|
echo "==> errors in the core log"
|
|
grep 'level=ERROR' "$WORK/core.log" | head -20
|
|
status=1
|
|
fi
|
|
exit $status
|