Recording with one LMAX thread

I met with LMAX and this great RingBuffer concept. Therefore, the guys say that when writing to ringbuffer with only one stream, performance is much better than with several manufacturers ...

However, I really don't think it is possible for a typical application to use only one stream to write to ringbuffer ... I really don't understand how lmax does this (if they do). For example, N the number of different traders places orders for exchange, these are all asynchronous requests that are transformed into orders and placed in a ringbuffer, how can they write those that use one stream?

Question 1. I may miss something or a misunderstanding of some aspect, but if you have N simultaneous producers, how can you combine them into 1, and not block each other?

Question 2. I remember rxJava observables, where you could take N observables and combine them into 1 using Observable.merge . It is interesting to block or support any lock in any way?

+4
source share
2 answers

The effect on multi-jet recording of RingBuffer is negligible, but can be significant under very heavy loads.

The RingBuffer implementation contains a nextnode where the following addition will be added. If only one stream is written to the ring, the process will always be completed in the shortest time, i.e. buffer[head++] = newData.

, , - while ( !buffer[head++].compareAndSet(null,newValue)){}. , , .

, , getFree .

  // Find the next free element and mark it not free.
  private Node<T> getFree() {
    Node<T> freeNode = head.get();
    int skipped = 0;
    // Stop when we hit the end of the list
    // ... or we successfully transit a node from free to not-free.
    // This is the loop that could cause delays under hight thread activity.
    while (skipped < capacity && !freeNode.free.compareAndSet(true, false)) {
      skipped += 1;
      freeNode = freeNode.next;
    }
    // ...
  }
+2

, RxJava merge , -, synchronized .

, .

, queue-drain, .

JCTools 'MpscArrayQueue, .

+2

All Articles