Skip to content

Conversation

@JonasKunz
Copy link
Contributor

@JonasKunz JonasKunz commented Jul 17, 2023

What does this PR do?

Part of #3059.
Our IOUtils uses thread-locals for reusing ByteBuffer (2kb size) and CharsetDecoders.
This usage is not feasible with virtual threads, because 1 million threads for example would equate to 2gb memory usage due to the bytebuffers.

This PR replaces the thread-local based pooling with a queue based pool which we already use for other recycling use-cases. A new ObjectHandle-variant has been added to make the usage safe and easy via try-with-resources.

Resource pooling via a queue is expected to be more expensive than thread-local based pooling, as it involves at least two atomic CAS operations. Those should however not be to costly, as we expect low contention.

An alternative approach would be to use thread-locals for platform threads and queue based pooling for virtual threads, but I would expect the complexity here to not be worth it.

Checklist

@JonasKunz JonasKunz marked this pull request as ready for review July 17, 2023 07:57
@JonasKunz JonasKunz requested a review from jackshirazi July 17, 2023 07:57
@github-actions
Copy link

/test

@JonasKunz JonasKunz force-pushed the loom-friendly-pooling branch from 2042012 to e0c900a Compare July 18, 2023 11:34
@JonasKunz JonasKunz merged commit f09206d into elastic:main Jul 31, 2023
@JonasKunz JonasKunz deleted the loom-friendly-pooling branch July 31, 2023 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants