Comments (3)
感谢对uid-generator项目的关注,很高兴一起交流探讨
请问为什么不像flags一样地去使用PaddedAtomicLong进行补齐
CPU Cache line是把双刃剑
-
好处:可充分利用CPU缓存提升性能。
RingBuffer.slots
环填充的为UID,会频繁的被读取。所以为了提升获取UID的性能,未采用内存补齐,这样cache line中可放置更多的UID。 -
隐患:伪共享问题。对于
RingBuffer.take()
操作,会频繁更新RingBuffer.cursor
、RingBuffer.flags
,对写操作采用内存补齐的方式,可避免伪共享的隐患,又不影响读取性能。
RingBuffer#put,并通过线程池间接调用了该方法,多线程间对slots进行写操作
这里采用多线程读RingBuffer.take()
,需要保证读的吞吐量;
串行写RingBuffer.put()
,同一时刻只要有一个线程写即可,同时写操作采用synchronized
串行化
另外,对于RingBuffer.put()
有两种触发机制:
- 实时写,环上可用UID达到一定阈值(默认50%)时,实时填满Ringbuffer(默认开启)
- 定时写,基于定时周期填满(可选开启)
填充动作BufferPaddingExecutor.paddingBuffer()
,均通过线程池异步执行,由BufferPaddingExecutor.running
保证同一时刻只有一个填充任务被执行
from uid-generator.
十分感谢贡献者在百忙之中能抽出时间进行解答。
多线程间对slots进行写操作在多核处理器下应该也会使得该数组发生伪共享问题
这里的本意其实是
即使是不同线程间对slots进行串行写操作在多核处理器下应该也会使得该数组发生伪共享问题,因为Java线程在目前来说并不能绑定CPU,所以在修改相同的Cache Line的时候,是有十分可能产生RFO信号的
由于本人的纰漏让作者您产生了歧义表示十分的抱歉。但是解决了鄙人对该变量的类型设定的问题 -- 提高获取UID的性能。
再次感谢贡献者对本issue的耐心回答。
from uid-generator.
slot只在put方法中被更新,而且put方法是单线程异步访问,后台线程对性能要求不高,没必要使用PaddedAtomicLong。
slot在take方法只是被读取,不使用PaddedAtomicLong,可以加载更多数据到cacheline,提高访问性能。
我是这么理解的
from uid-generator.
Related Issues (20)
- There is a vulnerability in spring 4.2.5.RELEASE,upgrade recommended
- There is a vulnerability in logback 1.1.3,upgrade recommended
- Synchronized DefaultUidGenerator & ParallelGenerate
- 压测的具体操作方法能麻烦提供一下
- 64位虚机里 CacheLine 填充过长问题 HOT 1
- 中文文档里的sql建表语句执行报错 时间字段需要设置默认值 HOT 1
- 总共没几条sql,建议直接使用jdbc,不要在使用mybatis等框架 HOT 2
- 控制台日志频繁打印 HOT 1
- 请问该项目是不再维护了吗
- A component required a bean of type 'com.github.wujun234.uid.impl.CachedUidGenerator' that could not be found. HOT 1
- 为啥不把delta seconds和worker id换个位置? HOT 1
- AtomicLong.updateAndGet()超级费CPU,并发一多就100% HOT 1
- 这个吞吐量怎么算出来的?
- BufferPaddingExecutor中的lastSecond的疑问
- 报错 UidGenerateExption :java.RuntimeExecption :Rejected take buffer . RingBuffer [bufferize=65536,tail=65536,cursor=65536,paddingThreshold=32768] HOT 5
- 机器 id,最多可支持约 420w 次机器启动 HOT 2
- 时间戳运算代码是不是写错了 HOT 1
- 有没有升级为springboot版的 HOT 1
- No qualifying bean of type 'com.github.wujun234.uid.UidGenerator' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@jakarta.annotation.Resource(shareable=true, lookup="", name="", description="", authenticationType=CONTAINER, type=java.lang.Object.class, mappedName="")}
- 什么时候出个go语言版本的
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uid-generator.