Repository navigation
Limit write chunk size in IOSessionImpl - #700
Conversation
1a7e393 to
050a56e
Compare
|
I do not think I think should be in Why 16K? |
Agreed — this belongs in the transport layer ( The 16K choice was not a hard requirement — just a reasonable upper bound: it matches the default HTTP/2 max frame size and the JDK HTTP client's internal buffer size, |
|
@yhzdys I fully agree with @arturobernalg The i/o session should be the right place to address the issue. If you could look into it, it would be awesome. You can start with 16K hardwired. We can figure out at the later point the best way to make it configurable |
Thanks! I'll rework it. |
|
@arturobernalg Reworked as suggested — the fix is now in |
Summary
IOSessionImpl#write(ByteBuffer)forwards the entire source buffer to the socket channel in a single write operation.When a heap
ByteBufferis written through a socket channel, the JDK copies its content through a temporary direct buffer of the same size.These buffers are cached per I/O dispatcher thread and never released for the entire thread life-span,
so large buffered output can pin an equally large amount of native memory per dispatcher thread — invisible to the GC, not bounded by
-Xmx,and able to trigger
OutOfMemoryError: Direct buffer memoryunder concurrent large transfers.Change
Chunk heap writes to 16 KB per underlying channel write operation, temporarily narrowing the buffer
limitand restoring it in afinallyblock.IOSessionImpl#writeis the single choke point for socket writes, so this covers all transports (HTTP/1.1, HTTP/2, TLS).Direct buffers bypass the chunking as the JDK does not copy them.
The chunk size is hardwired for now; it matches the default HTTP/2 max frame size and the internal buffer size used by the JDK's built-in HTTP client.