Nodejs class Sixth asynchronous I/O characteristics

Source: Internet
Author: User

We will study the "Braised chicken rice" business strategy, two cooks and a little girl, 10 tables, a waiter to take

Take care of more than a guest, when the user accesses 3000 port, we put the haha display in the webpage.

How to Render

Everyone watch this is the yellow stewed chicken rice, in greeting 172, has given 111 good food

133来, in greeting 133, already put 66 78 211 222 Read finished, set 133 has not read finished, and then came again, that is, this waiter will not death, and so give you finish dishes, alternating,

As long as I/O more, NODEJS macro on the more parallel, Nodejs afraid of is calculated, but if a person to the sister-in-the-cold chat, this time is not parallel,

node. js is suitable for the development of I/O business, and not suitable for computing the heavy workload of the business, that the calculation is given to the client JS is not OK, this is very reasonable,

PHP is also multi-threading, the CPU is often waiting for I/O to end, when the parallel is great, the CPU theoretical computing power is 100%;

Because Nodejs want to be able to operate efficiently on the broken machine, the sword Walk Pifo adopts the single-threaded mode.

For example, when accessing a database to obtain data, it takes a long time, in the traditional processing mechanism, after the execution of access to the database code, the entire thread will be paused, waiting for the database to return the results, in order to execute the subsequent code, that is, I/O block the execution of code, Greatly reduces the efficiency of program execution.

Because of node. The non-blocking I/O mechanism is used in JS, so the following code is implemented immediately after the Access data shorts code is executed.

When an I/O execution is complete, the linear execution of the I/O is notified as an event, and the thread executes the callback function at this time, in order to handle the asynchronous I/O, the thread must have an event loop, constantly checking that there are no unhandled events and processing them at once.

3.3 Event-driven

Event-driven is the underlying mechanism of NODEJS, we only need to understand that Nodejs will not "the wrong dish", the reason is the event-driven, there is an event ring, that table is a Muslim, you on the fish fragrant shredded pork, not the wrong dish is because there is a thing event-driven,

Nodejs will put everyone's request to the event, stack, and then process it later

Nodejs class Sixth asynchronous I/O characteristics

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.