使用干扰器与弹簧引导
问题描述:
我有以下的在我的春天启动的应用程序的反应器结构:使用干扰器与弹簧引导
@Configuration
public class AsyncConfig {
@Bean
public EventBus eventBus(){
return EventBus.create(getDispatcher("rb-relay"));
}
public MultiThreadDispatcher getDispatcher(String name){
return new WorkQueueDispatcher(name, 4, 1024, null);
}
}
基本上我在做什么是这样的:每当一个请求到达终点我,我将其转发至其他终端在我的应用程序中注册。为此,我派遣每个传入请求总线:
@Service
public class URLRelayPublisher {
@Autowired
EventBus bus;
@Autowired
DestinationURLRepository repository;
public void relay(HttpServletRequest request){
repository.findAll()
.forEach(destinationURL -> bus.notify("relay", Event.wrap(new RelayEvent(destinationURL, request))));
}
}
和我的消费
@Component
@Log
public class URLRelayReceiver implements Consumer<Event<RelayEvent>> {
@Autowired
RestTemplate template;
@Override
public void accept(Event<RelayEvent> relayEvent) {
try{
HttpServletRequest request = relayEvent.getData().getRequest();
DestinationURL destinationURL = relayEvent.getData().getDestinationURL();
log.info("Relaying for "+destinationURL.getUrl());
Map<String, String> headers = buildHeader(request);
template.postForLocation(destinationURL.getUrl(), headers, request.getParameterMap());
}catch (RestClientException e){
log.info("Could not relay event: "+e.getMessage());
}
}
干扰器号称处理周围6-8米TPS,虽然当我siege
应用程序(siege -d 2 -c 50 -t30S -H 'Content-Type: application/json' -H 'Auth-Token: qyz3kHZFuXRw8nm14uYLjLNoQ' 'http://127.0.0.1:8080/callback POST {"content": "message"}'
)我得到96 TPS左右的东西。我的问题是:1)配置是否足以使用Disruptor? 2)如何确保我在这里使用Disruptor?
答
干扰者可以“处理”6-8米的TPS,但这意味着它可以在线程之间交换6-8个Mi事件。它没有对弹簧引导应用程序的吞吐量做出任何声明。
因此,在你的例子中,它通过RelayEvent
各Consumers
之间。鉴于所有其他工作正在进行的春季启动应用程序的背景下,将主导应用程序的性能而不是破坏者。