He-Pin opened a new issue, #3225:
URL: https://github.com/apache/pekko/issues/3225

   ### Motivation
   
   `FlowOps.delay` 的延迟精度硬编码为 10ms(`DelayPrecisionMS = 10`),实际延迟粒度还依赖 
`scheduleOnce` 精度和上游发射时机,可能导致实际延迟与用户配置的 delay 值存在较大偏差。
   
   ### 当前代码行为
   
   `Ops.scala` 中 Delay 阶段实现:
   
   ```scala
   // Ops.scala:2025
   private val DelayPrecisionMS = 10
   
   // Ops.scala:2141
   def nextElementWaitTime(): Long = ...
   ```
   
   当 buffer 非空且下游 pull 时,计算 `waitTime`,仅在 `waitTime <= DelayPrecisionMS` 时立即 
push。10ms 的硬编码精度意味着:
   - 小于 10ms 的 delay 可能无法精确控制
   - 实际精度依赖系统调度器(`scheduleOnce`)的精度
   - 上游发射频率也会影响实际延迟
   
   ### 预期行为
   
   延迟精度应可配置或自适应,至少文档应明确说明精度限制。
   
   ### 代码证据
   
   - 
`stream/src/main/scala/org/apache/pekko/stream/impl/fusing/Ops.scala:2023-2153` 
— Delay 阶段完整实现
   - `stream/src/main/scala/org/apache/pekko/stream/impl/fusing/Ops.scala:2025` 
— `DelayPrecisionMS = 10` 硬编码
   
   ### 复现方式
   
   ```scala
   val start = System.nanoTime()
   Source(List(1, 2, 3))
     .delay(50.millis, DelayOverflowStrategy.backpressure)
     .map { elem =>
       val elapsed = (System.nanoTime() - start) / 1e6
       println(s"$elem at ${elapsed}ms")
       elem
     }
     .runWith(Sink.ignore)
   // 观察实际延迟是否与配置的 50ms 匹配
   ```
   
   ### 影响范围
   
   - 模块:`pekko-stream`
   - 影响需要精确延迟控制的流处理场景
   - 限流、时间窗口等对延迟敏感的使用场景


-- 
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