From 026a0ac1e4e49f09d7349c282c719508cbac34c6 Mon Sep 17 00:00:00 2001 From: James Liu Date: Thu, 17 Oct 2024 16:20:25 +1100 Subject: [PATCH] git: Allow core.packedGitLimit to be configured core.packedGitLimit [1] allows us to control the maximum size of packfile data that Git slurps into memory. Tweaking this value was proposed in https://gitlab.com/gitlab-org/charts/gitlab/-/issues/5795 may alleviate some git-clone(1) performance issues we've seen in large repositories. Expose an undocumented environment variable which enables us to set arbitrary values for core.packedGitLimit. This knob will be twisted by us, and eventually this option will either go away (because we've found a good way to configure it automatically), or be documented properly as a support-only/experimental option. [1] https://git-scm.com/docs/git-config#Documentation/git-config.txt-corepackedGitLimit --- internal/git/gitcmd/command_description.go | 11 ++++- .../git/gitcmd/command_description_test.go | 41 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/internal/git/gitcmd/command_description.go b/internal/git/gitcmd/command_description.go index e3384e98c4..1473d4deff 100644 --- a/internal/git/gitcmd/command_description.go +++ b/internal/git/gitcmd/command_description.go @@ -8,6 +8,7 @@ import ( "strings" "gitlab.com/gitlab-org/gitaly/v16/internal/git" + "gitlab.com/gitlab-org/gitaly/v16/internal/helper/env" "gitlab.com/gitlab-org/gitaly/v16/internal/structerr" ) @@ -529,11 +530,19 @@ func templateFsckConfiguration(_ context.Context, prefix string) []GlobalOption } func packConfiguration(context.Context) []GlobalOption { - return []GlobalOption{ + opts := []GlobalOption{ ConfigPair{Key: "pack.windowMemory", Value: "100m"}, ConfigPair{Key: "pack.writeReverseIndex", Value: "true"}, ConfigPair{Key: "pack.threads", Value: threadsConfigValue(runtime.NumCPU())}, } + + // Experimental configuration for https://gitlab.com/gitlab-org/charts/gitlab/-/issues/5795 + // To documented properly at a later stage. + if packedGitLimit := env.GetString("GITALY_PACKED_GIT_LIMIT", ""); packedGitLimit != "" { + opts = append(opts, ConfigPair{Key: "core.packedGitLimit", Value: packedGitLimit}) + } + + return opts } // threadsConfigValue returns the log-2 number of threads based on the number of provided CPUs. This diff --git a/internal/git/gitcmd/command_description_test.go b/internal/git/gitcmd/command_description_test.go index 686701eda4..fe303f9fe4 100644 --- a/internal/git/gitcmd/command_description_test.go +++ b/internal/git/gitcmd/command_description_test.go @@ -2,6 +2,7 @@ package gitcmd import ( "fmt" + "runtime" "testing" "github.com/stretchr/testify/require" @@ -148,3 +149,43 @@ func TestFsckConfiguration_prefix(t *testing.T) { }) } } + +func TestPackConfiguration(t *testing.T) { + ctx := testhelper.Context(t) + + for _, tc := range []struct { + name string + env map[string]string + expected []ConfigPair + }{ + { + name: "with GITALY_PACKED_GIT_LIMIT", + env: map[string]string{ + "GITALY_PACKED_GIT_LIMIT": "1g", + }, + expected: []ConfigPair{ + {Key: "pack.windowMemory", Value: "100m"}, + {Key: "pack.writeReverseIndex", Value: "true"}, + {Key: "pack.threads", Value: threadsConfigValue(runtime.NumCPU())}, + {Key: "core.packedGitLimit", Value: "1g"}, + }, + }, + { + name: "without GITALY_PACKED_GIT_LIMIT", + expected: []ConfigPair{ + {Key: "pack.windowMemory", Value: "100m"}, + {Key: "pack.writeReverseIndex", Value: "true"}, + {Key: "pack.threads", Value: threadsConfigValue(runtime.NumCPU())}, + }, + }, + } { + t.Run(tc.name, func(t *testing.T) { + for k, v := range tc.env { + t.Setenv(k, v) + } + + opts := packConfiguration(ctx) + require.ElementsMatch(t, tc.expected, opts) + }) + } +} -- GitLab