-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
RingBuffer内slots数组的补齐问题 #4
Comments
感谢对uid-generator项目的关注,很高兴一起交流探讨
CPU Cache line是把双刃剑
这里采用多线程读 另外,对于
填充动作 |
十分感谢贡献者在百忙之中能抽出时间进行解答。
这里的本意其实是
由于本人的纰漏让作者您产生了歧义表示十分的抱歉。但是解决了鄙人对该变量的类型设定的问题 -- 提高获取UID的性能。 再次感谢贡献者对本issue的耐心回答。 |
slot只在put方法中被更新,而且put方法是单线程异步访问,后台线程对性能要求不高,没必要使用PaddedAtomicLong。 |
感谢百度开源了本项目,鄙人在研读源码的时候有点疑惑,希望能得到各位前辈的指点。
在
RingBuffer
内有两个环形数组,一个名为slots作用为存储UID,另一个名为flags用于存储标志位。具体引用代码如下
https://github.com/baidu/uid-generator/blob/master/src/main/java/com/baidu/fsg/uid/buffer/RingBuffer.java#L51-L52
slots中的元素唯一被填充的填充的地方是
com.baidu.fsg.uid.buffer.RingBuffer#put
,并通过线程池间接调用了该方法,多线程间对slots进行写操作在多核处理器下应该也会使得该数组发生伪共享问题,请问为什么不像flags一样地去使用PaddedAtomicLong进行补齐,或者是我对伪共享有错误的理解,望不吝赐教!The text was updated successfully, but these errors were encountered: