Skip to content

Conversation

@vietj
Copy link
Member

@vietj vietj commented Apr 24, 2025

Motivation:

The pg encoder allocates Netty buffer without an initial capacity, when pipelining is used this buffer can be reallocated multiple times and in agressive scenario can lead to out of memory errors with the adapative allocator.

Changes:

Cumulate and encode all the outbound messages at once when flush happens instead of cumulating them in the outbound buffer.

Capacity is estimated when a message is enqueued.

At flush time, a single buffer of the estimated capacity is created and the outbound messages are written to this buffer.

This requires to pre-render some messages to estimate their length, e.g. a json object is pre-rendered to a string that can be then estimated. The client has been modified to handle message preparation which takes care of this and lazy duplicate the tuple / list of tuples when this happens.

@vietj vietj added this to the 5.0.0 milestone Apr 24, 2025
@vietj vietj self-assigned this Apr 24, 2025
@vietj vietj force-pushed the pg-encoder-loop-rewrite branch 2 times, most recently from 555d5e9 to f68ab45 Compare April 27, 2025 19:28
…locates.

Motivation:

The pg encoder allocates Netty buffer without an initial capacity, when pipelining is used this buffer can be reallocated multiple times and in agressive scenario can lead to out of memory errors with the adapative allocator.

Changes:

Cumulate and encode all the outbound messages at once when flush happens instead of cumulating them in the outbound buffer.

Capacity is estimated when a message is enqueued.

At flush time, a single buffer of the estimated capacity is created and the outbound messages are written to this buffer.

This requires to pre-render some messages to estimate their length, e.g. a json object is pre-rendered to a string that can be then estimated. The client has been modified to handle message preparation which takes care of this and lazy duplicate the tuple / list of tuples when this happens.
@vietj vietj force-pushed the pg-encoder-loop-rewrite branch from f68ab45 to e4956f4 Compare April 27, 2025 19:28
@vietj vietj merged commit 0aaff5f into master Apr 27, 2025
18 checks passed
@vietj vietj deleted the pg-encoder-loop-rewrite branch April 27, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants