Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion benchmark/hicache/bench_mix.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,13 @@ async def handle_request(self, user_data):

def request_sender(self):
async def request_loop():
tasks = []
while True:
if self.sent_requests - self.completed_requests < self.max_parallel:
new_request = self.user_generator.pop()
if new_request:
asyncio.create_task(self.handle_request(new_request))
task = asyncio.create_task(self.handle_request(new_request))
tasks.append(task)
self.sent_requests += 1
else:
await asyncio.sleep(0.05)
Expand All @@ -440,6 +442,11 @@ async def request_loop():
self.done = True
break

# Cancel all pending tasks and wait for them to finish
for task in tasks:
task.cancel()
await asyncio.gather(*tasks, return_exceptions=True)

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(request_loop())
Expand Down
Loading