Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[App] Fixing auto batching in Autoscaler #16110

Merged
merged 19 commits into from
Dec 20, 2022
Merged
Changes from 28 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
13 changes: 6 additions & 7 deletions src/lightning_app/components/serve/auto_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,16 @@ async def send_batch(self, batch: List[Tuple[str, _BatchRequestModel]]):
self._responses.update(result)

async def consumer(self):
self._last_batch_sent = time.time()
while True:
await asyncio.sleep(0.05)

batch = self._batch[: self.max_batch_size]
while batch and (
(len(batch) == self.max_batch_size) or ((time.time() - self._last_batch_sent) > self.timeout_batching)
):
is_batch_ready = len(batch) == self.max_batch_size
is_batch_timeout = time.time() - self._last_batch_sent > self.timeout_batching
if batch and (is_batch_ready or is_batch_timeout):
asyncio.create_task(self.send_batch(batch))

self._batch = self._batch[self.max_batch_size :]
batch = self._batch[: self.max_batch_size]
# resetting the batch array, TODO - not locking the array
self._batch = self._batch[len(batch) :]
self._last_batch_sent = time.time()

async def process_request(self, data: BaseModel):
Expand Down