rocketmq
rocketmq copied to clipboard
把循环index的类型由long改为int,让循环前放置Safepoint,效果会不会比Thread.sleep(0)更好?
如题
MappedFile 类,507~527行这个循环,把循环的i、j改成long类型。删除掉522行的Thread.sleep(0)。
这么改,关于gc方面的优化,效果会不会更好?代码看着也会更加优雅
虽然是sleep 0,但因操作系统时钟精度原因,实际会sleep 几毫秒,不同的系统,精度可能值会不一样; 删除之后,就没有sleep的效果了;
虽然是sleep 0,但因操作系统时钟精度原因,实际会sleep 几毫秒,不同的系统,精度可能值会不一样; 删除之后,就没有sleep的效果了;
@fuyou001 请问为什么要有sleep的效果呢?没有sleep的效果不是更好吗? 另外还有的问题是,如果追求sleep的效果,sleep(0)有没有可能被jit优化啊?
@foxeatsspicy can you make a test code ?
@foxeatsspicy can you make a test code ?
@francisoliverlee the person doesn't seem to exist,page is 404
safepoint,安全点。
虽然是sleep 0,但因操作系统时钟精度原因,实际会sleep 几毫秒,不同的系统,精度可能值会不一样; 删除之后,就没有sleep的效果了;
@fuyou001
No. It is not true. The intention of sleep(0) is to introduce safe points. When there is an ongoing GC, this thread will take fewer milliseconds to reach a safe point. This would be helpful if the available memory runs low. See https://stackoverflow.com/questions/67232199/how-to-reduce-time-taken-on-threads-reaching-safepoint-sync-state
@duhenglucky The pull request is not completed yet. Need more insights involved.
continuing to pay attention
虽然是sleep 0,但因操作系统时钟精度原因,实际会sleep 几毫秒,不同的系统,精度可能值会不一样; 删除之后,就没有sleep的效果了;
@fuyou001
No. It is not true. The intention of sleep(0) is to introduce safe points. When there is an ongoing GC, this thread will take fewer milliseconds to reach a safe point. This would be helpful if the available memory runs low. See https://stackoverflow.com/questions/67232199/how-to-reduce-time-taken-on-threads-reaching-safepoint-sync-state
Maybe Thread.yield()
is more clear for the usage?
实际上,这里的改动无效:for循环里有方法调用,就不存在这个问题。方法调用栈退出的地方,是可以加check safepoint的。
for循环退不出的场景,也可以通过-XX:+UseCountedLoopSafepoints解决,不需要改代码。 @lizhanhui