Skip to content

[UNDERTOW-2809] Reduce contention in DefaultByteBufferPool thread-local lookups - #2002

Open
matthewbayer wants to merge 1 commit into
undertow-io:mainfrom
matthewbayer:reduce-buffer-cache-contention
Open

matthewbayer wants to merge 1 commit into
undertow-io:mainfrom
matthewbayer:reduce-buffer-cache-contention

Conversation

@matthewbayer

@matthewbayer matthewbayer commented Oct 8, 2026 •

Copy link
Copy Markdown

Reduce shared-registry contention while preserving per-thread buffer reuse.

DefaultByteBufferPool acquires a shared map monitor to find a thread’s cached buffers on allocation and release. Threads contend on that monitor even when reusing their own buffers.

This change gives each allocating thread a weak reference to its existing cache:

  • Most cached lookups use a Java ThreadLocal. The synchronized weak-key registry continues to own the cache data and support cleanup from another thread.
  • Every 256 successful cached lookups, the registry is accessed to expunge dead threads’ entries. Weak references prevent long-lived workers from retaining discarded pools.
  • Pools with caching disabled bypass the added ThreadLocal lookup and retain their existing registry/queue path.

Jira: https://redhat.atlassian.net/browse/UNDERTOW-2809

@matthewbayer
matthewbayer force-pushed the reduce-buffer-cache-contention branch from a3c60be to 5cfc774 Compare October 8, 2026 14:31
@matthewbayer matthewbayer changed the title Reduce contention in DefaultByteBufferPool thread-local lookups [UNDERTOW-2809] Reduce contention in DefaultByteBufferPool thread-local lookups Oct 8, 2026
@matthewbayer
matthewbayer marked this pull request as ready for review October 8, 2026 14:32
@matthewbayer

Copy link
Copy Markdown
Author

@fl4via curious for your thoughts here! We experience pretty significant degradation under high concurrent request counts due to this lock, happy to help out here in any way to address this problem.

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.

2 participants