-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize TimeUtil get timestamp logic to optimize performance for Sentinel 1.8.x #2909
base: master
Are you sure you want to change the base?
Conversation
|
感觉有两个问题 |
|
不加volatile是有问题的,根据java内存模型的规定,如果没有volatile,各种jvm的实现可以非常宽松的去实现对共享变量的写入,读取线程可能永远读不到最新的值,而不是“守护线程可在下个周期读取到新值,我们不需要再额外加volatile来保证更实时的可见性” |
目前测试hotspot下是可行的,你那边可测试其他类型的jvm么? |
不用测试,按照java内存模型的约定写代码就行,可以看下JSR133或者《java concurrency in practice》相关章节 |
嗯嗯,加上volatile来保证当然是可行的。但我在想既然sleep也可以在不确定的时机中刷新,且此时需要的是一个模糊值,能否省略掉volatile |
cc @jasonjoo2010 for review |
private static TimeUtil INSTANCE; | ||
|
||
private volatile long currentTimeMillis; | ||
private volatile STATE state = STATE.IDLE; | ||
|
||
private LeapArray<Statistic> statistics; | ||
private long reads = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe volatile
is needed here (to ensure semantics).
Describe what this PR does / why we need it
优化获取时间戳逻辑
Does this pull request fix one issue?
Fixes #2902
Describe how you did it
简化读/写计数器
在频繁获取时间戳的场景中,或许并不需要过于精确的计数器。当前版本的读写计数器是精确累加开销稍大。