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

feat: reuse decompressed buffer to avoid allocating buffer whenever a batch is read. Fixes #909 #920

Merged
merged 1 commit into from May 31, 2022

Conversation

vmihailenco
Copy link
Contributor

@vmihailenco vmihailenco commented May 25, 2022

Fixes #909

@lizhifengones
Copy link

lizhifengones commented May 31, 2022

I have the same problem.

# go tool pprof -alloc_space http://192.168.10.101:6060/debug/pprof/heap
(pprof) top
Showing nodes accounting for 781.67MB, 92.64% of 843.73MB total
Dropped 146 nodes (cum <= 4.22MB)
Showing top 10 nodes out of 88
      flat  flat%   sum%        cum   cum%
  514.37MB 60.96% 60.96%   514.37MB 60.96%  bytes.makeSlice
  101.87MB 12.07% 73.04%   101.87MB 12.07%  kafka-comsume/pkg/variable.SetSyncPool.func1
   88.03MB 10.43% 83.47%    88.03MB 10.43%  github.com/pierrec/lz4/v4/internal/lz4block.glob..func6
      16MB  1.90% 85.37%   746.05MB 88.42%  kafka-comsume/pkg/kafka.(*KafkaComsumer).readKafkaMsgs

# Temporary memory is allocated for each batch
(pprof)list bytes.makeSlice
... ...
-----------+-------------------------------------------------------
     bytes:  3.98MB
   55.80MB   bytes.makeSlice
             bytes.(*Buffer).grow
             bytes.(*Buffer).Grow
             github.com/segmentio/kafka-go.(*messageSetReader).readMessageV2
             github.com/segmentio/kafka-go.(*messageSetReader).readMessage
             github.com/segmentio/kafka-go.(*Batch).readMessage
             github.com/segmentio/kafka-go.(*Batch).Read
             kafka-comsume/pkg/kafka.(*KafkaComsumer).readKafkaMsgs

@lizhifengones
Copy link

lizhifengones commented May 31, 2022

@nlsun PTAL

Copy link
Contributor

@nlsun nlsun left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the 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.

batch.Read(buf) allocates in readMessageV2
3 participants