Skip to content

Commit

Permalink
[Serve] Update min_replicas (#3057)
Browse files Browse the repository at this point in the history
* fix

* add a smoke test

* change comment

* revert task.yaml
  • Loading branch information
MaoZiming authored Jan 31, 2024
1 parent e3f09ab commit 3517f55
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sky/serve/autoscalers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def update_version(self, version: int,
f'latest version: {self.latest_version}')
return
self.latest_version = version
self.min_nodes = spec.min_replicas
self.max_nodes = (spec.max_replicas if spec.max_replicas is not None
else spec.min_replicas)
self.min_replicas = spec.min_replicas
self.max_replicas = (spec.max_replicas if spec.max_replicas is not None
else spec.min_replicas)
# Reclip self.target_num_replicas with new min and max replicas.
self.target_num_replicas = max(
self.min_replicas, min(self.max_replicas, self.target_num_replicas))
Expand Down
15 changes: 15 additions & 0 deletions tests/skyserve/update/num_min_one.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
service:
readiness_probe:
path: /health
initial_delay_seconds: 20
replica_policy:
min_replicas: 1

resources:
ports: 8080
cloud: gcp
cpus: 2+

workdir: examples/serve/http_server

run: python3 server.py --port 8080
16 changes: 16 additions & 0 deletions tests/skyserve/update/num_min_two.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
service:
readiness_probe:
path: /health
initial_delay_seconds: 20
replica_policy:
min_replicas: 2

resources:
ports: 8080
cloud: gcp
cpus: 2+

workdir: examples/serve/http_server

run: python3 server.py --port 8080

24 changes: 24 additions & 0 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -3088,6 +3088,30 @@ def test_skyserve_update():
run_one_test(test)


@pytest.mark.gcp
@pytest.mark.sky_serve
def test_skyserve_update_autoscale():
"""Test skyserve update with autoscale"""
name = _get_service_name()
test = Test(
f'test-skyserve-update-autoscale',
[
f'sky serve up -n {name} -y tests/skyserve/update/num_min_two.yaml',
_SERVE_WAIT_UNTIL_READY.format(name=name, replica_num=2),
f'{_get_serve_endpoint(name)}; curl -L http://$endpoint | grep "Hi, SkyPilot here"',
f'sky serve update {name} -y tests/skyserve/update/num_min_one.yaml',
# sleep before update is registered.
'sleep 20',
# Timeout will be triggered when update fails.
_SERVE_WAIT_UNTIL_READY.format(name=name, replica_num=1),
f'{_get_serve_endpoint(name)}; curl -L http://$endpoint | grep "Hi, SkyPilot here!"',
],
_TEARDOWN_SERVICE.format(name=name),
timeout=20 * 60,
)
run_one_test(test)


# ------- Testing user ray cluster --------
def test_user_ray_cluster(generic_cloud: str):
name = _get_cluster_name()
Expand Down

0 comments on commit 3517f55

Please sign in to comment.