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

pkg/chunkenc: Fix BenchmarkRead to focus on reading chunks, not converting bytes to string #1423

Merged
merged 1 commit into from
Dec 19, 2019
Merged

Conversation

pstibrany
Copy link
Member

Previously BenchmarkRead asked for every single line from chunks to be returned. This causes a lot of unnnecessary allocations (due to string([]byte) conversion), which dominate the benchmark. Instead of counting bytes when reading, we now count size when generating data for logging speed.

Another test was added to show that these two approaches are comparable.

This change makes BenchmarkRead to report real time needed to decode chunks:

name           old time/op    new time/op    delta
Read/none-4      86.2ms ± 0%    33.2ms ± 0%   ~     (p=1.000 n=1+1)
Read/gzip-4       255ms ± 0%     194ms ± 0%   ~     (p=1.000 n=1+1)
Read/lz4-4        121ms ± 0%      64ms ± 0%   ~     (p=1.000 n=1+1)
Read/snappy-4     119ms ± 0%      67ms ± 0%   ~     (p=1.000 n=1+1)

name           old alloc/op   new alloc/op   delta
Read/none-4       134MB ± 0%       0MB ± 0%   ~     (p=1.000 n=1+1)
Read/gzip-4       135MB ± 0%       0MB ± 0%   ~     (p=1.000 n=1+1)
Read/lz4-4        136MB ± 0%       1MB ± 0%   ~     (p=1.000 n=1+1)
Read/snappy-4     135MB ± 0%       0MB ± 0%   ~     (p=1.000 n=1+1)

name           old allocs/op  new allocs/op  delta
Read/none-4        491k ± 0%        3k ± 0%   ~     (p=1.000 n=1+1)
Read/gzip-4        491k ± 0%        3k ± 0%   ~     (p=1.000 n=1+1)
Read/lz4-4         491k ± 0%        3k ± 0%   ~     (p=1.000 n=1+1)
Read/snappy-4      491k ± 0%        3k ± 0%   ~     (p=1.000 n=1+1)

Decompression speed is now also more correct (esp. None is much higher than LZ4/Snappy)

	Before (/s)		Now (/s)
None	1.1 GB (n=1)		4.0 GB (n=1)
None	1.5 GB (n=9)		3.8 GB (n=38)
None	1.6 GB (n=13)
Gzip	516 MB (n=1)		640 MB (n=1)
Gzip	509 MB (n=3)		664 MB (n=4)
Gzip	514 MB (n=4)		649 MB (n=6)
LZ4	1.1 GB (n=1)		1.7 GB (n=1)
LZ4	1.1 GB (n=9)		1.9 GB (n=15)
Snappy	1.1 GB (n=1)		2.0 GB (n=1)
Snappy	1.1 GB (n=9)		1.8 GB (n=16)

Previously BenchmarkRead asked for every single line from chunks to be returned.
This causes a lot of unnnecessary allocations, which dominate the benchmark.
Instead of counting bytes when reading, we now count size when generating data
for logging speed.

Another test was added to show that these two approaches are comparable.

This change makes BenchmarkRead to report real time needed to decode chunks:

name           old time/op    new time/op    delta
Read/none-4      86.2ms ± 0%    33.2ms ± 0%   ~     (p=1.000 n=1+1)
Read/gzip-4       255ms ± 0%     194ms ± 0%   ~     (p=1.000 n=1+1)
Read/lz4-4        121ms ± 0%      64ms ± 0%   ~     (p=1.000 n=1+1)
Read/snappy-4     119ms ± 0%      67ms ± 0%   ~     (p=1.000 n=1+1)

name           old alloc/op   new alloc/op   delta
Read/none-4       134MB ± 0%       0MB ± 0%   ~     (p=1.000 n=1+1)
Read/gzip-4       135MB ± 0%       0MB ± 0%   ~     (p=1.000 n=1+1)
Read/lz4-4        136MB ± 0%       1MB ± 0%   ~     (p=1.000 n=1+1)
Read/snappy-4     135MB ± 0%       0MB ± 0%   ~     (p=1.000 n=1+1)

name           old allocs/op  new allocs/op  delta
Read/none-4        491k ± 0%        3k ± 0%   ~     (p=1.000 n=1+1)
Read/gzip-4        491k ± 0%        3k ± 0%   ~     (p=1.000 n=1+1)
Read/lz4-4         491k ± 0%        3k ± 0%   ~     (p=1.000 n=1+1)
Read/snappy-4      491k ± 0%        3k ± 0%   ~     (p=1.000 n=1+1)

Decompression speed is now also more correct (esp. None is much higher than LZ4/Snappy)

		Before (/s)			Now (/s)
None	1.1 GB (n=1)		4.0 GB (n=1)
None	1.5 GB (n=9)		3.8 GB (n=38)
None	1.6 GB (n=13)
Gzip	516 MB (n=1)		640 MB (n=1)
Gzip	509 MB (n=3)		664 MB (n=4)
Gzip	514 MB (n=4)		649 MB (n=6)
LZ4		1.1 GB (n=1)		1.7 GB (n=1)
LZ4		1.1 GB (n=9)		1.9 GB (n=15)
Snappy	1.1 GB (n=1)		2.0 GB (n=1)
Snappy	1.1 GB (n=9)		1.8 GB (n=16)

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

@cyriltovena cyriltovena merged commit 4381b28 into grafana:master Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants