The advantages / disadvantages of reactive programming

I continue to study and try to use a reactive coding style using Reactor and RxJava. I understand that reactive coding improves processor utilization over single-threaded execution.

Is there any concrete comparison between reactive programming and imperative programming in web applications?

How much does the performance increase, throughput achieved with reactive non-reactive programming, cost?

And what are the advantages and disadvantages of reactive programming?

Is there any statistical test?

+5
source share
4 answers

Well, reactive programming means that you complete all your IO-related tasks, such as network calls asynchronously. For example, if your application calls an external REST API or database, you can make this call asynchronously. If you do this, the current thread is not blocked. You can submit multiple requests simply by creating one or more threads. If you follow the lock method, you need to have one thread to handle each request. You can link to my blog post in several parts, part one , part two, and part 3 for more details.

Alternatively, you can use callbacks to do the same. You can make an asynchronous call using callbacks. But if you do this, sometimes you may end up in an addon. Having one callback inside another leads to very complex codes that are very difficult to maintain. On the other hand, RxJava gives you the opportunity to write asynchronous code, which is much simpler, more convenient and more convenient. In addition, RxJava provides you with many powerful operators, such as Map, Zip, etc., which makes your code much simpler, while increasing productivity due to the parallel execution of various tasks that are independent of each other.

RxJava is not another Observer implementation with many operators, but provides good error handling methods and retry mechanisms that are really convenient.

But I didn’t do any RxJava desktop marking with required programming to thank you statistically. But I am sure that RxJava should provide good performance on locking mechanisms.

+8
source

Besides the fact that they are already responding to the absence of blocking functions, another great feature for using a reactive program is the important use of back pressure. Commonly used in situations where your publisher provides more information than your consumer can handle.

Thus, with this mechanism, you can control the flow of traffic between them and avoid unpleasant memory problems.

You can see examples of the practical implementation of the reactive program here https://github.com/politrons/reactive

And about back pressure here https://github.com/politrons/Akka/blob/master/src/main/scala/stream/BackPressure.scala

By the way, the only drawback in reactive programming is the learning curve, because you are changing the programming paradigm. But now all important companies respect and follow the reactive manifesto http://www.reactivemanifesto.org/

+4
source

disadvantages

  • More memory is more intensive in storing data streams most of the time (since it is based on threads over time).
  • It may seem untouched to learn at the beginning (you need everything to be a stream).
  • Most of the difficulties have to be addressed during the announcement of new services.
  • Lack of good and easy resources to learn.

  • Often confused to be equivalent to functional reactive programming.

+3
source

Reactive programming is a microarchitecture style that includes intelligent routing and event consumption.

Reactive is that you can do more with less, in particular you can handle higher loads with fewer threads.

Reactive types are not designed to speed up the processing of your requests or data. Their strength lies in the fact that they can simultaneously serve more requests and process latency operations more efficiently, such as requesting data from a remote server.

They allow you to provide the best quality of service and predictable capacity planning, initially spending time and waiting time without consuming more resources.

WITH
https://blog.redelastic.com/what-is-reactive-programming-bc9fa7f4a7fc https://spring.io/blog/2016/06/07/notes-on-reactive-programming-part-i-the-reactive -landscape https://spring.io/blog/2016/07/28/reactive-programming-with-spring-5-0-m1

0
source

Source: https://habr.com/ru/post/1263864/


All Articles