+++ 2023_07_18_15_18_31_D_N_83.png
Binary file is not shown |
+++ config.txt
... | ... | @@ -0,0 +1,6 @@ |
1 | +URL=http://127.0.0.1:8080/action/image_anal | |
2 | +LAT=37.5665 | |
3 | +LON=126.9780 | |
4 | +FILENAME=2023_07_18_15_18_31_D_N_83 | |
5 | +FILE_TYPE=.png | |
6 | +REQUESTS=3000(파일 끝에 줄바꿈 문자 없음) |
+++ main.py
... | ... | @@ -0,0 +1,49 @@ |
1 | +import aiohttp | |
2 | +import asyncio | |
3 | +import time | |
4 | +from aiohttp import FormData | |
5 | + | |
6 | +def read_config(file_name): | |
7 | + config = {} | |
8 | + with open(file_name, 'r') as f: | |
9 | + lines = f.readlines() | |
10 | + for line in lines: | |
11 | + key, value = line.strip().split('=') | |
12 | + if key in ["LAT", "LON", "REQUESTS"]: | |
13 | + value = float(value) if "." in value else int(value) | |
14 | + config[key] = value | |
15 | + return config | |
16 | + | |
17 | +config = read_config('config.txt') | |
18 | +URL = config["URL"] | |
19 | +LAT = config["LAT"] | |
20 | +LON = config["LON"] | |
21 | +FILENAME = config["FILENAME"] | |
22 | +FILE_TYPE = config["FILE_TYPE"] | |
23 | +FILE_PATH = FILENAME + FILE_TYPE | |
24 | +requests = config["REQUESTS"] | |
25 | + | |
26 | +async def make_request(session): | |
27 | + data = FormData() | |
28 | + data.add_field("data", '{"gps_x": "%s", "gps_y": "%s", "filename": "%s", "file_type": "%s"}' % (LAT, LON, FILENAME, FILE_TYPE), content_type='application/json') | |
29 | + data.add_field('file', open(FILE_PATH, 'rb'), filename=FILE_PATH, content_type='image/png') | |
30 | + | |
31 | + response = await session.post(URL, data=data) | |
32 | + print(response) | |
33 | + return await response.json() | |
34 | + | |
35 | +async def main(): | |
36 | + async with aiohttp.ClientSession() as session: | |
37 | + tasks =[make_request(session) for _ in range(requests)] | |
38 | + await asyncio.gather(*tasks) | |
39 | + # tasks = [make_request(session) for _ in range(requests)] | |
40 | + # responses = await asyncio.gather(*tasks) | |
41 | + # for response in responses: | |
42 | + # print(response) | |
43 | + | |
44 | +if __name__ == "__main__": | |
45 | + time_init = time.time() | |
46 | + asyncio.run(main()) | |
47 | + time_finish = time.time() | |
48 | + time_elapsed = time_finish - time_init | |
49 | + print(f"for {requests}, it took {time_elapsed} \nTPS = {requests/time_elapsed}") |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?