-
Notifications
You must be signed in to change notification settings - Fork 529
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
[Serve] Not using previously failed replica when retry a failed request #3916
base: master
Are you sure you want to change the base?
Changes from 6 commits
847d78e
97e944f
56ccf63
39444aa
0f4c9ea
f94491c
2898816
a6980b7
615181c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import asyncio | ||
import logging | ||
import threading | ||
from typing import Dict, Union | ||
from typing import Dict, List, Union | ||
|
||
import aiohttp | ||
import fastapi | ||
|
@@ -160,11 +160,28 @@ async def _proxy_with_retries( | |
# SkyServe supports serving on Spot Instances. To avoid preemptions | ||
# during request handling, we add a retry here. | ||
retry_cnt = 0 | ||
# Here we try to not retry those failed replicas for the case when the | ||
# replica is in a NOT_READY state but does not sync-ed to the load | ||
# balancer yet. However, we still maintain a per-request failed replica | ||
# list instead of the global one to avoid the case for transient | ||
# networking issues, and letting new requests to retry them. Since our | ||
# LB policy is a global one, when the request rate is high, it is likely | ||
# that multiple retries on a single request will use the same replica. | ||
# Here we use the failed replica list to keep track of the failures | ||
# happened on every request and try to avoid them in the next retry. | ||
failed_replica_urls: List[str] = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! Updated. Thanks! |
||
while True: | ||
retry_cnt += 1 | ||
with self._client_pool_lock: | ||
ready_replica_url = self._load_balancing_policy.select_replica( | ||
request) | ||
request, failed_replica_urls) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems if this is the case, we will never retry for a transient network issue. How about we allow retrying on previously failed URLs if retry_cnt has not reached the maximum amount of retries? If that cause too much overheads for retries, we can probably reduce the interval between retries? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only retry logic in one request and it will still be selected by following requests. This PR is mainly for the case when the replica is in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I am talking about a single request. Should we fail directly for that specific request if there are replicas available but just transient network issue during the time load balancer is sending that request to the replica? I think our original purpose for this retry is to retry on network issues. I am proposing the following to allow retries for the same replica if we have not reach max retry count yet. if ready_replica_url is None and failed_replica_urls:
failed_replica_urls = [] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! PTAL again |
||
# If all replicas are failed, retry them again as some | ||
# of them might be transient networking issues. | ||
if ready_replica_url is None and failed_replica_urls: | ||
failed_replica_urls = [] | ||
ready_replica_url = ( | ||
self._load_balancing_policy.select_replica( | ||
request, failed_replica_urls)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may increase the index twice for round robin. Should we instead, just check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that is a good call. Done! |
||
if ready_replica_url is None: | ||
response_or_exception = fastapi.HTTPException( | ||
# 503 means that the server is currently | ||
|
@@ -184,6 +201,8 @@ async def _proxy_with_retries( | |
# 499 means a client terminates the connection | ||
# before the server is able to respond. | ||
return fastapi.responses.Response(status_code=499) | ||
assert ready_replica_url is not None | ||
failed_replica_urls.append(ready_replica_url) | ||
# TODO(tian): Fail fast for errors like 404 not found. | ||
if retry_cnt == constants.LB_MAX_RETRY: | ||
if isinstance(response_or_exception, fastapi.HTTPException): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks awesome! Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I change
to allow multiple requests to still try xxx for one request
to
to allow multiple requests to still try xxx for one time
since the former is slightly confusing (multiple req for one req).