mirror of https://github.com/ivanch/tcc.git
changes
This commit is contained in:
parent
b55d7eba06
commit
e19595ab6c
|
@ -23,6 +23,7 @@ namespace TCC.Controllers
|
|||
mstream.Position = 0;
|
||||
|
||||
var result = ImageService.BoxBlurImage(mstream, radius);
|
||||
mstream.Close();
|
||||
|
||||
var blurredImageStream = new MemoryStream();
|
||||
result.Write(blurredImageStream);
|
||||
|
@ -49,6 +50,7 @@ namespace TCC.Controllers
|
|||
MemoryStream mstream = new MemoryStream();
|
||||
await HttpContext.Request.Body.CopyToAsync(mstream);
|
||||
mstream.Position = 0;
|
||||
mstream.Close();
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import requests
|
||||
|
||||
def download_file(url):
|
||||
local_filename = url.split('/')[-1]
|
||||
with requests.get(url, stream=True) as r:
|
||||
r.raise_for_status()
|
||||
with open(local_filename, 'wb') as f:
|
||||
for chunk in r.iter_content(chunk_size=8192):
|
||||
# If you have chunk encoded response uncomment if
|
||||
# and set chunk_size parameter to None.
|
||||
#if chunk:
|
||||
f.write(chunk)
|
||||
return local_filename
|
||||
|
||||
def init():
|
||||
download_file('https://files.ivanch.me/api/public/dl/Dj0gkp-m/small-image.png')
|
||||
download_file('https://files.ivanch.me/api/public/dl/FqHEPM1Q/big-image.png')
|
|
@ -6,25 +6,31 @@ import sys
|
|||
import os
|
||||
from graph import generate_req_graph, generate_resource_graph
|
||||
from math import floor
|
||||
from init import init
|
||||
|
||||
if len(sys.argv) != 3 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
|
||||
print("Usage: python testes.py <framework name> <container name>")
|
||||
if len(sys.argv) < 2 or len(sys.argv) > 3 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
|
||||
print("Usage: python testes.py <framework name> [container name]")
|
||||
sys.exit(1)
|
||||
|
||||
init()
|
||||
|
||||
THREADS = 10
|
||||
FRAMEWORK_NAME = sys.argv[1]
|
||||
CONTAINER_NAME = sys.argv[2]
|
||||
CONTAINER_NAME = sys.argv[2] if len(sys.argv) > 2 else ""
|
||||
URL_BASE = 'http://localhost:9080'
|
||||
BLUR_RADIUS = 5
|
||||
API_REQUESTS = [
|
||||
('/status/ok', range(0, 30_000, 5000)),
|
||||
('/image/load-image', range(0, 30_000, 5000)),
|
||||
('/static/simpleimage.png', range(0, 30_000, 5000)),
|
||||
('/image/load-big-image', range(0, 1_000, 200)),
|
||||
('/static/bigimage.png', range(0, 1_000, 200)),
|
||||
('/static/video.mp4', range(0, 10_000, 1_000)),
|
||||
('/image/save-big-image', 'POST', range(0, 30_000, 50), open('big-image.png', 'rb').read()),
|
||||
(f'/image/blur?radius={BLUR_RADIUS}', 'POST', range(0, 1_000, 50), open('small-image.png', 'rb').read()),
|
||||
('/status/ok', 'GET', range(0, 30_000, 5000), None),
|
||||
('/image/load-image', 'GET', range(0, 30_000, 5000), None),
|
||||
('/static/simpleimage.png', 'GET', range(0, 30_000, 5000), None),
|
||||
('/image/load-big-image', 'GET', range(0, 1_000, 200), None),
|
||||
('/static/bigimage.png', 'GET', range(0, 1_000, 200), None),
|
||||
('/static/video.mp4', 'GET', range(0, 10_000, 1_000), None),
|
||||
]
|
||||
|
||||
def send_request(url):
|
||||
def send_request(url, method = 'GET', payload = None):
|
||||
success = False
|
||||
responses = {
|
||||
2: 0, # OK
|
||||
|
@ -33,7 +39,11 @@ def send_request(url):
|
|||
}
|
||||
while not success:
|
||||
try:
|
||||
response = requests.get(url)
|
||||
response = None
|
||||
if method == 'GET':
|
||||
response = requests.get(url)
|
||||
elif method == 'POST':
|
||||
response = requests.post(url, data=payload, headers={'Content-Type': 'image/png'})
|
||||
except:
|
||||
continue
|
||||
success = response.status_code == 200
|
||||
|
@ -44,8 +54,8 @@ def getFileNames(endpoint):
|
|||
endpoint = endpoint.replace('/', '')
|
||||
|
||||
files = [
|
||||
f"req_{FRAMEWORK_NAME}_{endpoint}.csv",
|
||||
f"resource_{FRAMEWORK_NAME}_{endpoint}.csv",
|
||||
f"data/req_{FRAMEWORK_NAME}_{endpoint}.csv",
|
||||
f"data/resource_{FRAMEWORK_NAME}_{endpoint}.csv",
|
||||
]
|
||||
|
||||
return files
|
||||
|
@ -58,7 +68,7 @@ def record_resource(filename, requests, cpu, ram):
|
|||
with open(filename, "a") as file:
|
||||
file.write(f"{requests},{cpu},{ram}\n")
|
||||
|
||||
def run_tests(endpoint, num_requests):
|
||||
def run_tests(endpoint, method, num_requests, metadata):
|
||||
files = getFileNames(endpoint)
|
||||
for filename in files:
|
||||
if os.path.exists(filename):
|
||||
|
@ -83,7 +93,7 @@ def run_tests(endpoint, num_requests):
|
|||
|
||||
half = floor(num_request/2)
|
||||
for i in range(num_request):
|
||||
futures.append(executor.submit(send_request, url))
|
||||
futures.append(executor.submit(send_request, url, method, metadata))
|
||||
|
||||
if i == half:
|
||||
cpu, ram = get_resource_usage()
|
||||
|
@ -108,6 +118,8 @@ def run_tests(endpoint, num_requests):
|
|||
time.sleep(3)
|
||||
|
||||
def get_resource_usage():
|
||||
if CONTAINER_NAME == "": return 0, 0
|
||||
|
||||
try:
|
||||
client = docker.from_env()
|
||||
stats = client.containers.get(CONTAINER_NAME).stats(stream=False)
|
||||
|
@ -132,7 +144,12 @@ def get_ram_usage(stats):
|
|||
# percent = round(percentage, 2)
|
||||
return f"{percentage:.2f}"
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not os.path.exists("data"):
|
||||
os.mkdir("data")
|
||||
else:
|
||||
os.system("rm -rf data/*")
|
||||
|
||||
for endpoint, num_requests in API_REQUESTS:
|
||||
print(f"# {endpoint}")
|
||||
run_tests(endpoint, num_requests)
|
||||
for endpoint, method, num_requests, metadata in API_REQUESTS:
|
||||
print(f"# {endpoint}")
|
||||
run_tests(endpoint, method, num_requests, metadata)
|
||||
|
|
Loading…
Reference in New Issue