Skip to content

Commit

Permalink
profile stress test
Browse files Browse the repository at this point in the history
added scoreboard visualization
  • Loading branch information
a-miscellaneous committed Jul 6, 2024
1 parent bdaae70 commit acf637a
Show file tree
Hide file tree
Showing 20 changed files with 442 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,5 @@ cython_debug/


checker/data
checker/src/backgrounds
checker/src/backgrounds
documentation/scripts/scoreboard/data
48 changes: 48 additions & 0 deletions documentation/scripts/scoreboard/fetcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import aiohttp
import asyncio
import json
import os

# http://localhost:5001/scoreboard/scoreboard33020.json
target_url = "http://localhost:5001/scoreboard/scoreboard"
data_folder = os.path.join(os.path.dirname(__file__), "data")
os.makedirs(data_folder, exist_ok=True)
found_files = os.listdir(data_folder)
batch_size = 10 # Number of files to download in each batch


async def download_scoreboard(session, n):
if f"scoreboard{n}.json" in found_files:
print(f"scoreboard{n}.json already exists")
return True
url = f"{target_url}{n}.json"
async with session.get(url) as response:
if response.status == 200:
data = await response.json()
with open(os.path.join(data_folder, f"scoreboard{n}.json"), "w") as f:
json.dump(data, f)
print(f"Downloaded scoreboard{n}.json")
return True
else:
print(f"Failed to download scoreboard{n}.json")
return False


async def download_batch(session, start, end):
tasks = [download_scoreboard(session, i) for i in range(start, end)]
results = await asyncio.gather(*tasks)
return all(results)


async def download_all_scoreboards(batch_size):
async with aiohttp.ClientSession() as session:
counter = 0
while True:
success = await download_batch(session, counter, counter + batch_size)
if not success:
break
counter += batch_size

if __name__ == "__main__":
asyncio.run(download_all_scoreboards(batch_size))
print("Done!")
Binary file added documentation/scripts/scoreboard/plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/scripts/scoreboard/plots/Wonki.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/scripts/scoreboard/plots/c2net.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/scripts/scoreboard/plots/sceam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
330 changes: 330 additions & 0 deletions documentation/scripts/scoreboard/visualizer.ipynb

Large diffs are not rendered by default.

File renamed without changes
84 changes: 62 additions & 22 deletions documentation/scripts/stress_test/get_profile_image.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import requests
import httpx
from PIL import Image
import random
import string
import io
import asyncio
from concurrent.futures import ThreadPoolExecutor
import time
import logging

logger = logging.getLogger("Service Benchmark Logger")
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler("get_profile_image.log")
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
fh.setFormatter(formatter)
logger.addHandler(fh)


def generate_random_string(length):
Expand All @@ -13,24 +25,52 @@ def generate_random_string(length):
k=length))


base = "http://localhost:8008/"
s = requests.Session()
name = generate_random_string(10)
email = name + "@" + generate_random_string(10) + ".scam"
data = {'email': email, 'name': name, 'quality': 2}
s.post(base + "sign-up", data=data)
r = s.post(base + "download_key")
key = r.content
img = Image.open(r"documentation\scripts\dog.4821.jpg")
b = io.BytesIO()
img.save(b, format="PNG")
b.seek(0)
b = b.getvalue()
files = {'file': b}
data = {'is_profile': 'on', 'description': 'Look at my new ENOFT!'}
r = s.post(base + "profile_" + email, files=files, data=data)
files = {'file': key}
r = s.post(base + "pimage_" + email, files=files, allow_redirects=True)
b = io.BytesIO(r.content)
img = Image.open(b)
img.show()
async def task():
base = "http://localhost:8008/"
async with httpx.AsyncClient() as client:
name = generate_random_string(10)
email = name + "@" + generate_random_string(10) + ".scam"
data = {'email': email, 'name': name, 'quality': 2}

await client.post(base + "sign-up", data=data)

r = await client.post(base + "download_key")
key = r.content

img = Image.open(r"documentation/scripts/stress_test/dog.4821.jpg")
b = io.BytesIO()
img.save(b, format="PNG")
b.seek(0)
b = b.getvalue()
files = {'file': ('image.png', b, 'image/png')}
data = {'is_profile': 'on', 'description': 'Look at my new ENOFT!'}

await client.post(base + "profile_" + email, files=files, data=data)

files = {'file': ('keyfile', key)}
r = await client.post(base + "pimage_" + email, files=files, follow_redirects=True)

b = io.BytesIO(r.content)
img = Image.open(b)


async def main(n):
loop = asyncio.get_event_loop()
with ThreadPoolExecutor() as executor:
tasks = [loop.run_in_executor(
executor, asyncio.run, task()) for _ in range(n)]
await asyncio.gather(*tasks)


if __name__ == "__main__":
n = 50 # Number of times to execute the script concurrently
t1 = time.time()
asyncio.run(main(n))
time_taken = time.time() - t1
gunicorn_config_raw = None
with open(r"service\gunicorn.conf.py", "r") as f:
gunicorn_config_raw = f.read()

logger.info(
f"Time taken: {time_taken} for {n} repeat \n {gunicorn_config_raw}")
print(f"Time taken: {time_taken}")

0 comments on commit acf637a

Please sign in to comment.