ivandika3 opened a new pull request, #1715: URL: https://github.com/apache/ratis/pull/1715
## What changes were proposed in this pull request? Please see https://issues.apache.org/jira/browse/RATIS-2524 for the background. The main class of the implementation is the `ReadIndexBatching`. #### Follower read flows 1. `ReadRequestHandler#sendReadIndexAsync` requests a ReadIndex by calling `ReadIndexBatching#submit`. 2. `ReadIndexBatching` adds the pending ReadIndex invocation to its `pending` call and immediately schedule `drain` (i.e. smart batching will not wait until the batch size reaches a certain size and send as fast as possible to reduce the latency). 3. `drain` will send a `ReadIndex` RPC to the leader and wait for the results. 4. After the `ReadIndex` RPC is retrieved, `ReadIndexBatching` will complete the `Completable<ReadIndexReplyProto>` that the clients are waiting for 5. Client sees that the `ReadIndex` barrier has finished and proceed to read locally #### Design decisions - read-after-write requests will NOT use ReadIndex batching since the ReadIndex RPC requires to choose single client ID among all the ReadIndex requests while read-after-write requires client ID to be preserved. - ReadIndexBatching uses its own ThreadPool for sending ReadIndex RPC, draining, and completing so it doesn't contend with serverExecutor - We set the element limit so that a ReadIndex RPC does not wait for too long - We also allow increasing the number of inflight ReadIndex RPC. This can mitigates the issue where a slow ReadIndex RPC can cause head-of-line blocking to the subsequent ReadIndex RPC. - Disable ReadIndex batching implementation by default. However, it might be reasonable to not gate the ReadIndex batching with a configuration since systems like etcd already uses batching as its default implementation. #### Advantages - Amortizes the cost of ReadIndex RPC which reduces the network overhead and bandwidth and OS interrupts due to OS packet. This can improve the average throughput and latency. #### Drawbacks - Possible increased latency since ReadIndex requests does not trigger ReadIndex immediately (although Natural batching will try to serve ReadIndex batching immediately) - Reads are more bursty since reads in a batch are going to be executed at around the same time (instead of previously where reads are going to be served immediately as they arrive which can have a smoother distribution). This can increase things lock contentions due to the bursty reads. ### Performance results We saw sizeable improvements in the follower read throughput (although it's still well below the leader read performance) on Ozone Manager. #### Setup Cluster - 3 OMs: OM leader and followers are always the same - Freon tests with 0-sized key so the performance tests only measure metadata performance - Ratis configuration - `raft.server.read.leader.heartbeat-check.enabled=false`: Leadership heartbeat check disabled - `raft.server.read.read-index.type=APPLIED_INDEX`: Use appliedIndex as read index to reduce apply latency - `raft.server.read.read-index.batch.enabled=true`: Enable ReadIndexBatch - Client - Colocated with the same OM follower - 100 client threads Results | OP | Mode | Mean Write QPS | Write QPS speedup (vs Baseline) | Number of written objects | Mean Read QPS | Read QPS speedup (vs Baseline) | Number of read objects | P99 Write latency (ms) | P99 Read latency (ms) | | --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | `READ_KEY` | Leader read (baseline) | N/A | N/A | N/A | 235,020.55 | 1.0000 | 140,479,709 | N/A | 1.477595 | | `READ_KEY` | Batching disabled | N/A | N/A | N/A | 156,767.86 | 0.6670 | 93,770,480 | | 3.511545 | | `READ_KEY` | Batching enabled | N/A | N/A | N/A | 162,638.62 | 0.6920 | 97,277,587 | | 1.266164 | | `CREATE_KEY,READ_KEY 10%,90%` | Leader read (baseline) | 1,365.69 | | 816,862 | 218,236.41 | | 130,534,000 | 12.449381 | 1.459514 | | `CREATE_KEY,READ_KEY 10%,90%` | Batching disabled | 6,085.91 | 4.4563 | 3,640,135 | 43,035.35 | 0.1972 | 25,740,592 | 3.084175 | 11.85607 | | `CREATE_KEY,READ_KEY 10%,90%` | Batching enabled | 6,195.40 | 4.5365 | 3,705,699 | 66,489.96 | 0.3047 | 39,770,209 | 4.284225 | 4.818169 | | `CREATE_KEY,READ_KEY 30%,70%` | Leader read (baseline) | 2,177.63 | | 1,302,616 | 181,877.78 | | 108,796,004 | 19.874166 | 0.905082 | | `CREATE_KEY,READ_KEY 30%,70%` | Batching disabled | 9,167.05 | 4.2096 | 5,483,229 | 10,458.07 | 0.0575 | 6,255,469 | 5.586502 | 109.034817 | | `CREATE_KEY,READ_KEY 30%,70%` | Batching enabled | 8,138.04 | 3.7371 | 4,867,503 | 36,321.30 | 0.1997 | 21,724,443 | 6.355364 | 11.007342 | | `CREATE_KEY,READ_KEY 90%,10%` | Leader read (baseline) | 6,899.44 | | 4,126,729 | 37,131.68 | | 22,209,148 | 17.001288 | 0.396753 | | `CREATE_KEY,READ_KEY 90%,10%` | Batching disabled | 9,170.18 | 1.3291 | 5,484,918 | 6,460.76 | 0.1740 | 3,864,296 | 18.140096 | 4.184204 | | `CREATE_KEY,READ_KEY 90%,10%` | Batching enabled | 9,186.71 | 1.3315 | 5,495,646 | 7,269.17 | 0.1958 | 4,348,473 | 12.897366 | 3.693773 | | `CREATE_KEY,READ_KEY 70%,30%` | Leader read (baseline) | 4,794.36 | | 2,867,575 | 94,964.18 | | 56,799,117 | 17.304544 | 0.527844 | | `CREATE_KEY,READ_KEY 70%,30%` | Batching disabled | 9,170.18 | 1.9127 | 5,484,918 | 6,460.76 | 0.0680 | 3,864,296 | 18.140096 | 4.184204 | | `CREATE_KEY,READ_KEY 70%,30%` | Batching enabled | 8,754.77 | 1.8261 | 5,236,708 | 19,391.86 | 0.2042 | 11,599,107 | 13.704982 | 6.734598 | | `CREATE_KEY` | Leader read (baseline) | 9,747.37 | | 5,830,136 | N/A | N/A | N/A | 13.7777 | N/A | | `CREATE_KEY` | Batching disabled | 9,328.98 | 0.9571 | 5,579,766 | | | | 12.835864 | N/A | | `CREATE_KEY` | Batching enabled | 9,363.38 | 0.9606 | 5,600,510 | | | | 12.471511 | N/A | | `CREATE_KEY,LIST_KEYS 10%,90%` | Leader read (baseline) | 384.17 | | 229,791 | 3,615.25 | | 2,162,461 | 107.107106 | 57.610108 | | `CREATE_KEY,LIST_KEYS 10%,90%` | Batching disabled | 3,983.28 | 10.3685 | 2,383,125 | 4,074.35 | 1.1270 | 2,437,613 | 16.235464 | 103.484811 | | `CREATE_KEY,LIST_KEYS 10%,90%` | Batching enabled | 3,852.27 | 10.0275 | 2,304,594 | 4,210.29 | 1.1646 | 2,518,782 | 14.221871 | 83.369605 | | `CREATE_KEY,LIST_KEYS 30%,70%` | Leader read (baseline) | 1,048.83 | | 627,321 | 3,386.85 | | 2,025,721 | 100.985067 | 49.900742 | | `CREATE_KEY,LIST_KEYS 30%,70%` | Batching disabled | 8,608.64 | 8.2078 | 5,149,161 | 1,738.83 | 0.5134 | 1,040,062 | 7.452631 | 408.199677 | | `CREATE_KEY,LIST_KEYS 30%,70%` | Batching enabled | 8,747.88 | 8.3406 | 5,232,839 | 1,789.96 | 0.5285 | 1,070,731 | 11.018446 | 529.75776 | | `CREATE_KEY,LIST_KEYS 90%,10%` | Leader read (baseline) | 8,467.57 | | 5,064,468 | 883.45 | | 528,384 | 20.601753 | 14.697683 | | `CREATE_KEY,LIST_KEYS 90%,10%` | Batching disabled | 9,669.82 | 1.1420 | 5,784,518 | 442.50 | 0.5009 | 264,704 | 13.162005 | 412.046207 | | `CREATE_KEY,LIST_KEYS 90%,10%` | Batching enabled | 9,347.02 | 1.1039 | 5,590,801 | 558.77 | 0.6325 | 334,216 | 13.135697 | 127.401691 | | `CREATE_KEY,LIST_KEYS 70%,30%` | Leader read (baseline) | 5,538.96 | | 3,313,050 | 2,119.40 | | 1,267,684 | 46.01335 | 82.778703 | | `CREATE_KEY,LIST_KEYS 70%,30%` | Batching disabled | 9,234.24 | 1.6671 | 5,523,470 | 1,006.17 | 0.4747 | 601,836 | 11.691424 | 475.057008 | | `CREATE_KEY,LIST_KEYS 70%,30%` | Batching enabled | 9,007.03 | 1.6261 | 5,387,922 | 1,199.23 | 0.5658 | 717,361 | 13.978648 | 377.931547 | | `LIST_KEYS` | Leader read (baseline) | N/A | N/A | N/A | 3,467.72 | | 2,074,081 | N/A | 74.094971 | | `LIST_KEYS` | Batching disabled | N/A | N/A | N/A | 5,115.04 | 1.4750 | 3,061,681 | | 51.548571 | | `LIST_KEYS` | Batching enabled | N/A | N/A | N/A | 5,606.89 | 1.6169 | 3,355,152 | | 49.47335 | Evaluation - The read throughput ReadIndex batching is the same or improve on the linearizable follower read - Due to this, we can consider enabling ReadIndex batching by default - Leader write throughput is always higher when follower read is enabled - This is because there are less RW contention on the leader - Follower read vs Leader read throughput - Point query (READ_KEY): The follower read throughput is always lower than leader read - Range query (LIST_KEYS): The follower read throughput are higher than the leader read only for pure read or read-dominated workloads ## What is the link to the Apache JIRA https://issues.apache.org/jira/browse/RATIS-2524 ## How was this patch tested? UT, IT. -- 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]
