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

Small memory optimizations in badger write-path #1771

Merged
merged 1 commit into from
Sep 7, 2019

Conversation

burmanm
Copy link
Contributor

@burmanm burmanm commented Sep 3, 2019

Which problem is this PR solving?

This is work from another unfinished PR ported as standalone. Adds benchmarks for profiling purposes and removes some unnecessary duplicate processing and memory pressure from the write-path mostly.

Improves perf slightly:

benchmark                                           old ns/op      new ns/op      delta
BenchmarkWrites-8                                   8365954405     7515525425     -10.17%
BenchmarkServiceTagsRangeQueryLimitIndexFetch-8     61905754       59933936       -3.19%
BenchmarkServiceIndexLimitFetch-8                   41341527       39249518       -5.06%

But more interesting, reduces memory pressure towards GC when writing:

benchmark             old allocs     new allocs     delta
BenchmarkWrites-8     49572552       36456074       -26.46%

benchmark             old bytes      new bytes      delta
BenchmarkWrites-8     2080032376     1853283416     -10.90%

Short description of the changes

time-package calls are reduced, bytes.Buffer is replaced with writing to slice directly and copy() is used instead of append( ...)

@codecov
Copy link

codecov bot commented Sep 3, 2019

Codecov Report

Merging #1771 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1771      +/-   ##
==========================================
- Coverage   98.27%   98.23%   -0.05%     
==========================================
  Files         195      195              
  Lines        9540     9550      +10     
==========================================
+ Hits         9375     9381       +6     
- Misses        131      134       +3     
- Partials       34       35       +1
Impacted Files Coverage Δ
plugin/storage/badger/spanstore/writer.go 97.53% <100%> (+0.3%) ⬆️
plugin/storage/badger/spanstore/cache.go 100% <100%> (ø) ⬆️
plugin/storage/badger/spanstore/reader.go 96.72% <100%> (+0.02%) ⬆️
cmd/query/app/static_handler.go 83.33% <0%> (-3.51%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fb55050...1ee8eca. Read the comment docs.

pressure. Also, add some benchmarks for easier profiling to improve
performance in the future.

Signed-off-by: Michael Burman <[email protected]>
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

if there is a significant memory/gc pressure from these allocations, this should certainly help, but an even more efficient solution would be to pool byte arrays (or byte buffers) using sync.Pool. It could be a single pool since the buffers will eventually be extended to fit most of the keys.

@yurishkuro yurishkuro merged commit b8d21ac into jaegertracing:master Sep 7, 2019
bookmoons pushed a commit to bookmoons/jaeger that referenced this pull request Sep 10, 2019
…ng#1771)

Small memory optimizations in badger write-path  pressure. Also, add some benchmarks for easier profiling to improve performance in the future.

Signed-off-by: Michael Burman <[email protected]>
@yurishkuro yurishkuro added this to the Release 1.15 milestone Nov 7, 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.

2 participants