In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the "example Analysis of non-blocking Imax O in Node.js". In daily operation, it is believed that many people have doubts about the analysis of non-blocking Imax O in Node.js. The editor has consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "non-blocking Imax O example Analysis in Node.js". Next, please follow the editor to study!
How to understand the non-blocking Ibank O of NodeJs
1. Input/output O: that is, input and output of a system
2. The main difference between non-blocking and blocking is whether it can continue to receive other inputs in the process of receiving input to output.
Example:
For example: go out for dinner
There are usually two ways to eat out:
1 go to the canteen to eat: stand in line to eat
[queue]-[wait for the person in front to eat]-[eat by yourself]-[eat]
2 go to the restaurant to eat
[sit down]-[order]-[wait]-[eat]
In terms of these two ways of eating:
1 eating in the canteen: for diners, they must wait for the previous person to finish the meal, and this process is the blocking mode.
2 restaurant: go to the restaurant to eat, the waiter will continue to deal with the next person's order after ordering for you, and then deliver the meal to you when your meal is ready. For the waiter, this process is a non-blocking process.
Understand the main points of non-blocking IBO
1 identify a system that performs IWeiO operation, for example: in the above example, the system that performs Ipicuro is the service staff.
2 is it possible to carry out other Icano in the process of the system's Istroke O operation?
Code demonstration
In the sample code, we introduce a library, glob, which is mainly used to find files that match the criteria. For details, please see https://www.npmjs.com/package/glob
First, let's use the synchronization method provided by glob to read the file.
Const glob = require ("glob"); let result = null; result = glob.sync (_ _ dirname + "/ * / *"); console.log (result)
The result is an array of files:
Let's take a look at the execution time of this synchronization operation:
Const glob = require ("glob"); let result = null; console.time ("glob"); result = glob.sync (_ _ dirname + "/ * / *"); console.timeEnd ("glob")
Results:
An operation to read a file will block the process for 33 milliseconds, which is unacceptable!
Next, we use an asynchronous way to read the file
Let result2 = null; console.time ("glob2"); glob (_ _ dirname + "/ * / *", (err, res) = > {console.log ("glob over");}); console.timeEnd ("glob2")
Results:
It took a total of 4 milliseconds to read the file asynchronously, and we were able to do other operations during the asynchronous read of the file.
At this point, the study on the "non-blocking I Node.js O example Analysis" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.