2017-02-19 223 views
0

我有以下的在我的春天啓動的應用程序的反應器結構:使用干擾器與彈簧引導

@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?

回答

1

干擾者可以「處理」6-8米的TPS,但這意味着它可以在線程之間交換6-8個Mi事件。它沒有對彈簧引導應用程序的吞吐量做出任何聲明。

因此,在你的例子中,它通過RelayEventConsumers之間。鑑於所有其他工作正在進行的春季啓動應用程序的背景下,將主導應用程序的性能而不是破壞者。