From b2d62949e1855d4b72a39818fc09250365f230dd Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 29 Mar 2022 07:59:55 +0200 Subject: git: Globally limit threads used by git-pack-objects(1) By default, git-pack-objects(1) will spawn as many threads as there are logical CPU cores on the machine. While this typically makes sense on a client's machine because a client will want the command to finish as fast as possible, on the server-side this is less of a good idea because it can easily impact other, concurrently running Git commands. This is why we have started to limit the number of threads this command may use when performing repository maintenance. Packing of objects is in no way limited to maintenance though, but it's also executed e.g. when serving packfiles. Let's globally limit the number of threads git-pack-objects(1) uses by injecting the `pack.threads` configuration into all commands which may generate packfiles. Changelog: performance --- internal/gitaly/service/repository/repack.go | 10 ---------- internal/gitaly/service/repository/repack_test.go | 22 ---------------------- 2 files changed, 32 deletions(-) (limited to 'internal/gitaly/service') diff --git a/internal/gitaly/service/repository/repack.go b/internal/gitaly/service/repository/repack.go index 18415d4ba..6ba97185d 100644 --- a/internal/gitaly/service/repository/repack.go +++ b/internal/gitaly/service/repository/repack.go @@ -3,11 +3,9 @@ package repository import ( "context" "fmt" - "math" "github.com/prometheus/client_golang/prometheus" gitalyerrors "gitlab.com/gitlab-org/gitaly/v14/internal/errors" - "gitlab.com/gitlab-org/gitaly/v14/internal/git" "gitlab.com/gitlab-org/gitaly/v14/internal/git/housekeeping" "gitlab.com/gitlab-org/gitaly/v14/internal/helper" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" @@ -25,14 +23,6 @@ func init() { prometheus.MustRegister(repackCounter) } -// log2Threads returns the log-2 number of threads based on the number of -// provided CPUs. This prevents repacking operations from exhausting all -// available CPUs and increasing request latency -func log2Threads(numCPUs int) git.ValueFlag { - n := math.Max(1, math.Floor(math.Log2(float64(numCPUs)))) - return git.ValueFlag{Name: "--threads", Value: fmt.Sprint(n)} -} - func (s *server) RepackFull(ctx context.Context, in *gitalypb.RepackFullRequest) (*gitalypb.RepackFullResponse, error) { if in.GetRepository() == nil { return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository) diff --git a/internal/gitaly/service/repository/repack_test.go b/internal/gitaly/service/repository/repack_test.go index 7e73290a6..d7efb78dc 100644 --- a/internal/gitaly/service/repository/repack_test.go +++ b/internal/gitaly/service/repository/repack_test.go @@ -300,25 +300,3 @@ func TestRepackFullDeltaIslands(t *testing.T) { return err }) } - -func TestLog2Threads(t *testing.T) { - t.Parallel() - for _, tt := range []struct { - cpus int - threads string - }{ - {1, "1"}, - {2, "1"}, - {3, "1"}, - {4, "2"}, - {8, "3"}, - {9, "3"}, - {13, "3"}, - {16, "4"}, - {27, "4"}, - {32, "5"}, - } { - actualThreads := log2Threads(tt.cpus) - require.Equal(t, tt.threads, actualThreads.Value) - } -} -- cgit v1.2.3