[
https://issues.apache.org/jira/browse/RATIS-2773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18130468#comment-18130468
]
Tsz-wo Sze commented on RATIS-2773:
-----------------------------------
[~peterxcli] This a great idea! BTW, you probably are aware of the following
API. We should do something similar.
{code}
// DataStreamOutput
CompletableFuture<DataStreamReply> writeAsync(FilePositionCount src,
WriteOption... options);
{code}
> 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)