diff options
-rw-r--r-- | manifest_xml.py | 8 | ||||
-rw-r--r-- | subcmds/sync.py | 67 |
2 files changed, 45 insertions, 30 deletions
diff --git a/manifest_xml.py b/manifest_xml.py index 12614c64..ee513a7e 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -123,7 +123,7 @@ class _Default(object): | |||
123 | destBranchExpr = None | 123 | destBranchExpr = None |
124 | upstreamExpr = None | 124 | upstreamExpr = None |
125 | remote = None | 125 | remote = None |
126 | sync_j = 1 | 126 | sync_j = None |
127 | sync_c = False | 127 | sync_c = False |
128 | sync_s = False | 128 | sync_s = False |
129 | sync_tags = True | 129 | sync_tags = True |
@@ -548,7 +548,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
548 | if d.upstreamExpr: | 548 | if d.upstreamExpr: |
549 | have_default = True | 549 | have_default = True |
550 | e.setAttribute('upstream', d.upstreamExpr) | 550 | e.setAttribute('upstream', d.upstreamExpr) |
551 | if d.sync_j > 1: | 551 | if d.sync_j is not None: |
552 | have_default = True | 552 | have_default = True |
553 | e.setAttribute('sync-j', '%d' % d.sync_j) | 553 | e.setAttribute('sync-j', '%d' % d.sync_j) |
554 | if d.sync_c: | 554 | if d.sync_c: |
@@ -1462,8 +1462,8 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
1462 | d.destBranchExpr = node.getAttribute('dest-branch') or None | 1462 | d.destBranchExpr = node.getAttribute('dest-branch') or None |
1463 | d.upstreamExpr = node.getAttribute('upstream') or None | 1463 | d.upstreamExpr = node.getAttribute('upstream') or None |
1464 | 1464 | ||
1465 | d.sync_j = XmlInt(node, 'sync-j', 1) | 1465 | d.sync_j = XmlInt(node, 'sync-j', None) |
1466 | if d.sync_j <= 0: | 1466 | if d.sync_j is not None and d.sync_j <= 0: |
1467 | raise ManifestParseError('%s: sync-j must be greater than 0, not "%s"' % | 1467 | raise ManifestParseError('%s: sync-j must be greater than 0, not "%s"' % |
1468 | (self.manifestFile, d.sync_j)) | 1468 | (self.manifestFile, d.sync_j)) |
1469 | 1469 | ||
diff --git a/subcmds/sync.py b/subcmds/sync.py index fa61d551..57ee0540 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -52,7 +52,7 @@ import git_superproject | |||
52 | import gitc_utils | 52 | import gitc_utils |
53 | from project import Project | 53 | from project import Project |
54 | from project import RemoteSpec | 54 | from project import RemoteSpec |
55 | from command import Command, MirrorSafeCommand, WORKER_BATCH_SIZE | 55 | from command import Command, DEFAULT_LOCAL_JOBS, MirrorSafeCommand, WORKER_BATCH_SIZE |
56 | from error import RepoChangedException, GitError, ManifestParseError | 56 | from error import RepoChangedException, GitError, ManifestParseError |
57 | import platform_utils | 57 | import platform_utils |
58 | from project import SyncBuffer | 58 | from project import SyncBuffer |
@@ -65,7 +65,6 @@ _ONE_DAY_S = 24 * 60 * 60 | |||
65 | 65 | ||
66 | 66 | ||
67 | class Sync(Command, MirrorSafeCommand): | 67 | class Sync(Command, MirrorSafeCommand): |
68 | jobs = 1 | ||
69 | COMMON = True | 68 | COMMON = True |
70 | MULTI_MANIFEST_SUPPORT = True | 69 | MULTI_MANIFEST_SUPPORT = True |
71 | helpSummary = "Update working tree to the latest revision" | 70 | helpSummary = "Update working tree to the latest revision" |
@@ -168,21 +167,16 @@ If the remote SSH daemon is Gerrit Code Review, version 2.0.10 or | |||
168 | later is required to fix a server side protocol bug. | 167 | later is required to fix a server side protocol bug. |
169 | 168 | ||
170 | """ | 169 | """ |
171 | PARALLEL_JOBS = 1 | 170 | # A value of 0 means we want parallel jobs, but we'll determine the default |
172 | 171 | # value later on. | |
173 | def _CommonOptions(self, p): | 172 | PARALLEL_JOBS = 0 |
174 | if self.outer_client and self.outer_client.manifest: | ||
175 | try: | ||
176 | self.PARALLEL_JOBS = self.outer_client.manifest.default.sync_j | ||
177 | except ManifestParseError: | ||
178 | pass | ||
179 | super()._CommonOptions(p) | ||
180 | 173 | ||
181 | def _Options(self, p, show_smart=True): | 174 | def _Options(self, p, show_smart=True): |
182 | p.add_option('--jobs-network', default=None, type=int, metavar='JOBS', | 175 | p.add_option('--jobs-network', default=None, type=int, metavar='JOBS', |
183 | help='number of network jobs to run in parallel (defaults to --jobs)') | 176 | help='number of network jobs to run in parallel (defaults to --jobs or 1)') |
184 | p.add_option('--jobs-checkout', default=None, type=int, metavar='JOBS', | 177 | p.add_option('--jobs-checkout', default=None, type=int, metavar='JOBS', |
185 | help='number of local checkout jobs to run in parallel (defaults to --jobs)') | 178 | help='number of local checkout jobs to run in parallel (defaults to --jobs or ' |
179 | f'{DEFAULT_LOCAL_JOBS})') | ||
186 | 180 | ||
187 | p.add_option('-f', '--force-broken', | 181 | p.add_option('-f', '--force-broken', |
188 | dest='force_broken', action='store_true', | 182 | dest='force_broken', action='store_true', |
@@ -451,7 +445,7 @@ later is required to fix a server side protocol bug. | |||
451 | def _Fetch(self, projects, opt, err_event, ssh_proxy): | 445 | def _Fetch(self, projects, opt, err_event, ssh_proxy): |
452 | ret = True | 446 | ret = True |
453 | 447 | ||
454 | jobs = opt.jobs_network if opt.jobs_network else self.jobs | 448 | jobs = opt.jobs_network |
455 | fetched = set() | 449 | fetched = set() |
456 | pm = Progress('Fetching', len(projects), delay=False, quiet=opt.quiet) | 450 | pm = Progress('Fetching', len(projects), delay=False, quiet=opt.quiet) |
457 | 451 | ||
@@ -651,7 +645,7 @@ later is required to fix a server side protocol bug. | |||
651 | return ret | 645 | return ret |
652 | 646 | ||
653 | return self.ExecuteInParallel( | 647 | return self.ExecuteInParallel( |
654 | opt.jobs_checkout if opt.jobs_checkout else self.jobs, | 648 | opt.jobs_checkout, |
655 | functools.partial(self._CheckoutOne, opt.detach_head, opt.force_sync), | 649 | functools.partial(self._CheckoutOne, opt.detach_head, opt.force_sync), |
656 | all_projects, | 650 | all_projects, |
657 | callback=_ProcessResults, | 651 | callback=_ProcessResults, |
@@ -691,8 +685,7 @@ later is required to fix a server side protocol bug. | |||
691 | project.bare_git, | 685 | project.bare_git, |
692 | ) | 686 | ) |
693 | 687 | ||
694 | cpu_count = os.cpu_count() | 688 | jobs = opt.jobs |
695 | jobs = min(self.jobs, cpu_count) | ||
696 | 689 | ||
697 | if jobs < 2: | 690 | if jobs < 2: |
698 | for (run_gc, bare_git) in tidy_dirs.values(): | 691 | for (run_gc, bare_git) in tidy_dirs.values(): |
@@ -704,6 +697,7 @@ later is required to fix a server side protocol bug. | |||
704 | pm.end() | 697 | pm.end() |
705 | return | 698 | return |
706 | 699 | ||
700 | cpu_count = os.cpu_count() | ||
707 | config = {'pack.threads': cpu_count // jobs if cpu_count > jobs else 1} | 701 | config = {'pack.threads': cpu_count // jobs if cpu_count > jobs else 1} |
708 | 702 | ||
709 | threads = set() | 703 | threads = set() |
@@ -1011,9 +1005,6 @@ later is required to fix a server side protocol bug. | |||
1011 | sys.exit(1) | 1005 | sys.exit(1) |
1012 | self._ReloadManifest(manifest_name, mp.manifest) | 1006 | self._ReloadManifest(manifest_name, mp.manifest) |
1013 | 1007 | ||
1014 | if opt.jobs is None: | ||
1015 | self.jobs = mp.manifest.default.sync_j | ||
1016 | |||
1017 | def ValidateOptions(self, opt, args): | 1008 | def ValidateOptions(self, opt, args): |
1018 | if opt.force_broken: | 1009 | if opt.force_broken: |
1019 | print('warning: -f/--force-broken is now the default behavior, and the ' | 1010 | print('warning: -f/--force-broken is now the default behavior, and the ' |
@@ -1036,12 +1027,6 @@ later is required to fix a server side protocol bug. | |||
1036 | opt.prune = True | 1027 | opt.prune = True |
1037 | 1028 | ||
1038 | def Execute(self, opt, args): | 1029 | def Execute(self, opt, args): |
1039 | if opt.jobs: | ||
1040 | self.jobs = opt.jobs | ||
1041 | if self.jobs > 1: | ||
1042 | soft_limit, _ = _rlimit_nofile() | ||
1043 | self.jobs = min(self.jobs, (soft_limit - 5) // 3) | ||
1044 | |||
1045 | manifest = self.outer_manifest | 1030 | manifest = self.outer_manifest |
1046 | if not opt.outer_manifest: | 1031 | if not opt.outer_manifest: |
1047 | manifest = self.manifest | 1032 | manifest = self.manifest |
@@ -1092,6 +1077,36 @@ later is required to fix a server side protocol bug. | |||
1092 | else: | 1077 | else: |
1093 | print('Skipping update of local manifest project.') | 1078 | print('Skipping update of local manifest project.') |
1094 | 1079 | ||
1080 | # Now that the manifests are up-to-date, setup the jobs value. | ||
1081 | if opt.jobs is None: | ||
1082 | # User has not made a choice, so use the manifest settings. | ||
1083 | opt.jobs = mp.default.sync_j | ||
1084 | if opt.jobs is not None: | ||
1085 | # Neither user nor manifest have made a choice. | ||
1086 | if opt.jobs_network is None: | ||
1087 | opt.jobs_network = opt.jobs | ||
1088 | if opt.jobs_checkout is None: | ||
1089 | opt.jobs_checkout = opt.jobs | ||
1090 | # Setup defaults if jobs==0. | ||
1091 | if not opt.jobs: | ||
1092 | if not opt.jobs_network: | ||
1093 | opt.jobs_network = 1 | ||
1094 | if not opt.jobs_checkout: | ||
1095 | opt.jobs_checkout = DEFAULT_LOCAL_JOBS | ||
1096 | opt.jobs = os.cpu_count() | ||
1097 | |||
1098 | # Try to stay under user rlimit settings. | ||
1099 | # | ||
1100 | # Since each worker requires at 3 file descriptors to run `git fetch`, use | ||
1101 | # that to scale down the number of jobs. Unfortunately there isn't an easy | ||
1102 | # way to determine this reliably as systems change, but it was last measured | ||
1103 | # by hand in 2011. | ||
1104 | soft_limit, _ = _rlimit_nofile() | ||
1105 | jobs_soft_limit = max(1, (soft_limit - 5) // 3) | ||
1106 | opt.jobs = min(opt.jobs, jobs_soft_limit) | ||
1107 | opt.jobs_network = min(opt.jobs_network, jobs_soft_limit) | ||
1108 | opt.jobs_checkout = min(opt.jobs_checkout, jobs_soft_limit) | ||
1109 | |||
1095 | superproject_logging_data = {} | 1110 | superproject_logging_data = {} |
1096 | self._UpdateProjectsRevisionId(opt, args, superproject_logging_data, | 1111 | self._UpdateProjectsRevisionId(opt, args, superproject_logging_data, |
1097 | manifest) | 1112 | manifest) |