Parallelization with the publishOn operator

At first glance, the publishOn operator does not enable the concurrent processing of the Reactive Stream elements, which we might expect. Nevertheless, the Reactive Programming paradigm enabled by Project Reactor allows fine-grained scaling and parallelizing of the processing flow using the publishOn operator. For example, let's first consider the fully synchronous processing depicted in the following diagram:

Diagram 4.10 The fully synchronous processing of a Reactive Stream

As we can see from the preceding diagram, we have a processing flow with three elements in it. Due to the nature of the synchronous processing of elements in the stream, we have to move elements one by one through all of the transformation stages. However, in order to start processing the next element, we have to fully process the previous element. In contrast, if we put a publishOn in this flow, we can potentially speed up processing. The following shows the same diagram but with a publishOn operator included:

Diagram 4.11 The publishOn operator's effect on stream processing

As we can see from the preceding diagram, keeping the processing time of elements the same, and just by providing an asynchronous boundary (represented by the publishOn operator) between processing stages, we can achieve parallel processing. Now, the left-hand side of the processing flow does not need to wait for the completion of the process on the right-hand side. Instead, they can work independently so that parallel processing is achieved properly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.32.67