Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What's the difference between Proactor and Reactor?

Shulou Source: shulou.com Published: 2022-06-02 06:25:49 09月11日 Update

This article is to share with you about the difference between Proactor and Reactor, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Proactor:

The event handle initializes an asynchronous read operation, which does not care about the result of the asynchronous operation, but registers to get the completion event

Event multiplexer waits until the io event completes

When the event multiplexer waits for the io event, the operating system processes the read operation on a parallel kernel thread, puts the data into a user-defined buffer, and notifies the event multiplexer that the operation is complete.

Event multiplexer invokes event handle

The event handle takes user data from the user-defined buffer and operates, then starts a new asynchronous operation and returns the controlled release to the event multiplexer

Proactor mode is AIO.

Added Java AIO in Java 7

Java AIO simulates the implementation based on the epoll pattern (Linux 2.6)

Https://www.jianshu.com/p/8dbb0686fb8b

Comparison between NIO and AIO

So NIO is not suitable for those who take a long time to read and write.

However, AIO was notified only after the reading and writing process was completed.

So AIO is competent for those heavyweight tasks with a long reading and writing process.

It's just that the stage of focusing on the event is different, and the system notifies the thread in a different way.

But AIO simplifies the complexity of coding than NIO.

And more efficient and more scalable.

Then execute the corresponding processing function (the system opens up a thread to complete it)

Execution completion notifies threads concerned about the completion of this event

The current thread can do its own thing without notification

Blocking when getting the notification result

Check the information notified when you are free.

But you can set the timeout.

When there is no result for a period of time, continue to do something else.

Then notify the current thread to process

You need to wait before the notification returns.

And Selector is required to cooperate with the notification thread

What event is NIO listening for? is it ready?

What event has been completed for AIO monitoring?

AIO is not faster to read and write than NIO's IO.

Because the reading and writing process of NIO is still completed in the application thread

These are the differences between Proactor and Reactor. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Events threads multiplexers handles procedures time users systems results processing things that is data more patterns knowledge articles and will monitor buffer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MySQL Shulou Technology NVidia Huawei