|
|
|
@ -1,7 +1,7 @@ |
|
|
|
package com.techsor.datacenter.sender.config; |
|
|
|
|
|
|
|
import com.lmax.disruptor.BlockingWaitStrategy; |
|
|
|
import com.lmax.disruptor.RingBuffer; |
|
|
|
import com.lmax.disruptor.SleepingWaitStrategy; |
|
|
|
import com.lmax.disruptor.dsl.Disruptor; |
|
|
|
import com.lmax.disruptor.dsl.ProducerType; |
|
|
|
import com.techsor.datacenter.sender.dao.DashboardAlertDao; |
|
|
|
@ -11,7 +11,7 @@ import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.concurrent.ThreadFactory; |
|
|
|
|
|
|
|
@Configuration |
|
|
|
public class DisruptorConfig { |
|
|
|
@ -19,22 +19,30 @@ public class DisruptorConfig { |
|
|
|
@Value("${data.operation.batch-size:100}") |
|
|
|
private int batchSize; |
|
|
|
|
|
|
|
/** 创建带线程名的 ThreadFactory **/ |
|
|
|
private ThreadFactory createDisruptorThreadFactory(String namePrefix) { |
|
|
|
return r -> { |
|
|
|
Thread t = new Thread(r); |
|
|
|
t.setName(namePrefix + "-" + t.getId()); |
|
|
|
t.setDaemon(true); |
|
|
|
return t; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
@Bean |
|
|
|
public Disruptor<MeasureEvent> measureDisruptor(DashboardStatisticsDao dao) { |
|
|
|
|
|
|
|
int ringSize = 1024; |
|
|
|
int ringSize = 32768; |
|
|
|
|
|
|
|
Disruptor<MeasureEvent> disruptor = new Disruptor<>( |
|
|
|
new MeasureEventFactory(), |
|
|
|
ringSize, |
|
|
|
Executors.defaultThreadFactory(), |
|
|
|
createDisruptorThreadFactory("measure-disruptor"), |
|
|
|
ProducerType.MULTI, |
|
|
|
new BlockingWaitStrategy() |
|
|
|
new SleepingWaitStrategy() |
|
|
|
); |
|
|
|
|
|
|
|
disruptor.handleEventsWith(new MeasureEventHandler(dao, batchSize)); |
|
|
|
disruptor.start(); |
|
|
|
|
|
|
|
return disruptor; |
|
|
|
} |
|
|
|
|
|
|
|
@ -43,22 +51,21 @@ public class DisruptorConfig { |
|
|
|
return disruptor.getRingBuffer(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
public Disruptor<AccumulateEvent> accumulateDisruptor(DashboardStatisticsDao dao) { |
|
|
|
|
|
|
|
int ringSize = 1024; |
|
|
|
int ringSize = 32768; |
|
|
|
|
|
|
|
Disruptor<AccumulateEvent> disruptor = new Disruptor<>( |
|
|
|
new AccumulateEventFactory(), |
|
|
|
ringSize, |
|
|
|
Executors.defaultThreadFactory(), |
|
|
|
createDisruptorThreadFactory("accumulate-disruptor"), |
|
|
|
ProducerType.MULTI, |
|
|
|
new BlockingWaitStrategy() |
|
|
|
new SleepingWaitStrategy() |
|
|
|
); |
|
|
|
|
|
|
|
disruptor.handleEventsWith(new AccumulateEventHandler(dao, batchSize)); |
|
|
|
disruptor.start(); |
|
|
|
|
|
|
|
return disruptor; |
|
|
|
} |
|
|
|
|
|
|
|
@ -67,22 +74,21 @@ public class DisruptorConfig { |
|
|
|
return disruptor.getRingBuffer(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
public Disruptor<AlertEvent> alertDisruptor(DashboardAlertDao dao) { |
|
|
|
|
|
|
|
int ringSize = 1024; |
|
|
|
int ringSize = 32768; |
|
|
|
|
|
|
|
Disruptor<AlertEvent> disruptor = new Disruptor<>( |
|
|
|
new AlertEventFactory(), |
|
|
|
ringSize, |
|
|
|
Executors.defaultThreadFactory(), |
|
|
|
createDisruptorThreadFactory("alert-disruptor"), |
|
|
|
ProducerType.MULTI, |
|
|
|
new BlockingWaitStrategy() |
|
|
|
new SleepingWaitStrategy() |
|
|
|
); |
|
|
|
|
|
|
|
disruptor.handleEventsWith(new AlertEventHandler(dao, batchSize)); |
|
|
|
disruptor.start(); |
|
|
|
|
|
|
|
return disruptor; |
|
|
|
} |
|
|
|
|
|
|
|
@ -90,5 +96,4 @@ public class DisruptorConfig { |
|
|
|
public RingBuffer<AlertEvent> alertRingBuffer(Disruptor<AlertEvent> disruptor) { |
|
|
|
return disruptor.getRingBuffer(); |
|
|
|
} |
|
|
|
|
|
|
|
} |