Skip to content

S3 driver: buffer pool - #3798

Closed
teivah wants to merge 1 commit into
distribution:mainfrom
teivah:s3-pool
Closed

teivah wants to merge 1 commit into
distribution:mainfrom
teivah:s3-pool

Conversation

@teivah

@teivah teivah commented Nov 22, 2022

Copy link
Copy Markdown

Use a pool to store the S3 driver buffers.

Signed-off-by: Teiva Harsanyi <[email protected]>
@teivah
teivah marked this pull request as ready for review November 22, 2022 09:32
@milosgajdos
milosgajdos requested a review from corhere December 11, 2022 13:00

@corhere corhere left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

After examining the implementation of writer, I am very skeptical that pooling buffers from closed writers for reuse in new writers is the right choice of starting point for optimizing the S3 driver's GC pressure. func (*writer) Write and especially func (*writer) flushPart drop buffers all over the place, pretty much guaranteeing that any buffer taken from the pool will be used by at most two writers before becoming garbage. For instance, each call to func (*writer) flushPart drops either w.pendingPart or w.readyPart if the buffers are nonempty. Optimize writer to better reuse its own buffers before thinking about reusing buffers between writers.

For example, flushPart currently flips the pending and ready buffers by

w.readyPart = w.pendingPart
w.pendingPart = nil

which drops the buffer which was assigned to w.readyPart. That buffer could instead be reused for the next w.pendingPart:

tmp := w.readyPart[:0]
w.readyPart = w.pendingPart
w.pendingPart = tmp

Comment on lines +1442 to +1443
w.pool.Put(w.readyPart[:0])
w.pool.Put(w.pendingPart[:0])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The w.pool field is redundant as it can be accessed via w.driver.pool.

Suggested change
w.pool.Put(w.readyPart[:0])
w.pool.Put(w.pendingPart[:0])
w.driver.pool.Put(w.readyPart[:0])
w.driver.pool.Put(w.pendingPart[:0])

@milosgajdos

Copy link
Copy Markdown
Member

Closing in favour of #4066

@milosgajdos milosgajdos closed this Oct 1, 2023
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.

3 participants