node. js asynchronous I/O and event-driven combat

Source: Internet
Author: User
Brief introduction

the biggest feature of node. JS is the asynchronous I/O and event-driven architecture design. for highly concurrent solutions, the traditional architecture is a multithreaded model that provides a system thread for each business logic module to compensate for the time overhead of synchronous I/O calls through system thread switching. node. JS uses a single-threaded model, with asynchronous requests for all I/O, avoiding frequent context switching. node. JS maintains an event queue during execution, the program enters the event loop at execution time, waits for the next event to arrive, and each asynchronous I/O request is pushed to the event queue for processing by the program process.

Concept Synchronous Invocation

A synchronous call is a blocking call, and when a piece of code calls another code, it must wait for the code to finish executing and return the result before the code can continue to execute.

asynchronous invocation

An asynchronous call is a non-blocking call, and a piece of asynchronous code is not finished, and you can proceed to the next piece of code logic, and after the asynchronous code executes, return to the corresponding logic through the callback without delaying the execution of the other code.

Callback

Callbacks are not asynchronous calls, but callbacks are a way of handling the results of asynchronous function execution. At asynchronous invocation, if we want the results of asynchronous code execution to be returned and processed, it can be resolved by means of a callback. Note that the callback is also a blocking call.

Supplement: Asynchronous functions often do not return execution results directly, but instead return execution results to the callback function through event-driven methods, and then process the corresponding logical code in the callback function.

node. js asynchronous I/O and event-driven combat

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.