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

Provide peekInt8 to reduce allocations #1373

Merged
merged 3 commits into from
May 22, 2019
Merged

Provide peekInt8 to reduce allocations #1373

merged 3 commits into from
May 22, 2019

Conversation

shanson7
Copy link
Contributor

Background:
In a project I use, sarama produces by far the most ongoing allocations (mainly, I think, because have lots of small messages) which negatively impacts our GC stats. I recently went through and tried to reduce them where I could and have been quite successful in that sarama doesn't show up in the pprof top10 by alloc_objects. This is the simplest change I made so far. The others follow the pattern from #1161 and are more invasive.

I benchmarked this change by consuming 5 million messages and then dumping out a heap profile.
Before the change:

Showing nodes accounting for 30777165, 99.24% of 31012468 total
Dropped 6 nodes (cum <= 155062)
Showing top 10 nodes out of 19
      flat  flat%   sum%        cum   cum%
  10362760 33.41% 33.41%   25777082 83.12%  github.com/Shopify/sarama.(*MessageBlock).decode
   5172719 16.68% 50.09%   25887933 83.48%  github.com/Shopify/sarama.(*MessageSet).decode
   5123816 16.52% 66.62%    5123816 16.52%  github.com/Shopify/sarama.(*partitionConsumer).parseMessages
   5087542 16.40% 83.02%    5087542 16.40%  github.com/Shopify/sarama.(*realDecoder).peek

Here you can see that peek is responsible for 16.4% of the objects allocated, a little over one per message (makes sense, because of the record batching in kafka).

After the change:

Showing nodes accounting for 25577632, 99.73% of 25647802 total

Peek doesn't show up at all and we allocate 25.6 million objects vs 31 million, which is the expected reduction.

real_decoder.go Outdated Show resolved Hide resolved
real_decoder.go Outdated Show resolved Hide resolved
@@ -27,6 +27,7 @@ type packetDecoder interface {
remaining() int
getSubset(length int) (packetDecoder, error)
peek(offset, length int) (packetDecoder, error) // similar to getSubset, but it doesn't advance the offset
Copy link
Contributor

Choose a reason for hiding this comment

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

If this change work, do we still need peek method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are no existing uses of peek. Should I remove it?

Copy link
Contributor

Choose a reason for hiding this comment

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

let's wait. @bai you have any inputs?

@shanson7
Copy link
Contributor Author

Any update?

@bai
Copy link
Contributor

bai commented May 22, 2019

Thanks for your contribution!

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.

3 participants