Solution to slow consumer(eventProcessor) issue in LMAX Disruptor pattern

后端 未结 3 589
谎友^
谎友^ 2020-12-30 14:28

While using the disruptor, there may be a consumer(s) that is lagging behind, and because of that slow consumer, the whole application is affected.

Keeping in mind

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 14:53

    Use a set of identical eventHandlers. To avoid more than 1 eventHandler acting upon a single event, I use the following approach.

    Create a thread pool of size Number of cores in the system

    Executor executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); // a thread pool to which we can assign tasks
    

    Then create a handler array

     HttpEventHandler [] handlers = new HttpEventHandler[Runtime.getRuntime().availableProcessors()];
    
    for(int i = 0; i

    In the EventHandler

    public void onEvent(HttpEvent event, long sequence, boolean endOfBatch) throws InterruptedException
    {
        if( sequence % Runtime.getRuntime().availableProcessors()==id){
    
            System.out.println("-----On event Triggered on thread "+Thread.currentThread().getName()+" on sequence "+sequence+" -----");
            //your event handler logic
    }
    

提交回复
热议问题