简体   繁体   English

使用Disruptor和Executor在Java中设计Orchestrator

[英]Designing Orchestrator In Java using disruptor and Executors

We are designing an Orchestrator System in java that will host a web service and on a request to it will invoke a flow written in XML which are nothing but steps that are executed one after another but the XML tell the user what the flow is and he can also change the flow by changing the XML. 我们正在用Java设计一个Orchestrator系统,它将托管一个Web服务,并在请求时将调用以XML编写的流,该流只是一个接一个地执行的步骤,但是XML告诉用户该流是什么,他也可以通过更改XML来更改流程。 He can add a new service and add it to the XML. 他可以添加新服务并将其添加到XML。 But while designing I am now confused with things like. 但是在设计时,我现在对类似的东西感到困惑。

  1. Should I make a service a runnable with a blocking queue and keep it alive all the time by scheduling it to the executor so when the new request arrives I will push the request in the blocking queue and the service will process it. 我是否应该使服务成为具有阻塞队列的可运行服务,并通过将其调度到执行程序来使其始终处于活动状态,所以当新请求到达时,我会将请求推送到阻塞队列中,然后服务将对其进行处理。 And create a Mailbox which will carry the message passing task between different services. 并创建一个邮箱,它将承载不同服务之间的消息传递任务。

  2. Instead of Making service runnable I should use spring IOC that will make the class singleton thus only one instance will be there and I will send a request directly to the service methods thus there will be no hassle that I have to do as there are no threads and also didn't need to implement any mailbox. 而不是使服务可运行,我应该使用spring IOC,它将使类成为单例,因此那里只有一个实例,并且我将直接向服务方法发送请求,因此不会有麻烦,因为没有线程并且不需要实现任何邮箱。

  3. I read about how event driven system is faster like nodejs and ngnix so I was thinking to use disuptor framework to push all the incoming request to the ringbuffer and then write a handler that will emit the event to the orchestrator that will start processing the request and also send a callback with the request so that when the orchestrator is done it will send back the response back to the caller using callback. 我了解了像nodejs和ngnix这样的事件驱动系统如何更快,因此我在考虑使用Disuptor框架将所有传入请求推送到环形缓冲区,然后编写一个将事件发送给协调器的处理程序,该处理程序将开始处理请求并还发送带有请求的回调,以便协调器完成后,它将使用回调将响应发送回调用方。 But as the request is not of the same type it so I would not be able to take advantage of disruptor object allocations. 但是由于请求的类型不同,所以我将无法利用中断对象分配。

The system needs to provide maximum throughput with low latency, the system will add new services/flows to XML in future so it should adopt the new flows without hitting the performance. 系统需要以低延迟提供最大的吞吐量,系统将来会向XML添加新的服务/流,因此它应该采用新的流而不会影响性能。 I am allowed to only use java 7, no Scala so I am bounded. 我被允许只使用Java 7,没有Scala,所以我受到了限制。

Answer #1 is a terrible idea. 答案1是一个可怕的想法。 You will effectively tie up a thread per service. 您将有效地为每个服务占用一个线程。 If the number of services exceeds the number of threads backing the executor service you have an instant, automatic DOS. 如果服务数量超过支持执行程序服务的线程数量,您将拥有一个即时的自动DOS。 Plus, if the services are inter-dependent on each other... all the ways in which you can dead lock. 另外,如果服务之间是相互依赖的...您可以采用所有方式进行死锁。 Plus, the inefficiency of using N threads if only M (< N) are actually required. 另外,如果仅需要M(<N),则使用N个线程的效率低下。

Answer #2: if the proposed flow is Request Parsing -> Dispatch -> Service Processing -> Callbacks you rely on the actual 'services' not to foul up because that will prevent callbacks from being called and/or DOS the application. 答案2:如果建议的流程是“请求解析->调度->服务处理->回调”,则您依赖于实际的“服务”不会阻塞,因为这将阻止调用回调和/或使应用程序DOS。 Essentially: what happens if an exception occurs in a service? 本质上:如果服务中发生异常会怎样? Will that also impact future requests to the same service and/or other services? 这还会影响将来对同一服务和/或其他服务的请求吗?

Also the opportunities for parallelism are limited to the framework's way of handling incoming requests. 同样,并行的机会仅限于框架处理传入请求的方式。 Meaning if you have X requests and the framework inherently processes them serially, you get a backlog of X requests. 这意味着,如果您有X个请求,并且框架固有地按顺序处理它们,则会积压X个请求。 Your latency requirements may be hard to meet in such a scenario. 在这种情况下,您的延迟要求可能很难满足。

Answer #3: an event driven system is indeed the better approach: have a scheduler farm out jobs to an executor service to allow the system to distribute the total load of all services dynamically and have a mechanism to generate and react on events to handle the control flow. 答案3:事件驱动的系统确实是更好的方法:让调度程序将作业分配给执行服务,以使系统动态分配所有服务的总负载,并具有对事件进行生成和响应的机制以处理事件。控制流。 This scales better if the number of services become very large and each 'job' is reasonably substantial (so the overhead of scheduling/dispatch is low compared to the actual work being performed). 如果服务数量变得非常大且每个“工作”相当合理(这样,与实际执行的工作相比,调度/调度的开销就很低),则这种方法的扩展性更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM