How to decide ring buffer size based upon L3 cache size?

693 views
Skip to first unread message

piyush tiwari

unread,
Jun 1, 2015, 3:12:38 PM6/1/15
to lmax-di...@googlegroups.com
Hi,

I want to know If we can derive the ring buffer size based upon the L3 cache available. I've a system that undergone L3 cache upgrade and now have 25 MB of L3 cache available.

Now I want to upgrade the ring buffer size as well. 
  • L3 cache: 25 MB
  • Ring Buffer Size:  ?
Could anyone please have a look and suggest?

P.S. : Earlier we had 15 MB of L3 cache and ring buffer size set to 1024. 

Looking forward for a response :-)


Michael Barker

unread,
Jun 1, 2015, 7:24:10 PM6/1/15
to lmax-di...@googlegroups.com
Hi Piyush,

Unfortunately I don't think that there is any useful math I can give you to that you that would allow you to set your ring buffer size.  There are too many external factors at play, such as message size and working set size of your business logic.

In a general sense smaller is better as it will improve the temporal locality of the message data and will leave more of the L3 available for other processing.  However, the buffer size should be sufficiently large, such that if there a burst of activity, the producer won't run into a full ring buffer while it waits for the consumer(s) to process the backlog of messages.  So unless you need to be able to deal with larger bursts or are running into cases where the publisher thread is blocking, I wouldn't change the size of the ring buffer.  Larger doesn't necessarily mean faster.

At LMAX we use the ring buffer as a recovery window, so the key requirement for the sizing of our buffers is based on how big we want our recovery window to be.

Mike.

--
You received this message because you are subscribed to the Google Groups "Disruptor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmax-disrupto...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Narges

unread,
Apr 9, 2018, 8:36:29 AM4/9/18
to Disruptor
Hi,

1. Do you mean that RingBuffer size should be at most equals to L3 cache size?
2. If we know the number of events, for example we have 1 million messages, then can we say that we need just 1048576 entries in our RingBuffer? Or is this better - in performance - to allocate space as much as possible for that?
3. Having Larger RingBuffer always improve performance? Or it is just for the case of burst of activity?

Narges.

Michael Barker

unread,
Apr 19, 2018, 2:53:23 AM4/19/18
to lmax-di...@googlegroups.com
1. Do you mean that RingBuffer size should be at most equals to L3 cache size?

No, not necessarily.  But generally less is better.
 
2. If we know the number of events, for example we have 1 million messages, then can we say that we need just 1048576 entries in our RingBuffer? Or is this better - in performance - to allocate space as much as possible for that?

Most of these types of questions can't really be answered generally.  You need to try different sizes while profiling the application. 
 
3. Having Larger RingBuffer always improve performance? Or it is just for the case of burst of activity?

Larger is generally worse.  The less memory you use the more cache is available for parts of the code.  The buffer size should be large enough to cover bursts.

Mike.
Reply all
Reply to author
Forward
0 new messages