Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

feat/cmd/gitserver: add memory tracking for both linux and macos#63114

Merged
ggilmore merged 1 commit intomainfrom
06-05-gitserver_add_memory_tracking_for_both_linux_and_macos
Jun 10, 2024
Merged

feat/cmd/gitserver: add memory tracking for both linux and macos#63114
ggilmore merged 1 commit intomainfrom
06-05-gitserver_add_memory_tracking_for_both_linux_and_macos

Conversation

@ggilmore
Copy link
Contributor

@ggilmore ggilmore commented Jun 5, 2024

Closes https://linear.app/sourcegraph/issue/SRC-369/finalize-memory-tracking-in-gitserver-on-linux

This PR adds a memory tracking feature to all gitserver command, using the utilities introduced in https://app.graphite.dev/github/pr/sourcegraph/sourcegraph/62803.

When the GITSERVER_MEMORY_OBSERVATION_ENABLED env var is set, an observer will be spawned that keeps track of the memory usage of the git invocation. This information is available in traces. Additionally, we'll print WARN logs if the commands uses more than 100 MB.

Test plan

Run sg start, and manually tweak the high memory usage threshold down from 500 MB to 1MB.

diff --git a/cmd/gitserver/internal/git/gitcli/command.go b/cmd/gitserver/internal/git/gitcli/command.go
index 393fa3c91e6..cf2630fc830 100644
--- a/cmd/gitserver/internal/git/gitcli/command.go
+++ b/cmd/gitserver/internal/git/gitcli/command.go
@@ -297,7 +297,7 @@ func (rc *cmdReader) waitCmd() error {
 	return rc.err
 }
 
-const highMemoryUsageThreshold = 500 * 1024 * 1024 // 500 MiB
+const highMemoryUsageThreshold = 1 * 1024 * 1024 // 500 MiB
 
 func (rc *cmdReader) trace() {
 	duration := time.Since(rc.cmdStart)

See log lines similar to the following when I run sg start (note the memory usage information in the log fields):

[    gitserver-1] WARN gitserver gitcli/command.go:363 High memory usage exec request {"TraceId": "5881f40e3bbbe4d26ec0f32b7f64f535", "SpanId": "a68818dc9f1f9ee2", "ev.Fields": {"cmd": "config", "cmd_ru_maxrss_kib": "5056", "cmd_ru_maxrss_human_readable": "5.2 MB", "traceID": "5881f40e3bbbe4d26ec0f32b7f64f535", "cmd_ru_inblock": "0", "args": "[git config --unset-all gc.auto]", "actor": "0", "cmd_duration_ms": "6", "user_time_ms": "2", "system_time_ms": "2", "repo": "github.com/sgtest/typescript-deps", "error": "git command [git config --unset-all gc.auto] failed with status code 5 (output: \"\")", "cmd_ru_majflt": "10", "cmd_ru_oublock": "0", "trace": "https://sourcegraph.test:3443/-/debug/jaeger/trace/5881f40e3bbbe4d26ec0f32b7f64f535", "exit_status": "5", "cmd_ru_minflt": "494"}}
[    gitserver-1] WARN gitserver gitcli/command.go:363 High memory usage exec request {"TraceId": "93cb7e9b3a42cfc085f570b8ad4a2ded", "SpanId": "c35ecddb6ef89e24", "ev.Fields": {"cmd_duration_ms": "6", "system_time_ms": "2", "cmd_ru_maxrss_kib": "5072", "cmd_ru_maxrss_human_readable": "5.2 MB", "cmd_ru_minflt": "495", "cmd_ru_majflt": "10", "actor": "0", "exit_status": "5", "user_time_ms": "2", "cmd_ru_oublock": "0", "traceID": "93cb7e9b3a42cfc085f570b8ad4a2ded", "trace": "https://sourcegraph.test:3443/-/debug/jaeger/trace/93cb7e9b3a42cfc085f570b8ad4a2ded", "repo": "github.com/sgtest/update-ids-test-base", "cmd": "config", "args": "[git config --unset-all gc.auto]", "error": "git command [git config --unset-all gc.auto] failed with status code 5 (output: \"\")", "cmd_ru_inblock": "0"}}
[    gitserver-1] WARN gitserver gitcli/command.go:363 High memory usage exec request {"TraceId": "346f1d04dc869f069b04bcabadec0665", "SpanId": "ec43228229e5f531", "ev.Fields": {"actor": "0", "error": "git command [git config --unset-all gc.auto] failed with status code 5 (output: \"\")", "cmd_ru_maxrss_kib": "4960", "trace": "https://sourcegraph.test:3443/-/debug/jaeger/trace/346f1d04dc869f069b04bcabadec0665", "args": "[git config --unset-all gc.auto]", "exit_status": "5", "cmd_duration_ms": "7", "system_time_ms": "2", "repo": "github.com/sgtest/utf8_test", "user_time_ms": "2", "cmd_ru_maxrss_human_readable": "5.1 MB", "cmd_ru_minflt": "487", "cmd_ru_inblock": "0", "cmd_ru_oublock": "0", "traceID": "346f1d04dc869f069b04bcabadec0665", "cmd": "config", "cmd_ru_majflt": "10"}}
[    gitserver-1] WARN gitserver gitcli/command.go:363 High memory usage exec request {"TraceId": "1b6a65835e3f75e7e83c8fe7355baeb2", "SpanId": "d525ac1f8c077184", "ev.Fields": {"cmd_ru_oublock": "0", "repo": "github.com/sourcegraph/about", "args": "[git config --unset-all gc.auto]", "cmd_duration_ms": "7", "system_time_ms": "2", "cmd_ru_inblock": "0", "exit_status": "5", "error": "git command [git config --unset-all gc.auto] failed with status code 5 (output: \"\")", "cmd_ru_maxrss_kib": "4912", "cmd_ru_maxrss_human_readable": "5.0 MB", "cmd_ru_minflt": "483", "cmd": "config", "user_time_ms": "2", "trace": "https://sourcegraph.test:3443/-/debug/jaeger/trace/1b6a65835e3f75e7e83c8fe7355baeb2", "actor": "0", "cmd_ru_majflt": "10", "traceID": "1b6a65835e3f75e7e83c8fe7355baeb2"}}
[    gitserver-1] WARN gitserver gitcli/command.go:363 High memory usage exec request {"TraceId": "39bbc0cc8b99292e6d3b6dfc067d4049", "SpanId": "60e4d69a25a3074b", "ev.Fields": {"args": "[git config --unset-all gc.auto]", "cmd_duration_ms": "7", "cmd_ru_maxrss_kib": "5056", "cmd_ru_minflt": "492", "trace": "https://sourcegraph.test:3443/-/debug/jaeger/trace/39bbc0cc8b99292e6d3b6dfc067d4049", "actor": "0", "system_time_ms": "2", "cmd_ru_inblock": "0", "cmd": "config", "exit_status": "5", "error": "git command [git config --unset-all gc.auto] failed with status code 5 (output: \"\")", "user_time_ms": "2", "cmd_ru_maxrss_human_readable": "5.2 MB", "cmd_ru_oublock": "0", "repo": "github.com/sourcegraph-testing/etcd", "cmd_ru_majflt": "10", "traceID": "39bbc0cc8b99292e6d3b6dfc067d4049"}}
[

Note that I have not tested this e2e in a linux system, but I think it's fine to test it on sourcegraph.com since:

  1. we have the benchmarks / integration tests from the previous PR
  2. it's behind a environment variable that is off by default

Changelog

Adds a new experimental feature to enable track of git command memory invocations when the GITSERVER_MEMORY_OBSERVATION_ENABLED environment variable is true (off by default).

Copy link
Contributor Author

ggilmore commented Jun 5, 2024

@github-actions github-actions bot added team/product-platform team/source Tickets under the purview of Source - the one Source to graph it all labels Jun 5, 2024
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from 5477d17 to 8c7c2c8 Compare June 6, 2024 00:07
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from d1e6438 to 54f15f5 Compare June 6, 2024 00:08
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from 8c7c2c8 to fa9f739 Compare June 7, 2024 08:14
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 54f15f5 to 6663fa4 Compare June 7, 2024 08:14
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from fa9f739 to f34c905 Compare June 7, 2024 08:20
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 6663fa4 to 8929898 Compare June 7, 2024 08:20
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from f34c905 to 7836694 Compare June 7, 2024 08:20
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 8929898 to 38163bc Compare June 7, 2024 08:20
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from 7836694 to 3e3654d Compare June 7, 2024 08:22
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 38163bc to 3656a7f Compare June 7, 2024 08:22
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from 36960b8 to c69f584 Compare June 7, 2024 16:56
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 3656a7f to 5ce6eba Compare June 7, 2024 16:56
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch 2 times, most recently from fd31fb9 to f7113c0 Compare June 7, 2024 20:17
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 5ce6eba to 6c85d79 Compare June 7, 2024 20:17
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from f7113c0 to c5f3b77 Compare June 7, 2024 22:18
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 6c85d79 to 2fcddfb Compare June 7, 2024 22:18
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from c5f3b77 to 182220b Compare June 8, 2024 01:42
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 2fcddfb to 0721a1d Compare June 8, 2024 01:42
@ggilmore ggilmore marked this pull request as ready for review June 8, 2024 01:52
Copy link
Contributor Author

ggilmore commented Jun 8, 2024

Unforunately, I couldn't see the grafana dashboards for this feature locally since sg start monitoring appears to be broken for me after two hours of debugging. (Something about crane trying to bind to 127.0.0.1:0) 🫠

@ggilmore ggilmore requested a review from a team June 8, 2024 01:53
Copy link
Member

@eseliger eseliger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's take it for a spin and see how it performs!

@graphite-app
Copy link

graphite-app bot commented Jun 10, 2024

SpongeBob gif. SpongeBob pretends to crank his fist like a jack-in-the-box, and his thumb rises and pops out for a thumbs up. He then gestures to his thumb like 'eh? What do you think?' (Added via Giphy)

@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from 182220b to 5f49f48 Compare June 10, 2024 18:59
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 0721a1d to 2d753e5 Compare June 10, 2024 19:00
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from 5f49f48 to da9e0db Compare June 10, 2024 19:29
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 2d753e5 to 1b08fce Compare June 10, 2024 19:29
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from da9e0db to 1aea5aa Compare June 10, 2024 19:34
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch 2 times, most recently from aaad947 to 4e3d913 Compare June 10, 2024 20:00
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from 1aea5aa to 456f90e Compare June 10, 2024 20:09
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 4e3d913 to 0ae625b Compare June 10, 2024 20:09
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from 456f90e to a223c9a Compare June 10, 2024 20:13
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch 3 times, most recently from 6f26a2d to 4e75cd4 Compare June 10, 2024 20:15
@ggilmore ggilmore force-pushed the 05-20-wip_keep_expriementing_with_linux_memory_observations branch from a223c9a to 9dd391b Compare June 10, 2024 20:54
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 4e75cd4 to 9fad661 Compare June 10, 2024 20:54
@ggilmore ggilmore changed the title gitserver: add memory tracking for both linux and macos feat/cmd/gitserver: add memory tracking for both linux and macos Jun 10, 2024
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 9fad661 to 4d5defb Compare June 10, 2024 21:10
Base automatically changed from 05-20-wip_keep_expriementing_with_linux_memory_observations to main June 10, 2024 21:20
@ggilmore ggilmore force-pushed the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch from 4d5defb to b7706e7 Compare June 10, 2024 21:21
Copy link
Contributor Author

ggilmore commented Jun 10, 2024

Merge activity

  • Jun 10, 5:21 PM EDT: Graphite rebased this pull request as part of a merge.
  • Jun 10, 5:26 PM EDT: @ggilmore merged this pull request with Graphite.

@ggilmore ggilmore merged commit 2c7d217 into main Jun 10, 2024
@ggilmore ggilmore deleted the 06-05-gitserver_add_memory_tracking_for_both_linux_and_macos branch June 10, 2024 21:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/product-platform team/source Tickets under the purview of Source - the one Source to graph it all

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants