You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by "Chu Cheng Li (Jira)" <ji...@apache.org> on 2026/10/22 10:51:00 UTC
[jira] [Updated] (RATIS-2773) Send file data in read-only data streams with sendfile
[ https://issues.apache.org/jira/browse/RATIS-2773?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Chu Cheng Li updated RATIS-2773:
--------------------------------
Description:
*Background*
A state machine serves a read-only data stream in {{DataStreamApi.transferTo(Message, WritableByteChannel)}}. Each {{write(ByteBuffer)}} on the channel sends one {{STREAM_DATA}} packet to the client.
*Problem*
The channel accepts only {{ByteBuffer}} data. Thus, a state machine that serves file data must first read the file into a buffer. Then netty writes the buffer to the socket. The server copies each byte from the page cache into the buffer, and then from the buffer into the socket.
Apache Ozone serves block reads this way (HDDS-9904). In a profile of a cold 8 GB read, the block file read uses 3.0 of the 4.9 CPU seconds of the datanode request threads. HDFS sends block data with {{FileChannel.transferTo}} (sendfile), without this copy.
*Proposal*
* Add {{DataStreamApi.FileRegionChannel}}. It is a {{WritableByteChannel}} with these methods:
** {{write(ByteBuffer header, FileChannel file, long position, long count)}} sends one packet. The packet contains the header, then {{count}} bytes of the file from {{position}}.
** {{flush()}} waits until all the packets are sent.
** {{isFileRegionSupported()}} returns false when the stream uses TLS.
* The netty read stream implements {{FileRegionChannel}}. It sends the file part as a {{DefaultFileRegion}}. The epoll and NIO transports send a {{DefaultFileRegion}} with sendfile.
* {{write}} does not wait until the packet is sent, because the packet holds no buffer. {{flush()}} and {{close()}} wait for all the packets. Thus, the file must stay open until {{flush()}} or {{close()}} returns.
* The file region does not close the file when netty releases it. The state machine closes the file.
* The packet format does not change. Thus, the client does not change.
*Limits*
* {{SslHandler}} accepts only {{ByteBuf}}. Thus, a stream with TLS does not support file regions. The state machine must use {{write(ByteBuffer)}}.
* sendfile runs in the netty event loop. If a page is not in the page cache, the event loop waits for the disk.
*Results*
A prototype on Ratis 3.3.1 with Ozone gave these results. The test used TestDFSIO on one host, with 3 datanodes on one NVMe disk.
||Test||Buffer copy||sendfile||
|One 8 GB file, cold, MB/s|812|1,152|
|One 8 GB file, warm, MB/s|949|1,251|
|16 files of 4 GB, warm, datanode CPU seconds per GB|2.04|0.78|
The Ozone part is HDDS-17317.
was:
*Background*
A state machine serves a read-only data stream in {{DataStreamApi.transferTo(Message, WritableByteChannel)}}. Each {{write(ByteBuffer)}} on the channel sends one {{STREAM_DATA}} packet to the client.
*Problem*
The channel accepts only {{ByteBuffer}} data. Thus, a state machine that serves file data must first read the file into a buffer. Then netty writes the buffer to the socket. The server copies each byte from the page cache into the buffer, and then from the buffer into the socket.
Apache Ozone serves block reads this way (HDDS-9904). In a profile of a cold 8 GB read, the block file read uses 3.0 of the 4.9 CPU seconds of the datanode request threads. HDFS sends block data with {{FileChannel.transferTo}} (sendfile), without this copy.
*Proposal*
* Add {{DataStreamApi.FileRegionChannel}}. It is a {{WritableByteChannel}} with these methods:
** {{write(ByteBuffer header, FileChannel file, long position, long count)}} sends one packet. The packet contains the header, then {{count}} bytes of the file from {{position}}.
** {{flush()}} waits until all the packets are sent.
** {{isFileRegionSupported()}} returns false when the stream uses TLS.
* The netty read stream implements {{FileRegionChannel}}. It sends the file part as a {{DefaultFileRegion}}. The epoll and NIO transports send a {{DefaultFileRegion}} with sendfile.
* {{write}} does not wait until the packet is sent, because the packet holds no buffer. {{flush()}} and {{close()}} wait for all the packets. Thus, the file must stay open until {{flush()}} or {{close()}} returns.
* The file region does not close the file when netty releases it. The state machine closes the file.
* The packet format does not change. Thus, the client does not change.
*Limits*
* {{SslHandler}} accepts only {{ByteBuf}}. Thus, a stream with TLS does not support file regions. The state machine must use {{write(ByteBuffer)}}.
* sendfile runs in the netty event loop. If a page is not in the page cache, the event loop waits for the disk.
*Results*
A prototype on Ratis 3.3.1 with Ozone gave these results. The test used TestDFSIO on one host, with 3 datanodes on one NVMe disk.
||Test||Buffer copy||sendfile||
|One 8 GB file, cold, MB/s|812|1,152|
|One 8 GB file, warm, MB/s|949|1,251|
|16 files of 4 GB, warm, datanode CPU seconds per GB|2.04|0.78|
The Ozone part is HDDS-XXXX.
> Send file data in read-only data streams with sendfile
> ------------------------------------------------------
>
> Key: RATIS-2773
> URL: https://issues.apache.org/jira/browse/RATIS-2773
> Project: Ratis
> Issue Type: Sub-task
> Components: API, Netty
> Reporter: Chu Cheng Li
> Assignee: Chu Cheng Li
> Priority: Major
>
> *Background*
> A state machine serves a read-only data stream in {{DataStreamApi.transferTo(Message, WritableByteChannel)}}. Each {{write(ByteBuffer)}} on the channel sends one {{STREAM_DATA}} packet to the client.
> *Problem*
> The channel accepts only {{ByteBuffer}} data. Thus, a state machine that serves file data must first read the file into a buffer. Then netty writes the buffer to the socket. The server copies each byte from the page cache into the buffer, and then from the buffer into the socket.
> Apache Ozone serves block reads this way (HDDS-9904). In a profile of a cold 8 GB read, the block file read uses 3.0 of the 4.9 CPU seconds of the datanode request threads. HDFS sends block data with {{FileChannel.transferTo}} (sendfile), without this copy.
> *Proposal*
> * Add {{DataStreamApi.FileRegionChannel}}. It is a {{WritableByteChannel}} with these methods:
> ** {{write(ByteBuffer header, FileChannel file, long position, long count)}} sends one packet. The packet contains the header, then {{count}} bytes of the file from {{position}}.
> ** {{flush()}} waits until all the packets are sent.
> ** {{isFileRegionSupported()}} returns false when the stream uses TLS.
> * The netty read stream implements {{FileRegionChannel}}. It sends the file part as a {{DefaultFileRegion}}. The epoll and NIO transports send a {{DefaultFileRegion}} with sendfile.
> * {{write}} does not wait until the packet is sent, because the packet holds no buffer. {{flush()}} and {{close()}} wait for all the packets. Thus, the file must stay open until {{flush()}} or {{close()}} returns.
> * The file region does not close the file when netty releases it. The state machine closes the file.
> * The packet format does not change. Thus, the client does not change.
> *Limits*
> * {{SslHandler}} accepts only {{ByteBuf}}. Thus, a stream with TLS does not support file regions. The state machine must use {{write(ByteBuffer)}}.
> * sendfile runs in the netty event loop. If a page is not in the page cache, the event loop waits for the disk.
> *Results*
> A prototype on Ratis 3.3.1 with Ozone gave these results. The test used TestDFSIO on one host, with 3 datanodes on one NVMe disk.
> ||Test||Buffer copy||sendfile||
> |One 8 GB file, cold, MB/s|812|1,152|
> |One 8 GB file, warm, MB/s|949|1,251|
> |16 files of 4 GB, warm, datanode CPU seconds per GB|2.04|0.78|
> The Ozone part is HDDS-17317.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)