File size: 832 Bytes
6a7089a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
set -euo pipefail

# Flood the server with requests from unique IPs to stress-test
# the rate-limit bucket map. Without the eviction fix (#94),
# this causes unbounded memory growth.
#
# Usage:
#   ./scripts/simulate-ratelimit-leak.sh [host:port] [unique-ips]

HOST="${1:-localhost:9867}"
UNIQUE_IPS="${2:-5000}"
BATCH_SIZE=50

echo "Rate-limit stress test — ${UNIQUE_IPS} unique IPs → ${HOST}"
echo "Monitor: curl http://${HOST}/metrics | jq .metrics.rateBucketHosts"
echo ""

for i in $(seq 1 "$UNIQUE_IPS"); do
  ip="10.$((i / 65536 % 256)).$((i / 256 % 256)).$((i % 256))"
  curl -s -o /dev/null -H "X-Forwarded-For: ${ip}" "http://${HOST}/help" &

  if (( i % BATCH_SIZE == 0 )); then
    wait
    printf "\rSent %d/%d" "$i" "$UNIQUE_IPS"
  fi
done
wait
echo -e "\rDone — sent ${UNIQUE_IPS} requests"