Skip to content

Instantly share code, notes, and snippets.

@Marakuba
Created August 11, 2018 06:20
Show Gist options
  • Select an option

  • Save Marakuba/80a05438fc4d5394ac13cc345adb2817 to your computer and use it in GitHub Desktop.

Select an option

Save Marakuba/80a05438fc4d5394ac13cc345adb2817 to your computer and use it in GitHub Desktop.
"""
Quick dog-piling (aka stampeding herd) URL stresstest
https://www.peterbe.com/plog/quick-dog-piling-url-stresstest
"""
import random
import time
import requests
import concurrent.futures
def _get_size(url):
sleep = random.random() / 10
# print("sleep", sleep)
time.sleep(sleep)
r = requests.get(url)
# print(r.status_code)
assert len(r.text)
return len(r.text)
def run(url, times=10):
sizes = []
futures = []
with concurrent.futures.ThreadPoolExecutor() as executor:
for _ in range(times):
futures.append(executor.submit(_get_size, url))
for future in concurrent.futures.as_completed(futures):
sizes.append(future.result())
return sizes
if __name__ == "__main__":
import sys
print(run(sys.argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment