윤영준 윤영준 2023-10-24
hello yona
@90f5ef52de646a9957ddc41cee1aca65d77e9c17
 
2023_07_18_15_18_31_D_N_83.png (Binary) (added)
+++ 2023_07_18_15_18_31_D_N_83.png
Binary file is not shown
 
config.txt (added)
+++ config.txt
@@ -0,0 +1,6 @@
+URL=http://127.0.0.1:8080/action/image_anal
+LAT=37.5665
+LON=126.9780
+FILENAME=2023_07_18_15_18_31_D_N_83
+FILE_TYPE=.png
+REQUESTS=3000(파일 끝에 줄바꿈 문자 없음)
 
main.py (added)
+++ main.py
@@ -0,0 +1,49 @@
+import aiohttp
+import asyncio
+import time
+from aiohttp import FormData
+
+def read_config(file_name):
+    config = {}
+    with open(file_name, 'r') as f:
+        lines = f.readlines()
+        for line in lines:
+            key, value = line.strip().split('=')
+            if key in ["LAT", "LON", "REQUESTS"]:
+                value = float(value) if "." in value else int(value)
+            config[key] = value
+    return config
+
+config = read_config('config.txt')
+URL = config["URL"]
+LAT = config["LAT"]
+LON = config["LON"]
+FILENAME = config["FILENAME"]
+FILE_TYPE = config["FILE_TYPE"]
+FILE_PATH = FILENAME + FILE_TYPE
+requests = config["REQUESTS"]
+
+async def make_request(session):
+    data = FormData()
+    data.add_field("data", '{"gps_x": "%s", "gps_y": "%s", "filename": "%s", "file_type": "%s"}' % (LAT, LON, FILENAME, FILE_TYPE), content_type='application/json')
+    data.add_field('file', open(FILE_PATH, 'rb'), filename=FILE_PATH, content_type='image/png')
+
+    response = await session.post(URL, data=data)
+    print(response)
+    return await response.json()
+
+async def main():
+    async with aiohttp.ClientSession() as session:
+        tasks =[make_request(session) for _ in range(requests)]
+        await asyncio.gather(*tasks)
+        # tasks = [make_request(session) for _ in range(requests)]
+        # responses = await asyncio.gather(*tasks)
+        # for response in responses:
+        #     print(response)
+
+if __name__ == "__main__":
+    time_init = time.time()
+    asyncio.run(main())
+    time_finish = time.time()
+    time_elapsed = time_finish - time_init
+    print(f"for {requests}, it took {time_elapsed} \nTPS = {requests/time_elapsed}")
Add a comment
List