The underlying technology supporting Java NIO and Nodejs

Source: Internet
Author: User
Tags epoll posix

The underlying technology supporting Java NIO and Nodejs

It is well known that some Java NIO, NIO2 support has been added in recent versions of Java, while one of the most praised advantages of the Nodejs technology stack is its high-performance IO, so the topic we are discussing today is the underlying technology that supports these technologies.

One of the first questions to ask before starting is:

Why did Nodejs and Java NIO2 not appear earlier in the day?

Answer: Personally think that the underlying support technology is immature.

So what does the underlying technology mean? Yes, I think a lot of people have guessed that it's operating system technology. The two concepts proposed in this paper, Java NIO2 and Nodejs, are either user-state or application-layer technology, and these application-layer technologies operate on the OS , while the programming models that can be supported are richer as the operating system progresses. It can be said that these two technologies are completely evolved to apply the dividends of the operating system's progress. In general, the first technology to enjoy this bonus must be c\c++, as the most recent advances in OS are mostly 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, it must continue to evolve, encapsulation, so that users can use these bonuses, once the platform stalled update, that is, the platform is down. the more convenient the package is to the user, the more friendly it is to the user, and the more people it may use. While many people can quickly write code based on these platforms, they are often not the essence, because they do not inherently understand the motivations and principles of these technologies. The techniques we discuss below are the underlying technologies associated with these two technologies.

No matter which 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 advantage of this IO model is that it is simple programming and one of the first IO models supported by the OS, and the disadvantage is that system calls block user dynamic thread execution, which results in wasted CPU time and low IO efficiency.

2. nonblocking I/O

, one of the improvements to this IO model is that IO is nonblocking, but requires long polling and also wastes CPU clock cycles.

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

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

4. Signal driven I/O (SIGIO)

, the data record that this IO model because the comparison Model 3 has no performance advantages, and because the system support is not stable, very few designers.

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

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

Although this model is rarely supported by the OS, it does not mean that there is no such AIO model now, many frameworks do this, and the AIO is simulated in the user state, allowing the user to focus more on the business logic code.

6. Synchronous asynchronous, blocking and non-blocking

Synchronization and Asynchrony are for the interaction of the application and the kernel. Wait until the data is read and return the synchronization, and the return is asynchronous. Blocking and non-blocking are for processes, threads, read in blocking mode, or write threads waiting, instead of blocking mode, the read or write thread immediately returns a status value.

The underlying technology supporting Java NIO and Nodejs

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.