English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Underlying Technology Supporting Java NIO and NodeJS

underlying technology supporting Java NIO and NodeJS

As is known to all, in recent versions of Java, some features have been added to support Java NIO, NIO2support, and at the same time, one of the most praised advantages of the NodeJS technology stack is its high-performance IO. So, the topic we are going to discuss today is the underlying technology that supports these technologies.

Before we start, we need to raise a question:

Why NodeJS and Java NIO2Why not appear earlier?

Answer:personally believe that the underlying supporting technology is not yet mature.

Then, what does the underlying technology refer to? Yes, I think many people have guessed, it is the operating system technology. The two concepts proposed in this article, Java NIO2and NodeJS are no exception, they are all user-space technologies or application-layer technologies, and these application-layer technologies run on the OS. At the same time, with the progress of the operating system, the supported programming models are becoming more and more abundant. It can be said that these two technologies are completely evolved to take advantage of the benefits brought by the progress of the operating system. Generally speaking, the technology that enjoys this benefit first is C\C++because the progress of the OS provides most of the latest system calls, and C\C++is the most convenient to apply these system calls, but it is also the most complex. Other platforms must constantly evolve, encapsulate, and allow users to enjoy these benefits. Once a platform stops updating, it is the time when the platform declines. The more convenient the encapsulation is for users, the more user-friendly it is, and the more people may use it. Although many people can quickly write code based on these platforms, they often do not grasp the essence because they fundamentally do not understand the motivation and principles of these technologies. The technologies we will discuss below are the underlying technologies related to these two technologies.

In any OS design, the following5are indispensable IO models.

1. blocking I/O
2. non-blocking I/O
3. I/O multiplexing (select, poll and epoll)
4. signal driven I/O (SIGIO)
5. asynchronous I/O (the POSIX aio_ functions)

1. blocking I/O

As shown in the figure, the advantage of this IO model is that it is simple to program and is one of the earliest supported IO models by the OS. The disadvantage is that system calls block the execution of user dynamic threads, resulting in wasted CPU time and low IO efficiency.

2. non-blocking I/O

As shown in the figure, an improvement of this IO model is that IO is non-blocking, but it requires long polling, which also wastes CPU clock cycles.

3. I/O multiplexing (select, poll and epoll)

As shown in the figure, this IO model is the most stable IO model provided by the OS today. Most mainstream applications are built based on this IO model, such as NodeJS. However, these platforms often add an additional layer of encapsulation on top of this model to directly support AIO.

4. signal driven I/O (SIGIO)

As shown in the figure, this IO model is due to the comparison model3There is no performance advantage, and due to the unstable system support, it is rarely adopted by designers.

5. asynchronous I/O (the POSIX aio_ functions)

As shown in the figure, this IO model is the most perfect AIO, and the programming model is also the simplest, but the OS that can perfectly support this model is very few. According to online information, Linux is making efforts in this aspect. Once the OS makes progress in this aspect, programming frameworks, platforms, and programming models may still need to be greatly simplified.

Although this model is rarely supported by OS, it does not mean that there is no such AIO model now. Many frameworks have done work in this area, simulating AIO in user mode, allowing users to focus more on business logic code.

6. Synchronous and asynchronous, blocking and non-blocking

Synchronous and asynchronous are terms used to describe the interaction between applications and the kernel. It is synchronous to wait until the data is read before returning, and it is asynchronous to return directly. Blocking and non-blocking are terms used for processes and threads, where the thread waits to read or write under blocking mode, and immediately returns a status value under non-blocking mode.

That's all for this article. I hope it will be helpful to everyone's learning, and I also hope everyone will support the Naya Tutorial.

Statement: The content of this article is from the Internet, the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email for reporting, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)

You May Also Like