The underlying technology of supporting Java NIO and Nodejs _java

Source: Internet
Author: User
Tags epoll posix

The underlying technology supporting Java NIO and Nodejs

While it is well known that some Java NIO and NIO2 support has been added in recent versions of Java, and one of the most admired of the Nodejs technology stacks is its high-performance io, the topic we are discussing today is the underlying technology that underpins these technologies.

One of the first questions to ask before starting is:

Why didn't the Nodejs and Java NIO2 appear earlier in the day?

Answer: personally think that the underlying support technology is not mature.

So what does the underlying technology mean? Yes, I think a lot of people have guessed that it is operating system technology. In this paper, the two concepts of Java NIO2 and Nodejs are User state technology or application layer technology, and these application layer technology is running on the OS, at the same time with the progress of the operating system, can support the programming model is richer. It can be said that these two technologies are entirely evolved to apply the dividends of operating system progress. In general, the first technology to enjoy this dividend must be c\c++, because the OS's progress is most recently provided by system calls, while C\c++ is the most convenient to apply these system calls, but it is also the most complex. Other platforms, in order to achieve the same performance, must evolve, encapsulate, and allow users to use these dividends, and once that platform is stalled, the platform is down. The more convenient the encapsulation for the user, the more friendly the user will be, the more people may use it. Although many people can quickly write the code based on these platforms, but often not the essence, because in essence still do not understand the motives and principles of these technologies. The techniques we are discussing below are the underlying technologies associated with these two technologies.

In either OS design, the following 5 IO models are essential.

1. Blocking I/O
2. nonblocking 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

The advantages of this IO model, as shown in the illustration, are simplicity of programming and one of the earliest OS-supported IO models, with the disadvantage that system calls block user dynamic thread execution, resulting in wasted CPU time and low IO efficiency.

2. nonblocking I/O

An improvement in this IO model, as shown in the figure, is that Io is non-blocking, but requires long polling, as well as a waste of CPU clock cycles.

3. I/O multiplexing (SELECT, poll and Epoll)

As the figure shows, this IO model is the most stable IO model provided by today's OS, and most of the mainstream applications are built on this IO model, such as NODEJS, but these platforms tend to add a layer of encapsulation on top of the model to support AIO directly.

4. Signal driven I/O (Sigio)

As shown in the picture, the data records that this IO model is not a performance advantage due to the contrast Model 3, and is rarely used by the designers because of the unstable system support.

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

As shown in the picture, this IO model is the most perfect AIO, the programming model is also the simplest, but the perfect supporter of a model of the OS very few, online data show Linux is doing this effort, once the OS in this area progress, programming framework, platform, programming model may still need to have a large degree of simplification.

Although this model has few OS support, it is not that there is no such AIO model, many frameworks do this, in the user state simulation of AIO, so that users can pay more attention to business logic code.

6. Synchronous asynchronous, blocking and non-blocking

Synchronization and Asynchrony are for the interaction between the application and the kernel. Wait until the data is read and then return to the synchronization, the direct return is asynchronous. Blocking and non-blocking is a process, a thread, a blocking mode read or write thread is waiting, rather than blocking, the read or write thread returns a status value immediately.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.