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

fix(dispatcher): prevent possible dispatcher bad behavior #3646

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 14 additions & 3 deletions src/bentoml/_internal/marshal/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,23 @@ async def controller(self):
continue
await asyncio.sleep(self.tick_interval)
continue
if (

# we are now free to dispatch whenever we like
while (
# if we don't already have enough requests,
n < self.max_batch_size
and n * (wn + dt + (a or 0)) <= self.optimizer.wait * decay
# we are not about to cancel the first request,
and latency_0 + dt <= self.max_latency_in_ms * 0.95
sauyon marked this conversation as resolved.
Show resolved Hide resolved
# and waiting will cause average latency to decrese
and n * (wn + dt + a) <= self.optimizer.wait * decay
):
n = len(self._queue)
now = time.time()
wn = now - self._queue[-1][0]
latency_0 = w0 + a * n + b

# wait for additional requests to arrive
await asyncio.sleep(self.tick_interval)
continue

if self.max_batch_size == -1: # batching is disabled
n_call_out = 1
Expand Down
Loading