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

Side by Side Diff: appengine/swarming/handlers_backend.py

Issue 2258103002: Further limit TaskTags aggregation cron job to avoid OOM (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: Properly handle None Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The LUCI Authors. All rights reserved. 1 # Copyright 2014 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """Main entry point for Swarming backend handlers.""" 5 """Main entry point for Swarming backend handlers."""
6 6
7 import datetime 7 import datetime
8 import json 8 import json
9 import logging 9 import logging
10 10
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 count = 0 137 count = 0
138 q = task_result.get_result_summaries_query( 138 q = task_result.get_result_summaries_query(
139 now - datetime.timedelta(hours=12), None, 'created_ts', 'all', None) 139 now - datetime.timedelta(hours=12), None, 'created_ts', 'all', None)
140 cursor = None 140 cursor = None
141 while True: 141 while True:
142 tasks, cursor = datastore_utils.fetch_page(q, 1000, cursor) 142 tasks, cursor = datastore_utils.fetch_page(q, 1000, cursor)
143 count += len(tasks) 143 count += len(tasks)
144 for t in tasks: 144 for t in tasks:
145 for i in t.tags: 145 for i in t.tags:
146 k, v = i.split(':', 1) 146 k, v = i.split(':', 1)
147 if k != 'cron_invocation_id': 147 s = seen.setdefault(k, set())
148 seen.setdefault(k, set()).add(v) 148 if s is not None:
149 s.add(v)
150 # 128 is arbitrary large number to avoid OOM
151 if len(s) >= 128:
152 logging.info('Stripping tag %s because there are too many', k)
153 seen[k] = None
149 if not cursor or len(tasks) == 0: 154 if not cursor or len(tasks) == 0:
150 break 155 break
151 156
152 tags = [ 157 tags = [
153 task_result.TagValues(tag=k, values=sorted(values)) 158 task_result.TagValues(tag=k, values=sorted(values))
154 for k, values in sorted(seen.iteritems()) 159 for k, values in sorted(seen.iteritems()) if values is not None
155 ] 160 ]
156 161
157 logging.info('From %d tasks, saw tags %s', count, tags) 162 logging.info('From %d tasks, saw tags %s', count, tags)
158 task_result.TagAggregation( 163 task_result.TagAggregation(
159 key=task_result.TagAggregation.KEY, 164 key=task_result.TagAggregation.KEY,
160 tags=tags, 165 tags=tags,
161 ts=now).put() 166 ts=now).put()
162 167
163 168
164 class CronMachineProviderPubSubHandler(webapp2.RequestHandler): 169 class CronMachineProviderPubSubHandler(webapp2.RequestHandler):
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 ('/internal/taskqueue/cleanup_data', TaskCleanupDataHandler), 253 ('/internal/taskqueue/cleanup_data', TaskCleanupDataHandler),
249 (r'/internal/taskqueue/pubsub/<task_id:[0-9a-f]+>', TaskSendPubSubMessage), 254 (r'/internal/taskqueue/pubsub/<task_id:[0-9a-f]+>', TaskSendPubSubMessage),
250 ('/internal/taskqueue/pubsub/machine_provider', 255 ('/internal/taskqueue/pubsub/machine_provider',
251 TaskMachineProviderPubSubHandler), 256 TaskMachineProviderPubSubHandler),
252 257
253 # Mapreduce related urls. 258 # Mapreduce related urls.
254 (r'/internal/taskqueue/mapreduce/launch/<job_id:[^\/]+>', 259 (r'/internal/taskqueue/mapreduce/launch/<job_id:[^\/]+>',
255 InternalLaunchMapReduceJobWorkerHandler), 260 InternalLaunchMapReduceJobWorkerHandler),
256 ] 261 ]
257 return [webapp2.Route(*a) for a in routes] 262 return [webapp2.Route(*a) for a in routes]
OLDNEW
« 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