Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Rate limiting test script
#!/usr/bin/env python3
from binascii import hexlify
import time
from random import randint
import requests
regular_url = "http://localhost:5000/_status"
asset_url = "http://localhost:5000/assets/images/icons/logo.svg"
# Generate a random auth header so this run is not counted as the same user as
# any previous run.
auth_token = hexlify(bytearray([randint(0, 16) for _ in range(10)]))
auth_header = f"Bearer {auth_token}"
def send_request(url):
r = requests.get(url, headers={"Authorization": auth_header})
if r.status_code != 200:
print(f"Request {url} failed with status {r.status_code}")
return r
def send_request_burst(url, burst_count):
print(f"Issuing a burst of {burst_count} requests")
burst_start = time.time()
for _ in range(burst_count):
burst_end = time.time()
print(f"Request burst took {burst_end - burst_start}s")
send_request_burst(asset_url, 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.