shutdown rps printer once series processing is done, rps 1 decimal

This commit is contained in:
2025-06-01 03:23:12 -05:00
parent c55046c708
commit efcab62336

17
main.py
View File

@@ -203,8 +203,10 @@ async def main():
) )
total_indexer_counts.update(indexer_counts) total_indexer_counts.update(indexer_counts)
async def print_rps(interval=3): async def print_rps(interval=3, stop_event=None):
while True: while True:
if stop_event and stop_event.is_set():
break
await anyio.sleep(interval) await anyio.sleep(interval)
async with counter_lock: async with counter_lock:
rps = request_counter["count"] / interval rps = request_counter["count"] / interval
@@ -212,15 +214,18 @@ async def main():
request_counter["count"] = 0 request_counter["count"] = 0
await logger.info( await logger.info(
"Requests per second and active requests", "Requests per second and active requests",
rps=rps, rps=round(rps, 1),
active_requests=active, active_requests=active,
interval=interval,
) )
stop_event = anyio.Event()
async with anyio.create_task_group() as tg: async with anyio.create_task_group() as tg:
tg.start_soon(print_rps, 3) tg.start_soon(print_rps, 3, stop_event)
for series in series_list: async with anyio.create_task_group() as series_tg:
tg.start_soon(process_and_log, series) for series in series_list:
series_tg.start_soon(process_and_log, series)
stop_event.set()
await logger.info( await logger.info(
"Total indexer counts across all series", "Total indexer counts across all series",