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

[UX][Serve] More comprehensive target_qps_per_replica check #3361

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions sky/serve/autoscalers.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ def collect_request_information(
index = bisect.bisect_left(self.request_timestamps,
current_time - self.qps_window_size)
self.request_timestamps = self.request_timestamps[index:]
logger.info(f'Num of requests in the last {self.qps_window_size} '
f'seconds: {len(self.request_timestamps)}')

def _set_target_num_replica_with_hysteresis(self) -> None:
"""Set target_num_replicas based on request rate with hysteresis."""
Expand Down
40 changes: 30 additions & 10 deletions sky/serve/service_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,44 @@ def __init__(
) -> None:
if max_replicas is not None and max_replicas < min_replicas:
with ux_utils.print_exception_no_traceback():
raise ValueError(
'max_replicas must be greater than or equal to min_replicas'
)
raise ValueError('max_replicas must be greater than or '
'equal to min_replicas. Found: '
f'min_replicas={min_replicas}, '
f'max_replicas={max_replicas}')

if target_qps_per_replica is not None and max_replicas is None:
with ux_utils.print_exception_no_traceback():
raise ValueError('max_replicas must be set where '
'target_qps_per_replica is set.')
if target_qps_per_replica is not None:
if max_replicas is None:
with ux_utils.print_exception_no_traceback():
raise ValueError('max_replicas must be set where '
'target_qps_per_replica is set.')
if max_replicas == min_replicas:
cblmemo marked this conversation as resolved.
Show resolved Hide resolved
with ux_utils.print_exception_no_traceback():
raise ValueError(
'Detect min_replicas equal to max_replicas while '
'target_qps_per_replica is set. No autoscaling will '
'be performed. Please set different min_replicas and '
'max_replicas to enable autoscaling.')
else:
if max_replicas is not None and max_replicas != min_replicas:
with ux_utils.print_exception_no_traceback():
raise ValueError(
'Detect different min_replicas and max_replicas '
'while target_qps_per_replica is not set. To enable '
'autoscaling, please set target_qps_per_replica.')
cblmemo marked this conversation as resolved.
Show resolved Hide resolved

if not readiness_path.startswith('/'):
with ux_utils.print_exception_no_traceback():
raise ValueError('readiness_path must start with a slash (/). '
f'Got: {readiness_path}')

# TODO(tian): Following field are deprecated. Remove after 2 minor
# release, i.e. 0.6.0.
if qps_upper_threshold is not None or qps_lower_threshold is not None:
with ux_utils.print_exception_no_traceback():
raise ValueError(
'Field `qps_upper_threshold` and `qps_lower_threshold`'
'under `replica_policy` are deprecated. '
'Please use target_qps_per_replica instead.')

if auto_restart is not None:
with ux_utils.print_exception_no_traceback():
raise ValueError(
Expand Down Expand Up @@ -236,10 +253,13 @@ def autoscaling_policy_str(self):
min_plural = '' if self.min_replicas == 1 else 's'
if self.max_replicas == self.min_replicas or self.max_replicas is None:
return f'Fixed {self.min_replicas} replica{min_plural}'
# Already checked in __init__.
assert self.target_qps_per_replica is not None
# TODO(tian): Refactor to contain more information
max_plural = '' if self.max_replicas == 1 else 's'
return (f'Autoscaling from {self.min_replicas} to '
f'{self.max_replicas} replica{max_plural}')
return (f'Autoscaling from {self.min_replicas} to {self.max_replicas} '
f'replica{max_plural} with Target {self.target_qps_per_replica}'
' QPS/replica')
cblmemo marked this conversation as resolved.
Show resolved Hide resolved

def __repr__(self) -> str:
return textwrap.dedent(f"""\
Expand Down
Loading