Hello, hello, I am Dabai (●—●)
table of Contents
High-performance queue DISruptor
Traditional queue problem:
1. Through locking to ensure thread safety, there are performance problems
2. ArrayBlockingQueue has false sharing problems
The principle of high performance of Disruptor
1. Introduced a circular array structure, the array will not be recycled, which means that there will be no frequent GC.
2. The elements are operated in CAS lock-free mode to avoid locking and ensure thread safety.
For traditional queues, pseudo For sharing issues, cache lines are also true for arrays. When the CPU is reading the circular array, it will
read multiple elements into one cache line at one time to speed up the access speed.
High-speed positioning in an array: the size of the array is defined as the n-th power of 2, and there is a pointer (Sequence) in the array that is a volatile variable
. Avoid pseudo-sharing when implementing it, and fill in meaningless data before and after the Sequence.
Dabai (●—●) accompany you to make progress together!