summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2011-09-22 17:23:41 -0700
committerShawn O. Pearce <sop@google.com>2011-09-22 18:08:26 -0700
commit97d2b2f7a087bfc695536ae9be962406d82152f2 (patch)
tree7cf3c07c6c9f42f17e1ade91eb354f95a16a0a80
parent3a0e782790ab83e3b1e93fe2fd57f7197ace2f76 (diff)
downloadgit-repo-97d2b2f7a087bfc695536ae9be962406d82152f2.tar.gz
sync: Limit -j to file descriptors
Each worker thread requires at least 3 file descriptors to run the forked 'git fetch' child to operate against the local repository. Mac OS X has the RLIMIT_NOFILE set to 256 by default, which means a sync -j128 often fails when the workers run out of pipes within the Python parent process. Change-Id: I2cdb14621b899424b079daf7969bc8c16b85b903 Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r--subcmds/sync.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 4689ac8b..93010c51 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -28,6 +28,14 @@ try:
28except ImportError: 28except ImportError:
29 import dummy_threading as _threading 29 import dummy_threading as _threading
30 30
31try:
32 import resource
33 def _rlimit_nofile():
34 return resource.getrlimit(resource.RLIMIT_NOFILE)
35except ImportError:
36 def _rlimit_nofile():
37 return (256, 256)
38
31from git_command import GIT 39from git_command import GIT
32from git_refs import R_HEADS 40from git_refs import R_HEADS
33from project import HEAD 41from project import HEAD
@@ -312,6 +320,10 @@ uncommitted changes are present' % project.relpath
312 def Execute(self, opt, args): 320 def Execute(self, opt, args):
313 if opt.jobs: 321 if opt.jobs:
314 self.jobs = opt.jobs 322 self.jobs = opt.jobs
323 if self.jobs > 1:
324 soft_limit, _ = _rlimit_nofile()
325 self.jobs = min(self.jobs, (soft_limit - 5) / 3)
326
315 if opt.network_only and opt.detach_head: 327 if opt.network_only and opt.detach_head:
316 print >>sys.stderr, 'error: cannot combine -n and -d' 328 print >>sys.stderr, 'error: cannot combine -n and -d'
317 sys.exit(1) 329 sys.exit(1)