Coder Social home page Coder Social logo

双Buffer使用问题 about uid-generator HOT 3 OPEN

baidu avatar baidu commented on July 19, 2024
双Buffer使用问题

from uid-generator.

Comments (3)

zhhao1212 avatar zhhao1212 commented on July 19, 2024

当然sequence递增也需要用incrementAndGet()来保证线程安全性

from uid-generator.

wangyunzhong123 avatar wangyunzhong123 commented on July 19, 2024

同问,本身id的生成是纯内存操作,靠移位就可以完成。buffer的意义个人感觉不大,而且put和take的时候做很多异步操作更是对cpu的一种浪费

from uid-generator.

GourdErwa avatar GourdErwa commented on July 19, 2024

在服务器启动时,类BufferPaddingExecutor构造函数对lastSecond进行初始化赋值,之后不再采用系统时间尽心校准,进而避免了时钟回调问题。我不太理解为什么要采用双buffer设计,既然lastSecond是稳定的lastSecond.incrementAndGet()进行递增,在每秒内的sequence(默认seqBits为13)也可以在0和8191间递增,那么此时采用双Buffer的意义是什么呢?

设计上,tail 和 cursor 指针是一直递增的,通过位运算定位 index,但是并发情况下,可能取值时环已经被循环一次了。可以参考
RingBuffer 中的 take 方法 int nextCursorIndex = calSlotIndex(nextCursor); 这一行判断.

from uid-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.