Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:46:20+00:00 2026-06-14T06:46:20+00:00

In this example https://stackoverflow.com/a/9980346/93647 and here Why is my disruptor example so slow? (at

  • 0

In this example https://stackoverflow.com/a/9980346/93647 and here Why is my disruptor example so slow? (at the end of the question) there is 1 publisher which publish items and 1 consumer.

But in my case consumer work is much more complicated and takes some time. So I want 4 consumers that process data in parallel.

So for example if producer produce numbers: 1,2,3,4,5,6,7,8,9,10,11..

I want consumer1 to catch 1,5,9,… consumer2 to catch 2,6,10,… consumer3 to catch 3,7,11,… consumer4 to catch 4,8,12… (well not exactly these numbers, the idea is that data should be processed in parallel, i don’t care which certain number is processed on which consumer)

And remember this need to be done parallel because in real application consumer work is pretty expensive. I expect consumers to be executed in different threads to use power of multicore systems.

Of course I can just create 4 ringbuffers and attach 1 consumer to 1 ring-buffer. This way I can use original example. But I feel it wouldn’t be correct. Likely it would be correct to create 1 publisher (1 ringbuffer) and 4 consumers – as this is what i need.

Adding link to a very simular question in google groups: https://groups.google.com/forum/#!msg/lmax-disruptor/-CLapWuwWLU/GHEP4UkxrAEJ

So we have two options:

  • one ring many consumers (each consumer will “wake-up” on every addition, all consumer should have the same WaitStrategy)
  • many “one ring – one consumer” (each consumer will wake-up only on data that it should process. each consumer can have own WaitStrategy).
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:46:23+00:00Added an answer on June 14, 2026 at 6:46 am

    EDIT: I forgot to mention the code is partially taken from the FAQ. I have no idea if this approach is better or worse than Frank’s suggestion.

    The project is severely under documented, that’s a shame as it looks nice.
    Anyway try the following snip (based on your first link) – tested on mono and seems to be OK:

    using System;
    using System.Threading.Tasks;
    using Disruptor;
    using Disruptor.Dsl;
    
    namespace DisruptorTest
    {
        public sealed class ValueEntry
        {
            public long Value { get; set; }
        }
    
        public class MyHandler : IEventHandler<ValueEntry>
        {
            private static int _consumers = 0;
            private readonly int _ordinal;
    
            public MyHandler()
            {
                this._ordinal = _consumers++;
            }
    
            public void OnNext(ValueEntry data, long sequence, bool endOfBatch)
            {
                if ((sequence % _consumers) == _ordinal)
                    Console.WriteLine("Event handled: Value = {0}, event {1} processed by {2}", data.Value, sequence, _ordinal);
                else
                    Console.WriteLine("Event {0} rejected by {1}", sequence, _ordinal);                     
            }
        }
    
        class Program
        {
            private static readonly Random _random = new Random();
            private const int SIZE = 16;  // Must be multiple of 2
            private const int WORKERS = 4; 
    
            static void Main()
            {
                var disruptor = new Disruptor.Dsl.Disruptor<ValueEntry>(() => new ValueEntry(), SIZE, TaskScheduler.Default);
                for (int i=0; i < WORKERS; i++)
                    disruptor.HandleEventsWith(new MyHandler());
                var ringBuffer = disruptor.Start();
    
                while (true)
                {
                    long sequenceNo = ringBuffer.Next();
                    ringBuffer[sequenceNo].Value =  _random.Next();;
                    ringBuffer.Publish(sequenceNo);
                    Console.WriteLine("Published entry {0}, value {1}", sequenceNo, ringBuffer[sequenceNo].Value);
                    Console.ReadKey();
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example form, https://stackoverflow.com/questions/ask and I save this page to desktop. Then I edit the
See, for example, here https://stackoverflow.com/questions/139299/difference-between-dependency-injection-di-inversion-of-control-ioc to remind yourself what IoC and DI are. The
This question is related to this one: https://stackoverflow.com/questions/7906356/how-to-solve-a-a-reference-tracked-object-changed-reference-during-deserializat Since the above post has been
this is how insert into, select is usually working (example taken from: https://stackoverflow.com/a/576442/101055 ):
Given this answer: https://stackoverflow.com/a/4263048 Which is excellent, how can we be sure that out
I was studying the visitor pattern and came across this useful example: https://stackoverflow.com/a/2604798/974594 .
This is a follow-up to what I was trying to accomplish here https://stackoverflow.com/questions/7313922/uploading-files-ussing-myfaces-tomahawk-jsf-2-0 I've
This is a slightly modified example from the Java Sound info page. https://stackoverflow.com/tags/javasound/info Unfortunately,
I'm trying to deploy WAR like in this example https://stackoverflow.com/a/4144674/758661 DeployTask task = new
I have something very similar to this example: https://developers.google.com/maps/documentation/javascript/examples/directions-simple All I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.