diff options
author | Shawn O. Pearce <sop@google.com> | 2011-09-22 17:23:41 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2011-09-22 18:08:26 -0700 |
commit | 97d2b2f7a087bfc695536ae9be962406d82152f2 (patch) | |
tree | 7cf3c07c6c9f42f17e1ade91eb354f95a16a0a80 | |
parent | 3a0e782790ab83e3b1e93fe2fd57f7197ace2f76 (diff) | |
download | git-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.py | 12 |
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: | |||
28 | except ImportError: | 28 | except ImportError: |
29 | import dummy_threading as _threading | 29 | import dummy_threading as _threading |
30 | 30 | ||
31 | try: | ||
32 | import resource | ||
33 | def _rlimit_nofile(): | ||
34 | return resource.getrlimit(resource.RLIMIT_NOFILE) | ||
35 | except ImportError: | ||
36 | def _rlimit_nofile(): | ||
37 | return (256, 256) | ||
38 | |||
31 | from git_command import GIT | 39 | from git_command import GIT |
32 | from git_refs import R_HEADS | 40 | from git_refs import R_HEADS |
33 | from project import HEAD | 41 | from 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) |