diff options
author | Kuang-che Wu <kcwu@google.com> | 2024-10-22 21:04:41 +0800 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-10-23 23:34:34 +0000 |
commit | 8da4861b3860c505e39341b4135c21f67569e4d8 (patch) | |
tree | 6f300266c91322df0e61953b84381e1f403074a5 /subcmds/upload.py | |
parent | 39ffd9977e2f6cb1ca1757e59173fc93e0eab72c (diff) | |
download | git-repo-8da4861b3860c505e39341b4135c21f67569e4d8.tar.gz |
subcmds: reduce multiprocessing serialization overhead
Follow the same approach as 39ffd9977e to reduce serialization overhead.
Below benchmarks are tested with 2.7k projects on my workstation
(warm cache). git tracing is disabled for benchmark.
(seconds) | v2.48 | v2.48 | this CL | this CL
| | -j32 | | -j32
-----------------------------------------------------------
with clean tree state:
branches (none) | 5.6 | 5.9 | 1.0 | 0.9
status (clean) | 21.3 | 9.4 | 19.4 | 4.7
diff (none) | 7.6 | 7.2 | 5.7 | 2.2
prune (none) | 5.7 | 6.1 | 1.3 | 1.2
abandon (none) | 19.4 | 18.6 | 0.9 | 0.8
upload (none) | 19.7 | 18.7 | 0.9 | 0.8
forall -c true | 7.5 | 7.6 | 0.6 | 0.6
forall -c "git log -1" | 11.3 | 11.1 | 0.6 | 0.6
with branches:
start BRANCH --all | 21.9 | 20.3 | 13.6 | 2.6
checkout BRANCH | 29.1 | 27.8 | 1.1 | 1.0
branches (2) | 28.0 | 28.6 | 1.5 | 1.3
abandon BRANCH | 29.2 | 27.5 | 9.7 | 2.2
Bug: b/371638995
Change-Id: I53989a3d1e43063587b3f52f852b1c2c56b49412
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/440221
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Tested-by: Kuang-che Wu <kcwu@google.com>
Commit-Queue: Kuang-che Wu <kcwu@google.com>
Diffstat (limited to 'subcmds/upload.py')
-rw-r--r-- | subcmds/upload.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/subcmds/upload.py b/subcmds/upload.py index 8039a1cd..6344ee31 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
@@ -713,16 +713,17 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
713 | merge_branch = p.stdout.strip() | 713 | merge_branch = p.stdout.strip() |
714 | return merge_branch | 714 | return merge_branch |
715 | 715 | ||
716 | @staticmethod | 716 | @classmethod |
717 | def _GatherOne(opt, project): | 717 | def _GatherOne(cls, opt, project_idx): |
718 | """Figure out the upload status for |project|.""" | 718 | """Figure out the upload status for |project|.""" |
719 | project = cls.get_parallel_context()["projects"][project_idx] | ||
719 | if opt.current_branch: | 720 | if opt.current_branch: |
720 | cbr = project.CurrentBranch | 721 | cbr = project.CurrentBranch |
721 | up_branch = project.GetUploadableBranch(cbr) | 722 | up_branch = project.GetUploadableBranch(cbr) |
722 | avail = [up_branch] if up_branch else None | 723 | avail = [up_branch] if up_branch else None |
723 | else: | 724 | else: |
724 | avail = project.GetUploadableBranches(opt.branch) | 725 | avail = project.GetUploadableBranches(opt.branch) |
725 | return (project, avail) | 726 | return (project_idx, avail) |
726 | 727 | ||
727 | def Execute(self, opt, args): | 728 | def Execute(self, opt, args): |
728 | projects = self.GetProjects( | 729 | projects = self.GetProjects( |
@@ -732,8 +733,9 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
732 | def _ProcessResults(_pool, _out, results): | 733 | def _ProcessResults(_pool, _out, results): |
733 | pending = [] | 734 | pending = [] |
734 | for result in results: | 735 | for result in results: |
735 | project, avail = result | 736 | project_idx, avail = result |
736 | if avail is None: | 737 | if avail is None: |
738 | project = projects[project_idx] | ||
737 | logger.error( | 739 | logger.error( |
738 | 'repo: error: %s: Unable to upload branch "%s". ' | 740 | 'repo: error: %s: Unable to upload branch "%s". ' |
739 | "You might be able to fix the branch by running:\n" | 741 | "You might be able to fix the branch by running:\n" |
@@ -746,12 +748,14 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
746 | pending.append(result) | 748 | pending.append(result) |
747 | return pending | 749 | return pending |
748 | 750 | ||
749 | pending = self.ExecuteInParallel( | 751 | with self.ParallelContext(): |
750 | opt.jobs, | 752 | self.get_parallel_context()["projects"] = projects |
751 | functools.partial(self._GatherOne, opt), | 753 | pending = self.ExecuteInParallel( |
752 | projects, | 754 | opt.jobs, |
753 | callback=_ProcessResults, | 755 | functools.partial(self._GatherOne, opt), |
754 | ) | 756 | range(len(projects)), |
757 | callback=_ProcessResults, | ||
758 | ) | ||
755 | 759 | ||
756 | if not pending: | 760 | if not pending: |
757 | if opt.branch is None: | 761 | if opt.branch is None: |