File tree 1 file changed +54
-0
lines changed
1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ import asyncio
2
+ import aiohttp
3
+ import matplotlib .pyplot as plt
4
+
5
+ PROBING_INTERVAL_SECONDS = 1
6
+ TOTAL_PROBES = 60
7
+
8
+ data = []
9
+
10
+
11
+ async def on_request_start (session , trace_config_ctx , params ):
12
+ trace_config_ctx .start = asyncio .get_event_loop ().time ()
13
+
14
+
15
+ async def on_request_end (session , trace_config_ctx , params ):
16
+ elapsed = asyncio .get_event_loop ().time () - trace_config_ctx .start
17
+ if params .response .status != 200 or await params .response .text () != "I'm alive" :
18
+ elapsed = 0
19
+
20
+ print ("." )
21
+
22
+ data .append ((trace_config_ctx .start , elapsed ))
23
+
24
+ # print(await params.response.text())
25
+ # print("Request took {}".format(elapsed))
26
+
27
+
28
+ trace_config = aiohttp .TraceConfig ()
29
+ trace_config .on_request_start .append (on_request_start )
30
+ trace_config .on_request_end .append (on_request_end )
31
+
32
+
33
+ async def probe (sleep = 0 ):
34
+ async with aiohttp .ClientSession (trace_configs = [trace_config ]) as session :
35
+ await asyncio .sleep (sleep )
36
+ try :
37
+ await session .get ("https://lab.polymed.online/health/" )
38
+ except :
39
+ pass
40
+
41
+
42
+ async def main ():
43
+ async with asyncio .TaskGroup () as tg :
44
+ for offset in range (TOTAL_PROBES ):
45
+ tg .create_task (probe (offset * PROBING_INTERVAL_SECONDS ))
46
+
47
+
48
+ asyncio .run (main ())
49
+
50
+ data .sort ()
51
+ times , values = zip (* data )
52
+
53
+ plt .plot (times , values )
54
+ plt .show ()
You can’t perform that action at this time.
0 commit comments