Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2222)

Unified Diff: appengine/gce-backend/instance_group_managers.py

Issue 2110253003: Allow no more than 100 instances to be created on each resizing run (Closed) Base URL: https://github.com/luci/luci-py.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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():
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698