zrlw opened a new issue #8949:
URL: https://github.com/apache/dubbo/issues/8949


   ### Environment
   
   * Dubbo version: 3.0 / master
   1. waitForNextTick想法有点多
   ```
                   final long currentTime = System.nanoTime() - startTime; <== 
startTime是初始化HashedWheelTimer的时间,currentTime是时间差,应用程序持续运行时间只要不超过292年,currentTime这个值都不会小于0。即使System.nanoTime()返回的当前时间超过LONG最大值变成了负数,它和startTime之间的纳秒时间差只要不超过2^63次方-1,currentTime就不会变成负值。
                   long sleepTimeMs = (deadline - currentTime + 999999) / 
1000000;
   
                   if (sleepTimeMs <= 0) {
                       if (currentTime == Long.MIN_VALUE) {  
                           <==  
Long.MIN_VALUE是-2^63,程序要持续运行262年之后才有遇到它的机会;返回负值也有问题,调用waitForNextTick的代码只认返回值大于0的情况。
                           return -Long.MAX_VALUE;  
                       } else {
                           return currentTime;
                       }
                   }
   ```
   2. 
HashedWheelTimer的maxPendingTimeouts可以任意设置,但实际情况是超过cpu核数时,超时机制就会混乱起来,原因是sleep的线程太多了,sleep时间到了也抢不到cpu。
 
   HashedWheelTimerTest的createTaskTest测试方法在4核windows机器上跑单元测试,多半失败:
   ```
           Thread.sleep(100); 《== 
实测发现执行expireTimeouts的线程很少能在1秒内抢到cpu,所以这里的100ms是想当然了
           Assertions.assertTrue(timeout.isExpired());
   
           timer.stop();
   ```


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