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

Unified Diff: scripts/slave/recipe_modules/goma/api.py

Issue 2291273005: Add counting the number of CPU's in goma module (Closed)
Patch Set: add comment why I use python.inline Created 4 years, 3 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 | scripts/slave/recipe_modules/goma/example.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/slave/recipe_modules/goma/api.py
diff --git a/scripts/slave/recipe_modules/goma/api.py b/scripts/slave/recipe_modules/goma/api.py
index 97c12f3f6e200a5787d3a682631de8b9f410a1b0..2d52df9a2aef81cf06e4340a3a154627efa93df8 100644
--- a/scripts/slave/recipe_modules/goma/api.py
+++ b/scripts/slave/recipe_modules/goma/api.py
@@ -14,6 +14,7 @@ class GomaApi(recipe_api.RecipeApi):
self._goma_ctl_env = {}
self._cloudtail_pid = None
+ self._goma_jobs = None
@property
def service_account_json_path(self):
@@ -31,6 +32,46 @@ class GomaApi(recipe_api.RecipeApi):
assert self._goma_dir
return self.m.path.join(self._goma_dir, 'jsonstatus')
+ @property
+ def recommended_goma_jobs(self):
+ """
+ Return the recommended number of jobs for parallel build using Goma.
+
+ This function caches the _goma_jobs.
+ """
+ if self._goma_jobs:
+ return self._goma_jobs
+
+ # In presubmit, a buildbot generates recipe json file and
+ # another buildbot checks generated recipe,
+ # so we need to use python.inline not to change
+ # behavior of recipes.
+ step_result = self.m.python.inline(
+ 'calculate the number of recommended jobs',
+ """
+import multiprocessing
+import sys
+
+job_limit = 200
+if sys.platform.startswith('linux'):
+ # Use 80 for linux not to load goma backend.
+ job_limit = 80
+
+try:
+ jobs = min(job_limit, multiprocessing.cpu_count() * 10)
+except NotImplementedError:
+ jobs = 50
+
+print jobs
+ """,
+ stdout=self.m.raw_io.output(),
+ step_test_data=(
+ lambda: self.m.raw_io.test_api.stream_output('50\n'))
+ )
+ self._goma_jobs = int(step_result.stdout)
+
+ return self._goma_jobs
+
def ensure_goma(self, canary=False):
with self.m.step.nest('ensure_goma'):
with self.m.step.context({'infra_step': True}):
« no previous file with comments | « no previous file | scripts/slave/recipe_modules/goma/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698