Chromium Code Reviews| Index: appengine/gce-backend/instance_group_managers.py |
| diff --git a/appengine/gce-backend/instance_group_managers.py b/appengine/gce-backend/instance_group_managers.py |
| index c1e4487e4a080269d4c9df857d8342b16f066ac2..e8ab6410d1395d7fdd94fe7186d3317a18459777 100644 |
| --- a/appengine/gce-backend/instance_group_managers.py |
| +++ b/appengine/gce-backend/instance_group_managers.py |
| @@ -134,10 +134,12 @@ def create(key): |
| api = gce.Project(parent.project) |
| try: |
| + # Create the instance group manager with 0 instances. The resize cron job |
| + # will adjust this later. |
| result = api.create_instance_group_manager( |
| get_name(entity), |
| parent.url, |
| - entity.minimum_size, |
| + 0, |
| entity.key.id(), |
| base_name=get_base_name(entity), |
| ) |
| @@ -281,6 +283,12 @@ def resize(key): |
| Args: |
| key: ndb.Key for a models.InstanceGroupManager entity. |
| """ |
| + # To avoid a massive resize, impose a limit on how much larger we can |
| + # resize the instance group. Repeated calls will eventually allow the |
| + # instance group to reach its target size. Cron timing together with |
| + # this limit controls the rate at which instances are created. |
| + RESIZE_LIMIT = 100 |
| + |
| entity = key.get() |
| if not entity: |
| logging.warning('InstanceGroupManager does not exist: %s', key) |
| @@ -298,13 +306,17 @@ def resize(key): |
| logging.warning('InstanceTemplateRevision project unspecified: %s', key) |
| return |
| - # For now, just ensure a minimum size. |
| - if entity.current_size >= entity.minimum_size: |
| + api = gce.Project(parent.project) |
| + response = api.get_instance_group_manager(get_name(entity), key.id()) |
| + |
| + # Try to reach the target size, but avoid increasing the number of |
| + # instances by more than the resize limit. For now, the target size |
| + # is just the minimum size. |
| + target_size = min(entity.minimum_size, response['targetSize'] + RESIZE_LIMIT) |
| + if response['targetSize'] >= target_size: |
|
Vadim Sh.
2016/06/29 23:17:48
how is it going to scale down then if we change mi
smut
2016/06/29 23:24:38
We never scale down, we just wait for excess VMs t
|
| return |
| - api = gce.Project(parent.project) |
| - api.resize_managed_instance_group( |
| - get_name(entity), key.id(), entity.minimum_size) |
| + api.resize_managed_instance_group(response['name'], key.id(), target_size) |
| def schedule_resize(): |