Skip to content

Conversation

@fommil
Copy link

@fommil fommil commented Apr 18, 2024

The MessageDecoder buffer is hard coded to 2MB and will grow to match the size of incoming messages. However, this can result in chronic allocations since the buffer will match the incoming message sizes exactly rather than growing in powers of two.

Furthermore, the cache never gets released, so one large message impacts the heap usage forever.

This is especially noticeable on systems that use the eventstream for services such as kinesis, where each lease/shard is allocated its own buffer. It is not long before the size of these buffers becomes a memory bottleneck for the service.

Description of changes:

  • the initial cache size is reduced to 1MB
  • the cache will grow to larger powers of 2, thereby anticipating future use
  • the cache will shrink to smaller powers of 2, if sustained usage fits within that size

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

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.

1 participant