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

Implementing Snappy Block Encoding #5215

Merged
merged 8 commits into from
Mar 22, 2023

Conversation

alanprot
Copy link
Member

@alanprot alanprot commented Mar 18, 2023

What this PR does:

This PR is a follow up of #5213 (comment)

This PR is implementing block format snappy encoding:

Benchmark Results:

pkg: github.com/cortexproject/cortex/pkg/util/grpcencoding
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkCompress/snappy-12         	  452925	      2339 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/snappy-12         	  545708	      2264 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/snappy-12         	  534312	      2230 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/snappy-12         	  538390	      2293 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/snappy-12         	  540451	      2201 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/snappy-block-12   	  536930	      2233 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/snappy-block-12   	  525919	      2306 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/snappy-block-12   	  476133	      2271 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/snappy-block-12   	  518916	      2203 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/snappy-block-12   	  543210	      2187 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/zstd-12           	  518970	      2202 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/zstd-12           	  528393	      2227 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/zstd-12           	  519684	      2455 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/zstd-12           	  507280	      2268 ns/op	      16 B/op	       1 allocs/op
BenchmarkCompress/zstd-12           	  526838	      2234 ns/op	      16 B/op	       1 allocs/op
BenchmarkDecompress/snappy-12       	  115866	     10098 ns/op	   34212 B/op	      12 allocs/op
BenchmarkDecompress/snappy-12       	  117933	     10162 ns/op	   34254 B/op	      12 allocs/op
BenchmarkDecompress/snappy-12       	  107898	     10284 ns/op	   34238 B/op	      12 allocs/op
BenchmarkDecompress/snappy-12       	  116962	     10009 ns/op	   34262 B/op	      12 allocs/op
BenchmarkDecompress/snappy-12       	  115161	     10359 ns/op	   34237 B/op	      12 allocs/op
BenchmarkDecompress/snappy-block-12 	  192163	      6091 ns/op	    9858 B/op	       4 allocs/op
BenchmarkDecompress/snappy-block-12 	  192910	      6224 ns/op	    9859 B/op	       4 allocs/op
BenchmarkDecompress/snappy-block-12 	  191830	      6087 ns/op	    9857 B/op	       4 allocs/op
BenchmarkDecompress/snappy-block-12 	  193527	      6156 ns/op	    9859 B/op	       4 allocs/op
BenchmarkDecompress/snappy-block-12 	  191727	      6156 ns/op	    9858 B/op	       4 allocs/op
BenchmarkDecompress/zstd-12         	  112138	      9586 ns/op	   43905 B/op	      14 allocs/op
BenchmarkDecompress/zstd-12         	  119416	      9455 ns/op	   43903 B/op	      14 allocs/op
BenchmarkDecompress/zstd-12         	  121332	      9560 ns/op	   43903 B/op	      14 allocs/op
BenchmarkDecompress/zstd-12         	  118489	      9505 ns/op	   43903 B/op	      14 allocs/op
BenchmarkDecompress/zstd-12         	  117463	      9563 ns/op	   43902 B/op	      14 allocs/op
PASS
ok  	github.com/cortexproject/cortex/pkg/util/grpcencoding	36.997s

Comparing Snappy x snappy-block (Decompress)

name                  old time/op    new time/op    delta
Decompress/snappy-12    10.2µs ± 2%     6.1µs ± 1%  -39.67%  (p=0.008 n=5+5)

name                  old alloc/op   new alloc/op   delta
Decompress/snappy-12    34.2kB ± 0%     9.9kB ± 0%  -71.21%  (p=0.008 n=5+5)

name                  old allocs/op  new allocs/op  delta
Decompress/snappy-12      12.0 ± 0%       4.0 ± 0%  -66.67%  (p=0.008 n=5+5)

Which issue(s) this PR fixes:
Fixes #

Checklist

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

@alanprot alanprot force-pushed the snappy-block branch 2 times, most recently from 5007e4b to c1e4045 Compare March 18, 2023 01:02
@alanprot
Copy link
Member Author

@damnever Do you wanna test this change?

@damnever
Copy link
Contributor

@alanprot Great! I may test this patch next week.

@alanprot alanprot force-pushed the snappy-block branch 2 times, most recently from 79c0f24 to c1bc632 Compare March 18, 2023 02:26
@alanprot
Copy link
Member Author

alanprot commented Mar 18, 2023

The results seems pretty good. I dont see any change on the CPU and the network is 10X less.

Screen Shot 2023-03-17 at 8 32 27 PM
Screen Shot 2023-03-20 at 9 12 25 AM

The first deployment of distributors used more CPU because we were changing the len of the dst array to 0, forcing a new array to be allocated on every operation. This was fixed by c1bc632

@alanprot
Copy link
Member Author

alanprot commented Mar 21, 2023

@damnever i addressed your comments...

Did you have the chance to test?

@alanprot alanprot marked this pull request as ready for review March 21, 2023 17:10
@damnever
Copy link
Contributor

damnever commented Mar 22, 2023

@alanprot The result is very good, here is the comparison of the ingesters' CPU usage in our test environment. (snappy/v1.14 vs snappy/#5213 vs snappy-block):
image

@alanprot
Copy link
Member Author

Nice!! So if i'm reading correcly we have:

snappy/v1.14: 22.5% CPU
snappy/#5213 : 17.9% CPU
snappy-block: 14.6% CPU

Seems that make sense to go ahead with this PR?

@yeya24 WDYT?

Maybe snappy-block is not a good name haha :P

@damnever
Copy link
Contributor

@alanprot You are right, but not in percentage rather CPU usage in seconds.

@alanprot
Copy link
Member Author

Oh i see..

So it reduced the CPU usage in seconds by 45% (22.5*0.65=~14.6)? Nice!
We saw improvements on our test environments as well but not that big. This is good news!

@yeya24
Copy link
Collaborator

yeya24 commented Mar 22, 2023

Nice! This is great improvement.
@alanprot About naming, I don't have strong preference. snappy-block also sounds good to me.

Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
@alanprot alanprot changed the title WIP: Implementing Snappy Block Encoding Implementing Snappy Block Encoding Mar 22, 2023
@alanprot alanprot enabled auto-merge (squash) March 22, 2023 16:52
@alanprot alanprot merged commit f23d591 into cortexproject:master Mar 22, 2023
@alanprot alanprot deleted the snappy-block branch March 22, 2023 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants