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

zaynt4606 pushed a commit to branch branch-0.7
in repository https://gitbox.apache.org/repos/asf/celeborn.git


The following commit(s) were added to refs/heads/branch-0.7 by this push:
     new 0e22dcf0d1 [CELEBORN-2545] Count memory and DFS pushes in worker 
congestion control
0e22dcf0d1 is described below

commit 0e22dcf0d1f1dbcea3c8b58cd6fa401861c15b74
Author: ForVic <[email protected]>
AuthorDate: Sat Nov 14 18:22:23 2026 +0800

    [CELEBORN-2545] Count memory and DFS pushes in worker congestion control
    
    ### What changes were proposed in this pull request?
    
    Congestion control slows down users who push data too fast. To decide who 
is too fast, it counts the bytes each user pushes.
    
    Right now only the **local disk** writer counts those bytes. Data written 
to a **memory file** or to **HDFS / S3 / OSS** is never counted.
    
    This PR moves the counting into `TierWriterBase.write`, which every storage 
tier goes through. The count runs after the existing "writer closed / flush 
failed" checks, so data that gets dropped is still not counted.
    
    | Data written to  | Counted before | Counted after |
    |------------------|:--------------:|:-------------:|
    | Local disk       | yes            | yes           |
    | Memory file      | **no**         | yes           |
    | HDFS / S3 / OSS  | **no**         | yes           |
    
    ### Why are the changes needed?
    
    When bytes are missing from the count:
    
    - A user whose data goes to memory or HDFS/S3/OSS shows **0** in 
`UserProduceSpeed` and is never slowed down, however hard they push.
    - The worker's total push speed is too low too, so the worker-wide speed 
limit (`workerProduceSpeed.high.watermark`) starts later than configured. On a 
worker that only writes to HDFS/S3/OSS, it never starts.
    
    Moving a memory file to disk hands over the same buffer without calling 
`write` again, so those bytes are not counted twice.
    
    **Evidence.** The new test in `TierWriterSuite` pushes data to each tier 
and checks the counter after every step: 81 KiB to memory, then the memory file 
moves to disk, then 1 KiB to local disk, then 1 KiB to HDFS.
    
    Without this fix, the very first check fails because the memory pushes were 
never counted:
    
    ```
    - every storage tier reports pushed bytes to congestion control *** FAILED 
***
      0 did not equal 82944 (TierWriterSuite.scala:765)
    ```
    
    With the fix, the counter reads 81 KiB → still 81 KiB after the move to 
disk → 82 KiB → 83 KiB, and the test passes.
    
    ### Does this PR resolve a correctness bug?
    
    - [ ] Yes
    
    ### Does this PR introduce _any_ user-facing change?
    
    - [x] Yes
    
    Only when congestion control is on 
(`celeborn.worker.congestionControl.enabled`, off by default). Users writing to 
memory or HDFS/S3/OSS can now be slowed down like local-disk users already are. 
`UserProduceSpeed` and the worker's push speed now include their data. No 
config changes.
    
    ### How was this patch tested?
    
    - New test: `TierWriterSuite` "every storage tier reports pushed bytes to 
congestion control". Fails without the fix, passes with it.
    - Existing tests, all passing: `TierWriterSuite` (16), 
`TestCongestionController` (7), `DiskReducePartitionDataWriterSuiteJ`, 
`DiskMapPartitionDataWriterSuiteJ`, `MemoryReducePartitionDataWriterSuiteJ`, 
`SSLReducePartitionDataWriterSuiteJ` (23 total).
    - `spotless:check` passes.
    
    Closes #3959 from ForVic/ForVic/congestion-count-all-tiers.
    
    Authored-by: ForVic <[email protected]>
    Signed-off-by: zhengtao <[email protected]>
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    (cherry picked from commit 9ffb6f7d3798e4fb604ffe1bbfcc9f279aa192e7)
    Signed-off-by: zhengtao <[email protected]>
    Co-Authored-By: Codex <[email protected]>
    AI-Model: gpt-6
    AI-Contributed/Feature: 0/31
    AI-Contributed/UT: 0/46
---
 .../service/deploy/worker/storage/TierWriter.scala | 31 +++++++++------
 .../deploy/worker/storage/TierWriterSuite.scala    | 46 ++++++++++++++++++++++
 2 files changed, 65 insertions(+), 12 deletions(-)

diff --git 
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/storage/TierWriter.scala
 
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/storage/TierWriter.scala
index 1284013587..a3519b3196 100644
--- 
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/storage/TierWriter.scala
+++ 
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/storage/TierWriter.scala
@@ -31,6 +31,7 @@ import org.apache.hadoop.fs.{FileSystem, FSDataOutputStream}
 
 import org.apache.celeborn.common.CelebornConf
 import org.apache.celeborn.common.exception.AlreadyClosedException
+import org.apache.celeborn.common.identity.UserIdentifier
 import org.apache.celeborn.common.internal.Logging
 import org.apache.celeborn.common.meta.{DiskFileInfo, FileInfo, MemoryFileInfo}
 import org.apache.celeborn.common.metrics.source.AbstractSource
@@ -53,7 +54,8 @@ abstract class TierWriterBase(
     val storageType: StorageInfo.Type,
     val filename: String,
     val shuffleKey: String,
-    val storageManager: StorageManager) extends Logging {
+    val storageManager: StorageManager,
+    userIdentifier: UserIdentifier) extends Logging {
   val metricsCollectCriticalEnabled: Boolean = 
conf.metricsCollectCriticalEnabled
   private val WAIT_INTERVAL_MS = 5
 
@@ -67,6 +69,14 @@ abstract class TierWriterBase(
   @volatile private var destroyed: Boolean = false
   @volatile var committed: Boolean = false
 
+  // Every tier reports its pushed bytes here so congestion control sees all 
incoming data,
+  // whether it lands in memory, on local disk, or in HDFS/S3/OSS.
+  private val userCongestionControlContext: UserCongestionControlContext =
+    if (CongestionController.instance != null)
+      CongestionController.instance.getUserCongestionContext(userIdentifier)
+    else
+      null
+
   takeBuffer()
 
   def write(buf: ByteBuf): Unit = {
@@ -79,6 +89,8 @@ abstract class TierWriterBase(
     flushLock.synchronized {
       metaHandler.beforeWrite(buf)
       ensureNotClosed()
+      if (userCongestionControlContext != null)
+        userCongestionControlContext.updateProduceBytes(buf.readableBytes())
       writeInternal(buf)
     }
 
@@ -322,7 +334,8 @@ class MemoryTierWriter(
     storageType,
     partitionDataWriterContext.getPartitionLocation.getFileName,
     partitionDataWriterContext.getShuffleKey,
-    storageManager) {
+    storageManager,
+    partitionDataWriterContext.getUserIdentifier) {
   assert(storageType == StorageInfo.Type.MEMORY)
   val memoryFileStorageMaxFileSize: Long = 
conf.workerMemoryFileStorageMaxFileSize
 
@@ -427,16 +440,11 @@ class LocalTierWriter(
     storageType,
     partitionDataWriterContext.getPartitionLocation.getFileName,
     partitionDataWriterContext.getShuffleKey,
-    storageManager) {
+    storageManager,
+    partitionDataWriterContext.getUserIdentifier) {
   assert(storageType == StorageInfo.Type.HDD || storageType == 
StorageInfo.Type.SSD)
   flusherBufferSize = conf.workerFlusherBufferSize
   private val flushWorkerIndex: Int = flusher.getWorkerIndex
-  val userCongestionControlContext: UserCongestionControlContext =
-    if (CongestionController.instance != null)
-      CongestionController.instance.getUserCongestionContext(
-        partitionDataWriterContext.getUserIdentifier)
-    else
-      null
   storageManager.registerDiskFilePartitionWriter(
     partitionDataWriterContext.getPartitionDataWriter,
     partitionDataWriterContext.getWorkingDir,
@@ -459,8 +467,6 @@ class LocalTierWriter(
 
   override def writeInternal(buf: ByteBuf): Unit = {
     val numBytes = buf.readableBytes()
-    if (userCongestionControlContext != null)
-      userCongestionControlContext.updateProduceBytes(numBytes)
     val flushBufferReadableBytes = flushBuffer.readableBytes
     if (flushBufferReadableBytes != 0 && flushBufferReadableBytes + numBytes 
>= flusherBufferSize) {
       flush(false)
@@ -559,7 +565,8 @@ class DfsTierWriter(
     storageType,
     partitionDataWriterContext.getPartitionLocation.getFileName,
     partitionDataWriterContext.getShuffleKey,
-    storageManager) {
+    storageManager,
+    partitionDataWriterContext.getUserIdentifier) {
   assert(
     storageType == StorageInfo.Type.HDFS || storageType == 
StorageInfo.Type.OSS || storageType == StorageInfo.Type.S3)
   flusherBufferSize = conf.workerHdfsFlusherBufferSize
diff --git 
a/worker/src/test/scala/org/apache/celeborn/service/deploy/worker/storage/TierWriterSuite.scala
 
b/worker/src/test/scala/org/apache/celeborn/service/deploy/worker/storage/TierWriterSuite.scala
index cb57960677..fa11aee4b2 100644
--- 
a/worker/src/test/scala/org/apache/celeborn/service/deploy/worker/storage/TierWriterSuite.scala
+++ 
b/worker/src/test/scala/org/apache/celeborn/service/deploy/worker/storage/TierWriterSuite.scala
@@ -42,6 +42,7 @@ import org.apache.celeborn.common.network.util.{NettyUtils, 
TransportConf}
 import org.apache.celeborn.common.protocol.{PartitionLocation, 
PartitionSplitMode, PartitionType, StorageInfo}
 import org.apache.celeborn.common.util.Utils
 import org.apache.celeborn.service.deploy.worker.WorkerSource
+import 
org.apache.celeborn.service.deploy.worker.congestcontrol.CongestionController
 import org.apache.celeborn.service.deploy.worker.memory.MemoryManager
 
 class TierWriterSuite extends AnyFunSuite with BeforeAndAfterAll with 
BeforeAndAfterEach {
@@ -740,4 +741,49 @@ class TierWriterSuite extends AnyFunSuite with 
BeforeAndAfterAll with BeforeAndA
       assert(fs.exists(fileInfo.getDfsIndexPath))
     }
   }
+
+  test("every storage tier reports pushed bytes to congestion control") {
+    val conf = new CelebornConf()
+    val congestionController =
+      CongestionController.initialize(new WorkerSource(conf), 60, conf, null)
+    try {
+      val user = UserIdentifier("`aa`.`bb`")
+      def userBytes: Long =
+        
congestionController.getUserBuffer(user).getBufferStatusHub.sum().getKey.numBytes()
+      def workerBytes: Long =
+        congestionController.getProducedBufferStatusHub.sum().getKey.numBytes()
+      def push(writer: TierWriterBase): Unit = {
+        val buf = 
WriterUtils.generateSparkFormatData(UnpooledByteBufAllocator.DEFAULT, 0)
+        writer.numPendingWrites.incrementAndGet()
+        writer.write(buf)
+        buf.release()
+      }
+
+      // Memory tier: 81 pushes of 1 KiB.
+      val memoryTierWriter = prepareMemoryWriter
+      (1 to 81).foreach(_ => push(memoryTierWriter))
+      assert(userBytes === 81 * 1024)
+      assert(workerBytes === 81 * 1024)
+
+      // Moving the memory file to disk must not count the same bytes again.
+      val localTierWriter = prepareLocalTierWriter(false)
+      assert(memoryTierWriter.needEvict())
+      memoryTierWriter.evict(localTierWriter)
+      assert(userBytes === 81 * 1024)
+
+      // Local disk tier: one more push.
+      push(localTierWriter)
+      assert(userBytes === 82 * 1024)
+      localTierWriter.close()
+
+      // DFS tier (HDFS/S3/OSS): the helper pushes 1 KiB.
+      withDfsTierWriter() { (dfsTierWriter, _, _) =>
+        assert(userBytes === 83 * 1024)
+        assert(workerBytes === 83 * 1024)
+        dfsTierWriter.close()
+      }
+    } finally {
+      CongestionController.destroy()
+    }
+  }
 }

Reply via email to