Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ingester: reduce activity tracker memory allocation #3203

Merged
merged 7 commits into from
Oct 17, 2022

Conversation

ortuman
Copy link
Contributor

@ortuman ortuman commented Oct 13, 2022

Signed-off-by: Miguel Ángel Ortuño ortuman@gmail.com

What this PR does

Added custom stringer for *client.QueryRequest to minimize memory allocation on ingester activity tracker record generator.

old:

BenchmarkRequestActivity-8   	 1284216	       927.5 ns/op	     984 B/op	      21 allocs/op
BenchmarkRequestActivity-8   	 1291141	       928.1 ns/op	     984 B/op	      21 allocs/op
BenchmarkRequestActivity-8   	 1289739	       928.9 ns/op	     984 B/op	      21 allocs/op
BenchmarkRequestActivity-8   	 1287590	       927.4 ns/op	     984 B/op	      21 allocs/op
BenchmarkRequestActivity-8   	 1287128	       934.3 ns/op	     984 B/op	      21 allocs/op
BenchmarkRequestActivity-8   	 1294728	       931.9 ns/op	     984 B/op	      21 allocs/op
BenchmarkRequestActivity-8   	 1291026	       928.1 ns/op	     984 B/op	      21 allocs/op
BenchmarkRequestActivity-8   	 1289536	       931.1 ns/op	     984 B/op	      21 allocs/op
BenchmarkRequestActivity-8   	 1289566	       933.2 ns/op	     984 B/op	      21 allocs/op
BenchmarkRequestActivity-8   	 1289500	       929.1 ns/op	     984 B/op	      21 allocs/op

new:

BenchmarkRequestActivity-8   	 3293625	       355.1 ns/op	     224 B/op	       1 allocs/op
BenchmarkRequestActivity-8   	 3372951	       356.3 ns/op	     224 B/op	       1 allocs/op
BenchmarkRequestActivity-8   	 3375446	       355.1 ns/op	     224 B/op	       1 allocs/op
BenchmarkRequestActivity-8   	 3357924	       356.0 ns/op	     224 B/op	       1 allocs/op
BenchmarkRequestActivity-8   	 3372872	       355.6 ns/op	     224 B/op	       1 allocs/op
BenchmarkRequestActivity-8   	 3371698	       355.7 ns/op	     224 B/op	       1 allocs/op
BenchmarkRequestActivity-8   	 3369746	       355.9 ns/op	     224 B/op	       1 allocs/op
BenchmarkRequestActivity-8   	 3374049	       355.5 ns/op	     224 B/op	       1 allocs/op
BenchmarkRequestActivity-8   	 3373887	       356.5 ns/op	     224 B/op	       1 allocs/op
BenchmarkRequestActivity-8   	 3376087	       355.4 ns/op	     224 B/op	       1 allocs/op

comparison:

name               old time/op    new time/op    delta
RequestActivity-8     930ns ± 0%     356ns ± 0%  -61.75%  (p=0.000 n=10+10)

name               old alloc/op   new alloc/op   delta
RequestActivity-8      984B ± 0%      224B ± 0%  -77.24%  (p=0.000 n=10+10)

name               old allocs/op  new allocs/op  delta
RequestActivity-8      21.0 ± 0%       1.0 ± 0%  -95.24%  (p=0.000 n=10+10)

Which issue(s) this PR fixes or relates to

Fixes #3192

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: Miguel Ángel Ortuño <ortuman@gmail.com>
Signed-off-by: Miguel Ángel Ortuño <ortuman@gmail.com>
@ortuman ortuman force-pushed the ortuman/query-req-activity-custom-stringer branch from a5c4137 to 8f13533 Compare October 13, 2022 10:24
@ortuman ortuman marked this pull request as ready for review October 13, 2022 10:25
@ortuman ortuman requested a review from a team as a code owner October 13, 2022 10:25
Copy link
Member

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Looking at the benchmark, and original issue #3192, I am not sure we're spending time well by optimizing this. It's a lot of extra code (although easy to follow) for tiny benefit in my opinion.

pkg/ingester/ingester_activity.go Show resolved Hide resolved
pkg/ingester/ingester_activity.go Outdated Show resolved Hide resolved
pkg/ingester/ingester_activity.go Outdated Show resolved Hide resolved
Signed-off-by: Miguel Ángel Ortuño <ortuman@gmail.com>
Signed-off-by: Miguel Ángel Ortuño <ortuman@gmail.com>
pkg/ingester/ingester_activity.go Outdated Show resolved Hide resolved
pkg/ingester/ingester_activity.go Show resolved Hide resolved
pkg/ingester/ingester_activity.go Outdated Show resolved Hide resolved
pkg/ingester/ingester_activity.go Outdated Show resolved Hide resolved
ortuman and others added 3 commits October 13, 2022 17:28
Co-authored-by: Peter Štibraný <pstibrany@gmail.com>
Co-authored-by: Peter Štibraný <pstibrany@gmail.com>
Signed-off-by: Miguel Ángel Ortuño <ortuman@gmail.com>
@pstibrany pstibrany merged commit d524dfc into main Oct 17, 2022
@pstibrany pstibrany deleted the ortuman/query-req-activity-custom-stringer branch October 17, 2022 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ingester: reduce activity tracker memory allocation
2 participants