peterxcli opened a new pull request, #10743:
URL: https://github.com/apache/ozone/pull/10743

   ## What changes were proposed in this pull request?
   
   Adds a streaming block read over the Ratis data stream, as an alternative to 
the gRPC streaming read (`ozone.client.stream.readblock.enable`). Enable it 
with `ozone.client.ratis.stream.readblock.enable`. The client uses it for 
blocks of RATIS pipelines whose datanodes all support it 
(`DatanodeVersion.RATIS_DATASTREAM_READ_BLOCK_SUPPORT`) and have a data stream 
port.
   
   This branch has #11302 (HDDS-16258) merged in, which reworks the datanode 
side of streaming reads that this PR builds on. To review only this PR's 
changes, see the commits other than those of HDDS-16258.
   
   ### Client
   
   - `RatisDataStreamBlockInputStream` extends `StreamBlockInputStream`. Each 
ReadBlock request opens a read-only data stream 
(`DataStreamApi.streamReadOnly`) to the closest datanode of the pipeline, which 
sends the requested range as a series of replies.
   - `ozone.client.ratis.stream.read.window-size` (default 8 MiB) bounds the 
bytes requested ahead of the reader: a sequential reader keeps at most two 
pipelined requests of half the window in flight. Read-ahead starts only once 
the reader has read whole requests adding up to 128 KB since its last seek, and 
then doubles with each request. So a few short reads before a seek (Parquet 
reading an index, then a page header) request only what they read, and a long 
scan soon reads ahead the full half window. A reader that reads at least half 
the window at a time gets exactly what it asks for.
   - A seek within the buffered reply keeps reading from it. Any other seek 
closes the requests in flight.
   - Read streams take turns on `ozone.client.ratis.stream.read.connections` 
(default 8) connections to a datanode. A datanode sends each reply whole and in 
order on its connection, so with one shared connection the reply to a small 
read waits behind the large replies of other readers.
   - Replies are read from the buffers netty received them in, without merging 
them into one, and their checksums are verified across those buffers.
   - For an open container, a follower answers with `NotLeaderException` before 
sending any data, and the client retries on the suggested leader.
   - The Ratis data stream client defaults to 16 netty event loops 
(`hdds.ratis.raft.netty.dataStream.client.worker-group.size`). Each event loop 
has its own pooled buffer arena, and a client that reads many closed containers 
opens a connection per container. With the Ratis default of twice the CPUs, an 
HBase RegionServer's buffer pools grew to its 30 GiB direct memory limit.
   
   ### Datanode
   
   - `ContainerStateMachine.transferTo` serves a ReadBlock request on the 
read-only stream. Each reply is the length of the metadata, the metadata 
(`ContainerCommandResponseProto`), then the data. The block file is read 
straight into a pooled direct buffer that already holds the length and 
metadata, and the stream sends that buffer without copying it.
   - Read pipelines of closed containers have random IDs with no Raft group 
behind them. `ClosedContainerReadResolver` (a Ratis `DataStreamApi.Resolver`) 
serves those reads by container instead, when the request names this datanode.
   
   ### New configuration
   
   | Key | Default |
   |---|---|
   | `ozone.client.ratis.stream.readblock.enable` | `false` |
   | `ozone.client.ratis.stream.read.window-size` | 8 MiB |
   | `ozone.client.ratis.stream.read.connections` | 8 |
   | `hdds.ratis.raft.netty.dataStream.client.worker-group.size` | 16 |
   
   ### Performance
   
   TPC-H on Parquet stored in Ozone, read by Spark SQL with 64 tasks, on one 
host (2x AMD EPYC 9654, 377 GB RAM, one NVMe drive) with one datanode and 
RATIS/ONE. Cold runs at SF100 and SF10, with the datanode page cache dropped 
first:
   
   <img width="3200" height="1240" alt="image" 
src="https://github.com/user-attachments/assets/5f236409-634c-4943-b2af-946bdd2f25d9";
 />
   
   <img width="3200" height="1240" alt="image" 
src="https://github.com/user-attachments/assets/490b0b4e-8ff4-420d-9722-d8865adcea62";
 />
   
   - Over the whole of Q1–Q22, mean of 3 runs, Ratis took 0.89 of the time of 
gRPC with pre-read 0 at SF100 and 0.93 at SF10 cold, and 0.93 and 0.92 warm. At 
SF1 it took 0.98 cold and 0.96 warm. Pre-read 0 was the fastest gRPC setting at 
every scale factor.
   - At SF10 and SF100, Ratis was faster than both gRPC settings tested 
(pre-read 0 and 1 MiB) on 20 or 21 of the 22 queries, cold and warm. At SF100 
cold it took 182.9 s, against 205.1 s with pre-read 0 and 258.8 s with 1 MiB.
   - Pre-read is `ozone.client.stream.read.pre-read-size`. With 256 KB or 1 
MiB, gRPC reads 1.5 or 2.7 times the data of pre-read 0 at SF100 and is slower. 
Its default of 32 MiB reads many times the data Parquet needs.
   - Ratis reads the same bytes as gRPC with pre-read 0.
   - Ratis windows of 1, 8 and 32 MiB give the same times: at SF100 warm, 172.3 
and 172.1 s for 1 and 32 MiB in one run, and 173.0 s for the default 8 MiB in 
another.
   - In a cold run at SF1, the median Ratis request took 1.1 ms against 2.6 ms 
for gRPC for reads up to 64 KB, and 3.8 ms against 13.3 ms for 512 KB to 4 MB.
   - Each query ran once before the measured runs. On a query's first run in a 
JVM, Spark spends seconds in its generated code before the JIT has optimized 
it, on both read paths, and faster reads reach that code sooner. Those first 
runs made Ratis look 17% slower at SF1 and 8% slower at SF100.
   - Serving from the page cache, the datanode used 0.95 ms of CPU per Ratis 
ReadBlock request.
   - The datanode in these runs had an experimental cache of block metadata, 
which is not part of this PR and makes both read paths about 7% faster. The 
cost it avoids, parsing the whole block metadata for every request, will be 
fixed separately.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-9904
   
   ## How was this patch tested?
   
   - New unit tests: `TestRatisDataStreamBlockInputStream`, 
`TestXceiverClientRatis`, `TestStreamReadBlock` and 
`TestClosedContainerReadResolver`.
   - Additions to `TestOzoneClientConfig`, `TestStreamBlockInputStream`, 
`TestBlockInputStreamFactoryImpl`, `TestRatisHelper`, `TestChecksum` and 
`TestKeyValueHandler`.
   - New integration test `TestRatisDataStreamReadBlock`. `TestStreamRead` 
checks both streaming reads on blocks whose chunks shift the checksum 
boundaries.
   - TPC-H at SF1, SF10 and SF100, with Spark on Parquet and with HBase, 
comparing every query result with Parquet read directly. The latest commits 
were run at SF1, SF10 and SF100 on Parquet.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to