forked from thanos-io/thanos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v2] store: reuse buffers for serializing Series() responses (thanos-…
…io#4535) * store: reuse buffers for serializing Series() responses Compared with v1: * Uses less CPU because Size() is called only once just as before; * Uses `protoc-go-inject-field` to inject extra fields into SeriesResponse which are used for marshaling the responses; * Uses []byte instead of bytes.Buffer because bytes.Buffer allocates 2x amount of memory and in our cases the responses are more or less of the same size so less memory is wasted; I think this version is more maintainable since the details of the allocation are hidden from the Series() function itself, it all happens in the Marshal() function. Benchmarks: ``` name old time/op new time/op delta BucketSeries/1000000SeriesWith1Samples/1of1000000-16 97.8ms ± 6% 89.4ms ± 8% -8.63% (p=0.000 n=49+45) BucketSeries/1000000SeriesWith1Samples/10of1000000-16 92.7ms ±12% 88.6ms ± 7% -4.42% (p=0.000 n=48+47) BucketSeries/1000000SeriesWith1Samples/1000000of1000000-16 1.14s ± 4% 1.11s ± 3% -2.89% (p=0.000 n=50+49) BucketSeries/100000SeriesWith100Samples/1of10000000-16 6.58ms ± 2% 6.70ms ± 9% ~ (p=0.125 n=46+50) BucketSeries/100000SeriesWith100Samples/100of10000000-16 6.73ms ± 5% 6.82ms ± 9% ~ (p=0.575 n=49+50) BucketSeries/100000SeriesWith100Samples/10000000of10000000-16 123ms ± 5% 119ms ± 7% -2.92% (p=0.000 n=48+50) BucketSeries/1SeriesWith10000000Samples/1of10000000-16 131µs ± 6% 129µs ± 6% -0.85% (p=0.027 n=47+47) BucketSeries/1SeriesWith10000000Samples/100of10000000-16 129µs ± 2% 129µs ± 8% ~ (p=0.358 n=44+49) BucketSeries/1SeriesWith10000000Samples/10000000of10000000-16 38.6ms ± 9% 34.7ms ±10% -10.11% (p=0.000 n=49+50) name old alloc/op new alloc/op delta BucketSeries/1000000SeriesWith1Samples/1of1000000-16 62.0MB ± 0% 62.0MB ± 0% ~ (p=0.529 n=47+50) BucketSeries/1000000SeriesWith1Samples/10of1000000-16 62.1MB ± 0% 62.1MB ± 0% ~ (p=0.334 n=49+50) BucketSeries/1000000SeriesWith1Samples/1000000of1000000-16 1.37GB ± 0% 1.27GB ± 0% -7.03% (p=0.000 n=49+50) BucketSeries/100000SeriesWith100Samples/1of10000000-16 4.85MB ± 0% 4.85MB ± 0% ~ (p=0.365 n=50+50) BucketSeries/100000SeriesWith100Samples/100of10000000-16 4.86MB ± 0% 4.86MB ± 0% ~ (p=0.579 n=50+50) BucketSeries/100000SeriesWith100Samples/10000000of10000000-16 157MB ± 4% 130MB ± 5% -16.99% (p=0.000 n=50+50) BucketSeries/1SeriesWith10000000Samples/1of10000000-16 213kB ± 0% 213kB ± 0% +0.14% (p=0.000 n=50+48) BucketSeries/1SeriesWith10000000Samples/100of10000000-16 213kB ± 0% 213kB ± 0% +0.14% (p=0.000 n=50+50) BucketSeries/1SeriesWith10000000Samples/10000000of10000000-16 115MB ± 0% 62MB ± 8% -45.98% (p=0.000 n=49+50) name old allocs/op new allocs/op delta BucketSeries/1000000SeriesWith1Samples/1of1000000-16 9.69k ± 0% 9.70k ± 1% ~ (p=0.143 n=49+50) BucketSeries/1000000SeriesWith1Samples/10of1000000-16 9.79k ± 0% 9.79k ± 0% ~ (p=0.845 n=49+49) BucketSeries/1000000SeriesWith1Samples/1000000of1000000-16 11.0M ± 0% 10.0M ± 0% -9.06% (p=0.000 n=49+50) BucketSeries/100000SeriesWith100Samples/1of10000000-16 1.10k ± 0% 1.10k ± 0% +0.27% (p=0.000 n=50+50) BucketSeries/100000SeriesWith100Samples/100of10000000-16 1.14k ± 0% 1.14k ± 0% ~ (p=0.622 n=50+50) BucketSeries/100000SeriesWith100Samples/10000000of10000000-16 1.10M ± 0% 1.00M ± 0% -9.04% (p=0.000 n=49+50) BucketSeries/1SeriesWith10000000Samples/1of10000000-16 200 ± 0% 202 ± 0% +1.00% (p=0.000 n=48+50) BucketSeries/1SeriesWith10000000Samples/100of10000000-16 200 ± 0% 202 ± 0% +1.00% (p=0.000 n=49+50) BucketSeries/1SeriesWith10000000Samples/10000000of10000000-16 167k ± 0% 167k ± 0% +0.00% (p=0.000 n=50+50) ``` CPU usage is +/- the same when you take the variance into account, the allocated memory is the real difference and, as expected, the benchmarks show the most improvement on the cases with lots of callers. Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * *: linter fixes Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * Makefile: run formatter after proto Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * store: use old behaviour when nil has been passed Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * store: clean up custom.go Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * store: add different constructors for responses with sync.Pool Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * store: "hide" *[]byte in the SeriesResponse Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * CHANGELOG: update Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
- Loading branch information
Showing
14 changed files
with
309 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT | ||
|
||
go 1.16 | ||
|
||
require github.com/favadi/protoc-go-inject-field v0.0.0-20170110051745-00204be12496 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.