This is an automated email from the ASF dual-hosted git repository.

nicholasjiang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/celeborn.git


The following commit(s) were added to refs/heads/main by this push:
     new c456df3ec [CELEBORN-2298] Introduce NettyTransportBenchmark for Netty 
transport layer performance evaluation
c456df3ec is described below

commit c456df3ec6a4611895dcc7dfe4167ef1e261560c
Author: SteNicholas <[email protected]>
AuthorDate: Mon Apr 13 10:26:56 2026 +0700

    [CELEBORN-2298] Introduce NettyTransportBenchmark for Netty transport layer 
performance evaluation
    
    ### What changes were proposed in this pull request?
    
    Introduce `NettyTransportBenchmark` for Netty transport layer performance 
evaluation.
    
    All suites measure performance through the actual Celeborn transport 
pipeline
    (`TransportServer` + `TransportClientFactory` + `TransportContext`).
    
    Suite overview:
    1. RPC Latency            - server-client RPC overhead at different payload 
sizes
    2. Concurrent Throughput  - multi-client pressure on the transport layer
    3. IOMode Comparison      - NIO vs native transport (Automatically selects 
EPOLL/KQUEUE)
    4. Server Thread Scaling  - validates MAX_DEFAULT_NETTY_THREADS=8 cap
    5. Multi-Connection       - numConnectionsPerPeer=1 vs 2 vs 4
    6. Async Write Pressure   - fire-and-forget RPCs to saturate the write path
    7. Large Block Transfer   - shuffle-like 16MB block transfers (in-memory 
payload)
    8. File-Backed Shuffle    - ChunkFetch from disk, NIO vs native transport 
(EPOLL sendfile bypass detection)
    
    Backport: https://github.com/apache/spark/pull/55061.
    
    ### Why are the changes needed?
    
    Netty is a crucial third-party component for Celeborn. Introduce a 
micro-benchmark test facilitates:
    
    - Verify performance during subsequent Netty upgrades;
    - Validate performance after changes to relevant code in Celeborn.
    
    ### Does this PR resolve a correctness bug?
    
    No.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Generated `NettyTransportBenchmark-results.txt`.
    
    Closes #3647 from SteNicholas/CELEBORN-2298.
    
    Lead-authored-by: SteNicholas <[email protected]>
    Co-authored-by: Cheng Pan <[email protected]>
    Signed-off-by: SteNicholas <[email protected]>
---
 .../NettyTransportBenchmark-jdk17-results.txt      | 123 +++++
 .../benchmarks/NettyTransportBenchmark-results.txt | 123 +++++
 .../network/client/TransportClientFactory.java     |  12 +
 .../celeborn/common/network/util/NettyUtils.java   |   8 +
 .../org/apache/celeborn/common/CelebornConf.scala  |  12 +-
 .../common/network/NettyTransportBenchmark.scala   | 584 +++++++++++++++++++++
 .../NettyTransportBenchmark-jdk17-results.txt      |  14 +
 .../benchmarks/NettyTransportBenchmark-results.txt |   4 +
 .../service/deploy/worker/FetchHandler.scala       |   6 +-
 .../deploy/network/NettyTransportBenchmark.scala   | 298 +++++++++++
 10 files changed, 1179 insertions(+), 5 deletions(-)

diff --git a/common/benchmarks/NettyTransportBenchmark-jdk17-results.txt 
b/common/benchmarks/NettyTransportBenchmark-jdk17-results.txt
new file mode 100644
index 000000000..01f862bab
--- /dev/null
+++ b/common/benchmarks/NettyTransportBenchmark-jdk17-results.txt
@@ -0,0 +1,123 @@
+================================================================================================
+RPC Round-Trip Latency - 1 KB payload (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 17.0.15+6-LTS on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+RPC Latency (1 KB):                       Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+1 KB payload                                        524            533         
 16          0.0      104753.3       1.0X
+
+
+================================================================================================
+RPC Round-Trip Latency - 64 KB payload (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 17.0.15+6-LTS on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+RPC Latency (64 KB):                      Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+64 KB payload                                      2521           2532         
 10          0.0      504112.3       1.0X
+
+
+================================================================================================
+RPC Round-Trip Latency - 1 MB payload (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 17.0.15+6-LTS on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+RPC Latency (1 MB):                       Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+1 MB payload                                       6438           6451         
 13          0.0     6438320.7       1.0X
+
+
+================================================================================================
+RPC Round-Trip Latency - 16 MB payload (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 17.0.15+6-LTS on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+RPC Latency (16 MB):                      Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+16 MB payload                                      9923          10034         
103          0.0    99231610.5       1.0X
+
+
+================================================================================================
+Concurrent RPC Throughput (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 17.0.15+6-LTS on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+Concurrent RPC Throughput:                Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+1 client(s)                                        2049           2097         
 50          0.0      102469.1       1.0X
+4 client(s)                                        1325           1355         
 30          0.0       66251.5       1.5X
+8 client(s)                                        1121           1142         
 18          0.0       56046.7       1.8X
+16 client(s)                                       1095           1106         
 10          0.0       54742.0       1.9X
+
+
+================================================================================================
+IOMode Comparison (Concurrent Throughput)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 17.0.15+6-LTS on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+IOMode Comparison:                        Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+NIO (8 clients)                                    5399           5459         
 83          0.0      269943.5       1.0X
+EPOLL (8 clients)                                  5288           5374         
 84          0.0      264393.7       1.0X
+
+
+================================================================================================
+Server Thread Scaling (IOMode=EPOLL, 16 clients)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 17.0.15+6-LTS on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+Server Thread Scaling:                    Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+2 server threads                                   1034           1044         
  9          0.0       51713.7       1.0X
+4 server threads                                   1059           1062         
  4          0.0       52962.1       1.0X
+8 server threads                                   1074           1076         
  3          0.0       53712.2       1.0X
+16 server threads                                  1090           1101         
 16          0.0       54503.7       0.9X
+32 server threads                                  1069           1145         
 68          0.0       53447.3       1.0X
+
+
+================================================================================================
+Multi-Connection Per Peer (IOMode=EPOLL, 1MB payload)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 17.0.15+6-LTS on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+Multi-Connection Throughput:              Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+1 conn(s), 4 threads                              31793          32359         
883          0.0     6358548.8       1.0X
+2 conn(s), 4 threads                              20196          20265         
 63          0.0     4039234.4       1.6X
+4 conn(s), 4 threads                              17268          17333         
 81          0.0     3453573.5       1.8X
+
+
+================================================================================================
+Async Write Pressure (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 17.0.15+6-LTS on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+Async Write Throughput:                   Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+1 KB async burst                                     73             74         
  1          0.1       14656.2       1.0X
+64 KB async burst                                  2247           2255         
 10          0.0      449355.7       0.0X
+1 MB async burst                                  31720          31831         
 98          0.0     6343939.2       0.0X
+
+
+================================================================================================
+Large Block Transfer Throughput (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 17.0.15+6-LTS on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+16 MB Block Transfer:                     Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+Sequential sends                                  10197          10222         
 29          0.0   101965659.2       1.0X
+4-thread parallel sends                            5498           5508         
 16          0.0    54980188.1       1.9X
+
+
diff --git a/common/benchmarks/NettyTransportBenchmark-results.txt 
b/common/benchmarks/NettyTransportBenchmark-results.txt
new file mode 100644
index 000000000..7fd5ed27b
--- /dev/null
+++ b/common/benchmarks/NettyTransportBenchmark-results.txt
@@ -0,0 +1,123 @@
+================================================================================================
+RPC Round-Trip Latency - 1 KB payload (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 1.8.0_432-b06 on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+RPC Latency (1 KB):                       Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+1 KB payload                                        522            537         
 17          0.0      104306.4       1.0X
+
+
+================================================================================================
+RPC Round-Trip Latency - 64 KB payload (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 1.8.0_432-b06 on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+RPC Latency (64 KB):                      Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+64 KB payload                                      2484           2516         
 47          0.0      496880.6       1.0X
+
+
+================================================================================================
+RPC Round-Trip Latency - 1 MB payload (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 1.8.0_432-b06 on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+RPC Latency (1 MB):                       Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+1 MB payload                                       6370           6382         
 12          0.0     6370193.2       1.0X
+
+
+================================================================================================
+RPC Round-Trip Latency - 16 MB payload (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 1.8.0_432-b06 on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+RPC Latency (16 MB):                      Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+16 MB payload                                      9727           9768         
 31          0.0    97271624.0       1.0X
+
+
+================================================================================================
+Concurrent RPC Throughput (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 1.8.0_432-b06 on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+Concurrent RPC Throughput:                Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+1 client(s)                                        2007           2082         
 70          0.0      100368.0       1.0X
+4 client(s)                                        1241           1257         
 21          0.0       62035.5       1.6X
+8 client(s)                                        1042           1051         
 12          0.0       52077.6       1.9X
+16 client(s)                                       1024           1027         
  4          0.0       51206.5       2.0X
+
+
+================================================================================================
+IOMode Comparison (Concurrent Throughput)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 1.8.0_432-b06 on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+IOMode Comparison:                        Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+NIO (8 clients)                                    5146           5173         
 26          0.0      257286.2       1.0X
+EPOLL (8 clients)                                  5044           5071         
 26          0.0      252196.6       1.0X
+
+
+================================================================================================
+Server Thread Scaling (IOMode=EPOLL, 16 clients)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 1.8.0_432-b06 on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+Server Thread Scaling:                    Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+2 server threads                                    983            995         
 14          0.0       49167.8       1.0X
+4 server threads                                   1001           1014         
 20          0.0       50042.0       1.0X
+8 server threads                                   1015           1026         
 19          0.0       50737.9       1.0X
+16 server threads                                  1027           1052         
 31          0.0       51332.2       1.0X
+32 server threads                                  1032           1035         
  3          0.0       51618.3       1.0X
+
+
+================================================================================================
+Multi-Connection Per Peer (IOMode=EPOLL, 1MB payload)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 1.8.0_432-b06 on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+Multi-Connection Throughput:              Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+1 conn(s), 4 threads                              31726          32399        
1076          0.0     6345298.2       1.0X
+2 conn(s), 4 threads                              20641          20946         
386          0.0     4128100.8       1.5X
+4 conn(s), 4 threads                              16958          17319         
370          0.0     3391650.7       1.9X
+
+
+================================================================================================
+Async Write Pressure (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 1.8.0_432-b06 on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+Async Write Throughput:                   Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+1 KB async burst                                     70             72         
  2          0.1       14087.9       1.0X
+64 KB async burst                                  2240           2256         
 17          0.0      447946.2       0.0X
+1 MB async burst                                  32199          32584         
341          0.0     6439790.4       0.0X
+
+
+================================================================================================
+Large Block Transfer Throughput (IOMode=EPOLL)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 1.8.0_432-b06 on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+16 MB Block Transfer:                     Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+Sequential sends                                  10263          10475         
187          0.0   102625029.7       1.0X
+4-thread parallel sends                            5428           5509         
 71          0.0    54275773.9       1.9X
+
+
diff --git 
a/common/src/main/java/org/apache/celeborn/common/network/client/TransportClientFactory.java
 
b/common/src/main/java/org/apache/celeborn/common/network/client/TransportClientFactory.java
index 370b3e62a..08c0d277b 100644
--- 
a/common/src/main/java/org/apache/celeborn/common/network/client/TransportClientFactory.java
+++ 
b/common/src/main/java/org/apache/celeborn/common/network/client/TransportClientFactory.java
@@ -261,6 +261,18 @@ public class TransportClientFactory implements Closeable {
     return createClient(remoteHost, remotePort, -1);
   }
 
+  /**
+   * Create a completely new {@link TransportClient} to the given remote host 
/ port. This
+   * connection is not pooled.
+   *
+   * <p>As with {@link #createClient(String, int)}, this method is blocking.
+   */
+  public TransportClient createUnmanagedClient(String remoteHost, int 
remotePort)
+      throws IOException, InterruptedException {
+    final InetSocketAddress address = new InetSocketAddress(remoteHost, 
remotePort);
+    return internalCreateClient(address, NettyUtils.createFrameDecoder());
+  }
+
   /**
    * Create a completely new {@link TransportClient} to the given remote host 
/ port. This
    * connection is not pooled.
diff --git 
a/common/src/main/java/org/apache/celeborn/common/network/util/NettyUtils.java 
b/common/src/main/java/org/apache/celeborn/common/network/util/NettyUtils.java
index df9d507a2..a68399199 100644
--- 
a/common/src/main/java/org/apache/celeborn/common/network/util/NettyUtils.java
+++ 
b/common/src/main/java/org/apache/celeborn/common/network/util/NettyUtils.java
@@ -122,6 +122,14 @@ public class NettyUtils {
     }
   }
 
+  /**
+   * Creates a LengthFieldBasedFrameDecoder where the first 8 bytes are the 
length of the frame.
+   * This is used before all decoders.
+   */
+  public static TransportFrameDecoder createFrameDecoder() {
+    return new TransportFrameDecoder();
+  }
+
   /** Returns the remote address on the channel or "&lt;unknown remote&gt;" if 
none exists. */
   public static String getRemoteAddress(Channel channel) {
     if (channel != null && channel.remoteAddress() != null) {
diff --git 
a/common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala 
b/common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala
index 59b729bf0..798099bcb 100644
--- a/common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala
+++ b/common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala
@@ -60,7 +60,7 @@ class CelebornConf(loadDefaults: Boolean) extends Cloneable 
with Logging with Se
     _reader
   }
 
-  private def loadFromMap(props: Map[String, String], silent: Boolean): Unit =
+  def loadFromMap(props: Map[String, String], silent: Boolean): Unit =
     settings.synchronized {
       // Load any celeborn.* system properties
       for ((key, value) <- props if key.startsWith("celeborn.")) {
@@ -545,9 +545,7 @@ class CelebornConf(loadDefaults: Boolean) extends Cloneable 
with Logging with Se
   def networkIoMode(module: String): String = {
     get(
       NETWORK_IO_MODE.key.replace("<module>", module),
-      if (Epoll.isAvailable) { IOMode.EPOLL.name() }
-      else if (KQueue.isAvailable) { IOMode.KQUEUE.name() }
-      else { IOMode.NIO.name() })
+      CelebornConf.networkIoMode())
   }
 
   def networkIoPreferDirectBufs(module: String): Boolean = {
@@ -1916,6 +1914,12 @@ object CelebornConf extends Logging {
 
   private def buildConf(key: String): ConfigBuilder = 
ConfigBuilder(key).onCreate(register)
 
+  def networkIoMode(): String = {
+    if (Epoll.isAvailable) { IOMode.EPOLL.name() }
+    else if (KQueue.isAvailable) { IOMode.KQUEUE.name() }
+    else { IOMode.NIO.name() }
+  }
+
   val NETWORK_BIND_PREFER_IP: ConfigEntry[Boolean] =
     buildConf("celeborn.network.bind.preferIpAddress")
       .categories("network")
diff --git 
a/common/src/test/scala/org/apache/celeborn/common/network/NettyTransportBenchmark.scala
 
b/common/src/test/scala/org/apache/celeborn/common/network/NettyTransportBenchmark.scala
new file mode 100644
index 000000000..8448e8ed3
--- /dev/null
+++ 
b/common/src/test/scala/org/apache/celeborn/common/network/NettyTransportBenchmark.scala
@@ -0,0 +1,584 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.celeborn.common.network
+
+import java.nio.ByteBuffer
+import java.util.concurrent.{CountDownLatch, TimeUnit}
+import java.util.concurrent.atomic.AtomicLong
+
+import org.apache.celeborn.benchmark.{Benchmark, BenchmarkBase}
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.network.client.{RpcResponseCallback, 
TransportClient, TransportClientFactory}
+import org.apache.celeborn.common.network.protocol.RequestMessage
+import org.apache.celeborn.common.network.server.BaseMessageHandler
+import org.apache.celeborn.common.network.util.TransportConf
+
+/**
+ * Benchmark for Celeborn's Netty transport layer.
+ *
+ * All suites measure performance through the actual Celeborn transport 
pipeline
+ * (TransportServer + TransportClientFactory + TransportContext).
+ *
+ * Suite overview:
+ *   1. RPC Latency            - server-client RPC overhead at different 
payload sizes
+ *   2. Concurrent Throughput  - multi-client pressure on the transport layer
+ *   3. IOMode Comparison      - NIO vs native transport (Automatically 
selects EPOLL/KQUEUE)
+ *   4. Server Thread Scaling  - validates MAX_DEFAULT_NETTY_THREADS=8 cap
+ *   5. Multi-Connection       - numConnectionsPerPeer=1 vs 2 vs 4
+ *   6. Async Write Pressure   - fire-and-forget RPCs to saturate the write 
path
+ *   7. Large Block Transfer   - shuffle-like 16MB block transfers (in-memory 
payload)
+ *
+ * {{{
+ *   To run this benchmark:
+ *   1. build/sbt "celeborn-common/test:runMain <this class>"
+ *   2. generate result:
+ *      CELEBORN_GENERATE_BENCHMARK_FILES=1 build/sbt 
"celeborn-common/test:runMain <this class>"
+ *      Results will be written to 
"benchmarks/NettyTransportBenchmark-results.txt".
+ * }}}
+ */
+object NettyTransportBenchmark extends BenchmarkBase {
+
+  private val SMALL_PAYLOAD = 1024 // 1 KB
+  private val MEDIUM_PAYLOAD = 64 * 1024 // 64 KB
+  private val LARGE_PAYLOAD = 1024 * 1024 // 1 MB
+  private val XLARGE_PAYLOAD = 16 * 1024 * 1024 // 16 MB
+
+  private val RPC_ITERS = 5000
+  private val THROUGHPUT_ITERS = 20000
+
+  // Fixed 8-byte ACK response, avoids heap allocation proportional to payload.
+  private val ACK_BYTES = Array[Byte](0, 0, 0, 0, 0, 0, 0, 1)
+
+  private def createEchoRpcHandler(): BaseMessageHandler = new 
BaseMessageHandler {
+    override def receive(
+        client: TransportClient,
+        message: RequestMessage,
+        callback: RpcResponseCallback): Unit = {
+      callback.onSuccess(ByteBuffer.wrap(ACK_BYTES))
+    }
+
+    override def checkRegistered(): Boolean = true
+  }
+
+  private def createConf(
+      ioMode: String,
+      serverThreads: Int = 4,
+      clientThreads: Int = 4,
+      extraConf: Map[String, String] = Map.empty): TransportConf = {
+    val celebornConf = new CelebornConf()
+      .set("celeborn.shuffle.io.mode", ioMode)
+      .set("celeborn.shuffle.io.serverThreads", serverThreads.toString)
+      .set("celeborn.shuffle.io.clientThreads", clientThreads.toString)
+    celebornConf.loadFromMap(extraConf, silent = false)
+    new TransportConf("shuffle", celebornConf)
+  }
+
+  /**
+   * Sets up a TransportServer + TransportClientFactory, runs fn, then tears 
down.
+   */
+  private def withTransport(conf: TransportConf)(
+      fn: (TransportClientFactory, Int) => Unit): Unit = {
+    val context = new TransportContext(conf, createEchoRpcHandler())
+    val server = context.createServer()
+    val clientFactory = context.createClientFactory()
+    try {
+      fn(clientFactory, server.getPort)
+    } finally {
+      clientFactory.close()
+      server.close()
+      context.close()
+    }
+  }
+
+  private def withTransport(ioMode: String)(
+      fn: (TransportClientFactory, Int) => Unit): Unit = {
+    withTransport(createConf(ioMode))(fn)
+  }
+
+  /**
+   * Sends a synchronous RPC. Throws on failure to prevent silent result 
corruption.
+   */
+  private def sendRpcSync(
+      client: TransportClient,
+      payload: Array[Byte],
+      timeoutMs: Long = 30000): Unit = {
+    val latch = new CountDownLatch(1)
+    @volatile var error: Throwable = null
+    client.sendRpc(
+      ByteBuffer.wrap(payload),
+      new RpcResponseCallback {
+        override def onSuccess(response: ByteBuffer): Unit = latch.countDown()
+        override def onFailure(e: Throwable): Unit = {
+          error = e
+          latch.countDown()
+        }
+      })
+    if (!latch.await(timeoutMs, TimeUnit.MILLISECONDS)) {
+      throw new RuntimeException("RPC timed out")
+    }
+    if (error != null) {
+      throw new RuntimeException("RPC failed", error)
+    }
+  }
+
+  /**
+   * Fires RPCs asynchronously and waits for all to complete.
+   * Returns (successCount, failCount).
+   */
+  private def sendRpcsAsync(
+      client: TransportClient,
+      payload: Array[Byte],
+      count: Int): (Long, Long) = {
+    val successCount = new AtomicLong(0)
+    val failCount = new AtomicLong(0)
+    val latch = new CountDownLatch(count)
+    var i = 0
+    while (i < count) {
+      client.sendRpc(
+        ByteBuffer.wrap(payload),
+        new RpcResponseCallback {
+          override def onSuccess(response: ByteBuffer): Unit = {
+            successCount.incrementAndGet()
+            latch.countDown()
+          }
+          override def onFailure(e: Throwable): Unit = {
+            failCount.incrementAndGet()
+            latch.countDown()
+          }
+        })
+      i += 1
+    }
+    latch.await(120, TimeUnit.SECONDS)
+    (successCount.get(), failCount.get())
+  }
+
+  /**
+   * Creates N independent (non-pooled) connections to the server.
+   * Uses createUnmanagedClient to bypass TransportClientFactory's connection 
pool,
+   * which defaults to numConnectionsPerPeer=1 and would return the same 
client.
+   */
+  private def createClients(
+      factory: TransportClientFactory,
+      port: Int,
+      count: Int): Seq[TransportClient] = {
+    (0 until count).map(_ => factory.createUnmanagedClient("localhost", port))
+  }
+
+  // ==================== Benchmark Suites ====================
+
+  /**
+   * Suite 1: RPC Round-Trip Latency at different payload sizes.
+   * Each size is a separate Benchmark so valuesPerIteration and Rate are 
accurate.
+   */
+  private def rpcLatencyBenchmark(): Unit = {
+    val ioMode = detectIOMode()
+
+    Seq(
+      ("1 KB", SMALL_PAYLOAD, RPC_ITERS),
+      ("64 KB", MEDIUM_PAYLOAD, RPC_ITERS),
+      ("1 MB", LARGE_PAYLOAD, RPC_ITERS / 5),
+      ("16 MB", XLARGE_PAYLOAD, RPC_ITERS / 50)).foreach { case (sizeLabel, 
payloadSize, iters) =>
+      runBenchmark(s"RPC Round-Trip Latency - $sizeLabel payload 
(IOMode=$ioMode)") {
+        withTransport(ioMode) { (clientFactory, port) =>
+          val client = clientFactory.createUnmanagedClient("localhost", port)
+          val payload = new Array[Byte](payloadSize)
+
+          val benchmark = new Benchmark(
+            s"RPC Latency ($sizeLabel)",
+            iters.toLong,
+            minNumIters = 3,
+            output = output)
+
+          benchmark.addTimerCase(s"$sizeLabel payload", numIters = 5) { timer 
=>
+            sendRpcSync(client, payload) // warm up
+
+            timer.startTiming()
+            var i = 0
+            while (i < iters) {
+              sendRpcSync(client, payload)
+              i += 1
+            }
+            timer.stopTiming()
+          }
+
+          benchmark.run()
+          client.close()
+        }
+      }
+    }
+  }
+
+  /**
+   * Suite 2: Concurrent RPC throughput with 1-16 independent connections.
+   * Uses createUnmanagedClient so each "client" is a distinct TCP connection.
+   */
+  private def concurrentThroughputBenchmark(): Unit = {
+    val ioMode = detectIOMode()
+
+    runBenchmark(s"Concurrent RPC Throughput (IOMode=$ioMode)") {
+      withTransport(ioMode) { (clientFactory, port) =>
+        val payload = new Array[Byte](SMALL_PAYLOAD)
+        val totalMessages = THROUGHPUT_ITERS.toLong
+
+        val benchmark = new Benchmark(
+          "Concurrent RPC Throughput",
+          totalMessages,
+          minNumIters = 3,
+          output = output)
+
+        Seq(1, 4, 8, 16).foreach { numThreads =>
+          benchmark.addTimerCase(s"$numThreads client(s)", numIters = 3) { 
timer =>
+            val messagesPerThread = (totalMessages / numThreads).toInt
+            val latch = new CountDownLatch(numThreads)
+            val clients = createClients(clientFactory, port, numThreads)
+
+            clients.foreach(c => sendRpcSync(c, payload))
+
+            timer.startTiming()
+
+            clients.foreach { client =>
+              val t = new Thread(new Runnable {
+                override def run(): Unit = {
+                  try {
+                    var i = 0
+                    while (i < messagesPerThread) {
+                      sendRpcSync(client, payload)
+                      i += 1
+                    }
+                  } finally {
+                    latch.countDown()
+                  }
+                }
+              })
+              t.setDaemon(true)
+              t.start()
+            }
+
+            latch.await(120, TimeUnit.SECONDS)
+            timer.stopTiming()
+            clients.foreach(_.close())
+          }
+        }
+
+        benchmark.run()
+      }
+    }
+  }
+
+  /**
+   * Suite 3: IOMode Comparison (NIO vs EPOLL/KQUEUE).
+   * Automatically selects the best native transport via 
NettyUtils.createEventLoop
+   * (EPOLL on Linux, KQUEUE on macOS, NIO fallback), so comparing NIO vs 
EPOLL/KQUEUE
+   * shows the benefit of native transport without needing manual probing.
+   * Uses concurrent load (8 clients) to amplify transport-level differences.
+   */
+  private def ioModeComparisonBenchmark(): Unit = {
+    val payload = new Array[Byte](MEDIUM_PAYLOAD)
+    val totalMessages = THROUGHPUT_ITERS.toLong
+    val numClients = 8
+
+    runBenchmark("IOMode Comparison (Concurrent Throughput)") {
+      val benchmark = new Benchmark(
+        "IOMode Comparison",
+        totalMessages,
+        minNumIters = 3,
+        output = output)
+
+      Seq("NIO", detectIOMode()).foreach { mode =>
+        benchmark.addTimerCase(s"$mode ($numClients clients)", numIters = 3) { 
timer =>
+          withTransport(mode) { (clientFactory, port) =>
+            val messagesPerClient = (totalMessages / numClients).toInt
+            val latch = new CountDownLatch(numClients)
+            val clients = createClients(clientFactory, port, numClients)
+
+            clients.foreach(c => sendRpcSync(c, payload))
+
+            timer.startTiming()
+
+            clients.foreach { client =>
+              val t = new Thread(new Runnable {
+                override def run(): Unit = {
+                  try {
+                    var i = 0
+                    while (i < messagesPerClient) {
+                      sendRpcSync(client, payload)
+                      i += 1
+                    }
+                  } finally {
+                    latch.countDown()
+                  }
+                }
+              })
+              t.setDaemon(true)
+              t.start()
+            }
+
+            latch.await(120, TimeUnit.SECONDS)
+            timer.stopTiming()
+            clients.foreach(_.close())
+          }
+        }
+      }
+
+      benchmark.run()
+    }
+  }
+
+  /**
+   * Suite 4: Server thread scaling (2-32 threads) under 16-client load.
+   * Shows whether raising MAX_DEFAULT_NETTY_THREADS=8 helps.
+   */
+  private def serverThreadScalingBenchmark(): Unit = {
+    val ioMode = detectIOMode()
+    val numClients = 16
+    val totalMessages = THROUGHPUT_ITERS.toLong
+    val payload = new Array[Byte](SMALL_PAYLOAD)
+
+    runBenchmark(s"Server Thread Scaling (IOMode=$ioMode, $numClients 
clients)") {
+      val benchmark = new Benchmark(
+        "Server Thread Scaling",
+        totalMessages,
+        minNumIters = 3,
+        output = output)
+
+      Seq(2, 4, 8, 16, 32).foreach { serverThreads =>
+        benchmark.addTimerCase(s"$serverThreads server threads", numIters = 3) 
{ timer =>
+          val conf = createConf(ioMode, serverThreads = serverThreads)
+          withTransport(conf) { (clientFactory, port) =>
+            val messagesPerClient = (totalMessages / numClients).toInt
+            val latch = new CountDownLatch(numClients)
+            val clients = createClients(clientFactory, port, numClients)
+
+            clients.foreach(c => sendRpcSync(c, payload))
+
+            timer.startTiming()
+
+            clients.foreach { client =>
+              val t = new Thread(new Runnable {
+                override def run(): Unit = {
+                  try {
+                    var i = 0
+                    while (i < messagesPerClient) {
+                      sendRpcSync(client, payload)
+                      i += 1
+                    }
+                  } finally {
+                    latch.countDown()
+                  }
+                }
+              })
+              t.setDaemon(true)
+              t.start()
+            }
+
+            latch.await(120, TimeUnit.SECONDS)
+            timer.stopTiming()
+            clients.foreach(_.close())
+          }
+        }
+      }
+
+      benchmark.run()
+    }
+  }
+
+  /**
+   * Suite 5: Multi-connection per peer (1 vs 2 vs 4 connections, 4 sender 
threads).
+   * Uses createUnmanagedClient to ensure genuinely distinct TCP connections.
+   */
+  private def multiConnectionBenchmark(): Unit = {
+    val ioMode = detectIOMode()
+    val payload = new Array[Byte](LARGE_PAYLOAD) // 1MB
+    val numSenderThreads = 4
+    val totalMessages = THROUGHPUT_ITERS / 4
+
+    runBenchmark(s"Multi-Connection Per Peer (IOMode=$ioMode, 1MB payload)") {
+      withTransport(ioMode) { (clientFactory, port) =>
+        val benchmark = new Benchmark(
+          "Multi-Connection Throughput",
+          totalMessages.toLong,
+          minNumIters = 3,
+          output = output)
+
+        Seq(1, 2, 4).foreach { numConns =>
+          benchmark.addTimerCase(
+            s"$numConns conn(s), $numSenderThreads threads",
+            numIters = 3) { timer =>
+            val messagesPerThread = totalMessages / numSenderThreads
+            val clients = createClients(clientFactory, port, numConns)
+            clients.foreach(c => sendRpcSync(c, payload))
+
+            val latch = new CountDownLatch(numSenderThreads)
+
+            timer.startTiming()
+            (0 until numSenderThreads).foreach { idx =>
+              val client = clients(idx % numConns)
+              val t = new Thread(new Runnable {
+                override def run(): Unit = {
+                  try {
+                    var i = 0
+                    while (i < messagesPerThread) {
+                      sendRpcSync(client, payload)
+                      i += 1
+                    }
+                  } finally {
+                    latch.countDown()
+                  }
+                }
+              })
+              t.setDaemon(true)
+              t.start()
+            }
+            latch.await(120, TimeUnit.SECONDS)
+            timer.stopTiming()
+            clients.foreach(_.close())
+          }
+        }
+
+        benchmark.run()
+      }
+    }
+  }
+
+  /**
+   * Suite 6: Async write pressure - fire-and-forget RPCs to saturate the 
write path.
+   * Reports failure count to detect backpressure effects.
+   */
+  private def asyncWritePressureBenchmark(): Unit = {
+    val ioMode = detectIOMode()
+    val asyncBatchSize = 5000
+
+    runBenchmark(s"Async Write Pressure (IOMode=$ioMode)") {
+      withTransport(ioMode) { (clientFactory, port) =>
+        val benchmark = new Benchmark(
+          "Async Write Throughput",
+          asyncBatchSize.toLong,
+          minNumIters = 3,
+          output = output)
+
+        Seq(
+          ("1 KB async burst", SMALL_PAYLOAD),
+          ("64 KB async burst", MEDIUM_PAYLOAD),
+          ("1 MB async burst", LARGE_PAYLOAD)).foreach { case (name, 
payloadSize) =>
+          val payload = new Array[Byte](payloadSize)
+
+          benchmark.addTimerCase(name, numIters = 3) { timer =>
+            val client = clientFactory.createUnmanagedClient("localhost", port)
+            sendRpcSync(client, payload)
+
+            timer.startTiming()
+            val (success, fail) = sendRpcsAsync(client, payload, 
asyncBatchSize)
+            timer.stopTiming()
+
+            if (fail > 0) {
+              // scalastyle:off println
+              println(s"    $name: $success ok, $fail failed (backpressure)")
+              // scalastyle:on println
+            }
+            client.close()
+          }
+        }
+
+        benchmark.run()
+      }
+    }
+  }
+
+  /**
+   * Suite 7: Large block transfer (16MB), sequential and 4-thread parallel.
+   */
+  private def largeBlockTransferBenchmark(): Unit = {
+    val ioMode = detectIOMode()
+    val numBlocks = 100
+
+    runBenchmark(s"Large Block Transfer Throughput (IOMode=$ioMode)") {
+      withTransport(ioMode) { (clientFactory, port) =>
+        val payload = new Array[Byte](XLARGE_PAYLOAD)
+
+        val benchmark = new Benchmark(
+          "16 MB Block Transfer",
+          numBlocks.toLong,
+          minNumIters = 3,
+          output = output)
+
+        benchmark.addTimerCase("Sequential sends", numIters = 3) { timer =>
+          val client = clientFactory.createUnmanagedClient("localhost", port)
+          sendRpcSync(client, payload)
+
+          timer.startTiming()
+          var i = 0
+          while (i < numBlocks) {
+            sendRpcSync(client, payload)
+            i += 1
+          }
+          timer.stopTiming()
+          client.close()
+        }
+
+        benchmark.addTimerCase("4-thread parallel sends", numIters = 3) { 
timer =>
+          val numThreads = 4
+          val blocksPerThread = numBlocks / numThreads
+          val clients = createClients(clientFactory, port, numThreads)
+          clients.foreach(c => sendRpcSync(c, payload))
+
+          timer.startTiming()
+          val latch = new CountDownLatch(numThreads)
+          clients.foreach { c =>
+            val t = new Thread(new Runnable {
+              override def run(): Unit = {
+                try {
+                  var i = 0
+                  while (i < blocksPerThread) {
+                    sendRpcSync(c, payload)
+                    i += 1
+                  }
+                } finally {
+                  latch.countDown()
+                }
+              }
+            })
+            t.setDaemon(true)
+            t.start()
+          }
+          latch.await(120, TimeUnit.SECONDS)
+          timer.stopTiming()
+          clients.foreach(_.close())
+        }
+
+        benchmark.run()
+      }
+    }
+  }
+
+  // ==================== Helpers ====================
+
+  /** Automatically selects EPOLL/KQUEUE, which safely falls back to NIO if 
native .so is unavailable. */
+  private def detectIOMode(): String = CelebornConf.networkIoMode()
+
+  // ==================== Main ====================
+
+  override def runBenchmarkSuite(mainArgs: Array[String]): Unit = {
+    rpcLatencyBenchmark()
+    concurrentThroughputBenchmark()
+    ioModeComparisonBenchmark()
+    serverThreadScalingBenchmark()
+    multiConnectionBenchmark()
+    asyncWritePressureBenchmark()
+    largeBlockTransferBenchmark()
+  }
+}
diff --git a/worker/benchmarks/NettyTransportBenchmark-jdk17-results.txt 
b/worker/benchmarks/NettyTransportBenchmark-jdk17-results.txt
new file mode 100644
index 000000000..9f466d3ce
--- /dev/null
+++ b/worker/benchmarks/NettyTransportBenchmark-jdk17-results.txt
@@ -0,0 +1,14 @@
+================================================================================================
+File-Backed Shuffle Block Fetch (NIO vs EPOLL/KQUEUE, 100x16MB)
+================================================================================================
+
+OpenJDK 64-Bit Server VM 17.0.15+6-LTS on Linux 6.18.7-76061807-generic
+Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
+File-Backed Shuffle Fetch:                Best Time(ms)   Avg Time(ms)   
Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
+------------------------------------------------------------------------------------------------------------------------
+NIO, sequential fetch                             10207          10316         
131          0.0   102070276.3       1.0X
+NIO, parallel fetch (4 clients)                    5310           5320         
  9          0.0    53099106.5       1.9X
+EPOLL, sequential fetch                           10032          10061         
 32          0.0   100317608.1       1.0X
+EPOLL, parallel fetch (4 clients)                  5515           5606         
115          0.0    55150042.8       1.9X
+
+
diff --git a/worker/benchmarks/NettyTransportBenchmark-results.txt 
b/worker/benchmarks/NettyTransportBenchmark-results.txt
new file mode 100644
index 000000000..16488f3f3
--- /dev/null
+++ b/worker/benchmarks/NettyTransportBenchmark-results.txt
@@ -0,0 +1,4 @@
+================================================================================================
+File-Backed Shuffle Block Fetch (NIO vs EPOLL/KQUEUE, 100x16MB)
+================================================================================================
+
diff --git 
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/FetchHandler.scala
 
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/FetchHandler.scala
index ca9138e8f..7ad990e2b 100644
--- 
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/FetchHandler.scala
+++ 
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/FetchHandler.scala
@@ -48,7 +48,7 @@ class FetchHandler(
     val workerSource: WorkerSource)
   extends BaseMessageHandler with Logging {
 
-  val chunkStreamManager = new ChunkStreamManager()
+  val chunkStreamManager = getChunkStreamManager
   val maxChunkBeingTransferred: Option[Long] = 
conf.shuffleIoMaxChunksBeingTransferred
 
   val creditStreamManager = new CreditStreamManager(
@@ -78,6 +78,10 @@ class FetchHandler(
     this.registered = Some(worker.registered)
   }
 
+  def getChunkStreamManager: ChunkStreamManager = {
+    new ChunkStreamManager()
+  }
+
   def getRawFileInfo(
       shuffleKey: String,
       fileName: String): FileInfo = {
diff --git 
a/worker/src/test/scala/org/apache/celeborn/service/deploy/network/NettyTransportBenchmark.scala
 
b/worker/src/test/scala/org/apache/celeborn/service/deploy/network/NettyTransportBenchmark.scala
new file mode 100644
index 000000000..8567e2510
--- /dev/null
+++ 
b/worker/src/test/scala/org/apache/celeborn/service/deploy/network/NettyTransportBenchmark.scala
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.celeborn.service.deploy.network
+
+import java.io.{File, RandomAccessFile}
+import java.util.concurrent.{CountDownLatch, Semaphore, TimeUnit}
+
+import org.apache.celeborn.benchmark.{Benchmark, BenchmarkBase}
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.identity.UserIdentifier
+import org.apache.celeborn.common.meta.DiskFileInfo
+import org.apache.celeborn.common.network.TransportContext
+import org.apache.celeborn.common.network.buffer.{FileChunkBuffers, 
FileSegmentManagedBuffer, ManagedBuffer}
+import org.apache.celeborn.common.network.client.{ChunkReceivedCallback, 
TransportClient, TransportClientFactory}
+import org.apache.celeborn.common.network.server.BaseMessageHandler
+import org.apache.celeborn.common.network.util.TransportConf
+import org.apache.celeborn.common.protocol.TransportModuleConstants
+import org.apache.celeborn.common.util.Utils
+import org.apache.celeborn.service.deploy.worker.{FetchHandler, WorkerSource}
+import org.apache.celeborn.service.deploy.worker.memory.MemoryManager
+import org.apache.celeborn.service.deploy.worker.storage.ChunkStreamManager
+
+/**
+ * Benchmark for Celeborn's Netty transport layer.
+ *
+ * All suites measure performance through the actual Celeborn transport 
pipeline
+ * (TransportServer + TransportClientFactory + TransportContext).
+ *
+ * Suite overview:
+ *   1. File-Backed Shuffle    - ChunkFetch from disk, NIO vs native transport 
(EPOLL sendfile bypass detection)
+ *
+ * {{{
+ *   To run this benchmark:
+ *   1. build/sbt "celeborn-worker/test:runMain <this class>"
+ *   2. generate result:
+ *      CELEBORN_GENERATE_BENCHMARK_FILES=1 build/sbt 
"celeborn-worker/test:runMain <this class>"
+ *      Results will be written to 
"benchmarks/NettyTransportBenchmark-results.txt".
+ * }}}
+ */
+object NettyTransportBenchmark extends BenchmarkBase {
+
+  private def createConf(
+      ioMode: String,
+      serverThreads: Int = 4,
+      clientThreads: Int = 4,
+      extraConf: Map[String, String] = Map.empty): TransportConf = {
+    val celebornConf = new CelebornConf()
+      .set("celeborn.shuffle.io.mode", ioMode)
+      .set("celeborn.shuffle.io.serverThreads", serverThreads.toString)
+      .set("celeborn.shuffle.io.clientThreads", clientThreads.toString)
+    celebornConf.loadFromMap(extraConf, silent = false)
+    new TransportConf("shuffle", celebornConf)
+  }
+
+  /**
+   * Creates N independent (non-pooled) connections to the server.
+   * Uses createUnmanagedClient to bypass TransportClientFactory's connection 
pool,
+   * which defaults to numConnectionsPerPeer=1 and would return the same 
client.
+   */
+  private def createClients(
+      factory: TransportClientFactory,
+      port: Int,
+      count: Int): Seq[TransportClient] = {
+    (0 until count).map(_ => factory.createUnmanagedClient("localhost", port))
+  }
+
+  // ==================== Benchmark Suites ====================
+
+  /**
+   * Suite 1: File-Backed Shuffle Block Fetch via ChunkFetch.
+   *
+   * Writes temp files to disk, serves them as FileSegmentManagedBuffer via 
StreamManager,
+   * and fetches them using client.fetchChunk(). This exercises the 
DefaultFileRegion
+   * zero-copy sendfile/splice path.
+   *
+   * Compares NIO vs EPOLL/KQUEUE to verify that native transports 
(EPOLL/KQUEUE) use sendfile()
+   * for file-backed transfers. EPOLL/KQUEUE should be equal to or faster than 
NIO.
+   */
+  private def fileBackedShuffleBenchmark(): Unit = {
+    val numFiles = 100
+    val fileSize = 16 * 1024 * 1024 // 16 MB per file
+
+    // Create temp shuffle files
+    val tmpDir = new File(System.getProperty("java.io.tmpdir"), 
"celeborn-bench-shuffle")
+    tmpDir.mkdirs()
+    val files = (0 until numFiles).map { idx =>
+      val f = new File(tmpDir, s"shuffle-$idx.data")
+      f.deleteOnExit()
+      val raf = new RandomAccessFile(f, "rw")
+      try {
+        val chunk = new Array[Byte](1024 * 1024)
+        var written = 0
+        while (written < fileSize) {
+          val toWrite = math.min(chunk.length, fileSize - written)
+          raf.write(chunk, 0, toWrite)
+          written += toWrite
+        }
+      } finally {
+        raf.close()
+      }
+      f
+    }
+
+    try {
+      runBenchmark(s"File-Backed Shuffle Block Fetch (NIO vs EPOLL/KQUEUE, 
${numFiles}x16MB)") {
+        val benchmark = new Benchmark(
+          "File-Backed Shuffle Fetch",
+          numFiles.toLong,
+          minNumIters = 3,
+          output = output)
+
+        Seq("NIO", detectIOMode()).foreach { mode =>
+          benchmark.addTimerCase(s"$mode, sequential fetch", numIters = 3) { 
timer =>
+            val conf = createConf(mode)
+            val streamId = 0
+            val memoryManager = MemoryManager.initialize(conf.getCelebornConf)
+            val streamManager = createFileStreamManager(conf, streamId, files)
+            val rpcHandler = createStreamRpcHandler(conf, streamManager)
+            val context = new TransportContext(conf, rpcHandler)
+            val server = context.createServer()
+            val clientFactory = context.createClientFactory()
+            try {
+              val client = clientFactory.createUnmanagedClient("localhost", 
server.getPort)
+              fetchChunksSync(conf, client, streamId, Seq(0))
+
+              timer.startTiming()
+              fetchChunksSync(conf, client, streamId, 0 until numFiles)
+              timer.stopTiming()
+              client.close()
+            } finally {
+              memoryManager.close()
+              clientFactory.close()
+              server.close()
+              context.close()
+            }
+          }
+
+          benchmark.addTimerCase(s"$mode, parallel fetch (4 clients)", 
numIters = 3) { timer =>
+            val conf = createConf(mode)
+            val streamId = 0
+            val memoryManager = MemoryManager.initialize(conf.getCelebornConf)
+            val streamManager = createFileStreamManager(conf, streamId, files)
+            val rpcHandler = createStreamRpcHandler(conf, streamManager)
+            val context = new TransportContext(conf, rpcHandler)
+            val server = context.createServer()
+            val clientFactory = context.createClientFactory()
+            try {
+              val port = server.getPort
+              val numThreads = 4
+              val chunksPerThread = numFiles / numThreads
+              val clients = createClients(clientFactory, port, numThreads)
+              clients.foreach(c =>
+                fetchChunksSync(conf, c, streamId, Seq(0)))
+
+              timer.startTiming()
+              val latch = new CountDownLatch(numThreads)
+              (0 until numThreads).foreach { threadIdx =>
+                val client = clients(threadIdx)
+                val startChunk = threadIdx * chunksPerThread
+                val endChunk = startChunk + chunksPerThread
+                val t = new Thread(new Runnable {
+                  override def run(): Unit = {
+                    try {
+                      fetchChunksSync(
+                        conf,
+                        client,
+                        0,
+                        startChunk until endChunk)
+                    } finally {
+                      latch.countDown()
+                    }
+                  }
+                })
+                t.setDaemon(true)
+                t.start()
+              }
+              latch.await(120, TimeUnit.SECONDS)
+              timer.stopTiming()
+              clients.foreach(_.close())
+            } finally {
+              memoryManager.close()
+              clientFactory.close()
+              server.close()
+              context.close()
+            }
+          }
+        }
+
+        benchmark.run()
+      }
+    } finally {
+      files.foreach(_.delete())
+      tmpDir.delete()
+    }
+  }
+
+  private def createFileStreamManager(
+      conf: TransportConf,
+      streamId: Long,
+      files: Seq[File]): ChunkStreamManager = {
+    val streamManager = new ChunkStreamManager() {
+      override def getChunk(
+          streamId: Long,
+          chunkIndex: Int,
+          offset: Int,
+          len: Int): ManagedBuffer = {
+        new FileSegmentManagedBuffer(conf, files(chunkIndex), 0, 
files(chunkIndex).length())
+      }
+    }
+    val shuffleFile = files.head
+    streamManager.registerStream(
+      streamId,
+      "bench-0",
+      new FileChunkBuffers(
+        new DiskFileInfo(
+          shuffleFile,
+          new UserIdentifier("bench-tenantId", "bench-name"),
+          conf.getCelebornConf),
+        conf),
+      shuffleFile.getName,
+      null)
+    streamManager
+  }
+
+  private def createStreamRpcHandler(
+      conf: TransportConf,
+      streamManager: ChunkStreamManager): BaseMessageHandler = {
+    val celebornConf = conf.getCelebornConf
+    new FetchHandler(
+      celebornConf,
+      Utils.fromCelebornConf(
+        celebornConf,
+        TransportModuleConstants.FETCH_MODULE),
+      new WorkerSource(celebornConf)) {
+      override def getChunkStreamManager: ChunkStreamManager = streamManager
+
+      override def checkRegistered: Boolean = true
+    }
+  }
+
+  // ==================== Helpers ====================
+
+  /** Automatically selects EPOLL/KQUEUE, which safely falls back to NIO if 
native .so is unavailable. */
+  private def detectIOMode(): String = CelebornConf.networkIoMode()
+
+  /**
+   * Fetches chunks synchronously via ChunkFetchRequest and waits for all to 
complete.
+   * The buffer is NOT retained or released here -- TransportResponseHandler 
releases
+   * it after the callback returns.
+   */
+  private def fetchChunksSync(
+      conf: TransportConf,
+      client: TransportClient,
+      streamId: Long,
+      chunkIndices: Seq[Int]): Unit = {
+    val sem = new Semaphore(0)
+    @volatile var error: Throwable = null
+    val callback = new ChunkReceivedCallback {
+      override def onSuccess(chunkIndex: Int, buffer: ManagedBuffer): Unit = {
+        sem.release()
+      }
+      override def onFailure(chunkIndex: Int, e: Throwable): Unit = {
+        error = e
+        sem.release()
+      }
+    }
+    chunkIndices.foreach { idx =>
+      client.fetchChunk(streamId, idx, 
conf.getCelebornConf.clientFetchTimeoutMs, callback)
+    }
+    if (!sem.tryAcquire(chunkIndices.size, 120, TimeUnit.SECONDS)) {
+      throw new RuntimeException("ChunkFetch timed out")
+    }
+    if (error != null) {
+      throw new RuntimeException("ChunkFetch failed", error)
+    }
+  }
+
+  // ==================== Main ====================
+
+  override def runBenchmarkSuite(mainArgs: Array[String]): Unit = {
+    fileBackedShuffleBenchmark()
+  }
+}

Reply via email to