I. node. JS is event-driven and asynchronous programming.
The term event-driven is no stranger. In network programming in some traditional languages, we will use callback functions. For example, when the socket resource reaches a certain state, the registered callback function will be executed. In the design philosophy of Node. js, event-driven is the core. The vast majority of Apis it provides are event-based and asynchronous. Take the Net module as an example. the Socket object has the following events: connect, data, end, timeout, drain, error, close, etc., using Node. js developers need to register the corresponding callback function based on their own business logic. These callback functions are executed asynchronously, which means that although these functions appear to be registered sequentially in the code structure, they do not depend on the order in which they appear, wait for the event to be triggered. An important advantage in the design of event-driven and asynchronous programming is that the system resources are fully utilized, and the execution of code does not need to be blocked to wait for a certain operation to complete. limited resources can be used for other tasks. This type of design is very suitable for backend Network Service programming, and Node. js's goal is also to this. In server development, concurrent request processing is a big problem. blocking functions can cause resource waste and time delay. Through event registration and asynchronous functions, developers can improve resource utilization and performance. From Node. in the support module provided by js, we can see that many functions, including file operations, are executed asynchronously, which is different from traditional languages. To facilitate server development, Node. js has many network modules, including HTTP, DNS, NET, UDP, HTTPS, and TLS. On this basis, developers can quickly build Web servers.
Ii. nodejs Performance Analysis
Node. js has good performance. According to founder Ryan Dahl, performance is an important factor for Node. js consideration. Selecting C ++ and V8 instead of Ruby or other virtual machines is also based on performance. Node. js is also bold in design.Single Process, single threadRun in mode (surprised, right? This is consistent with the Javascript running mode). The event-driven mechanism is Node. js is implemented through highly efficient maintenance of the event loop queue by a single internal thread. It does not have multi-threaded resource occupation and context switching, which means that in the face of large-scale http requests, Node. with event-driven processing, js gets used to network service developers in traditional languages and may be very familiar with multi-thread concurrency and collaboration, but is familiar with Node. js, we need to accept and understand its features. Therefore, can we determine whether such a design will cause the load pressure to be concentrated on the CPU rather than the memory. Since Node. js adopts a single-process and single-thread mode, in today's popular multi-core hardware environment, how does Node. js, with a single-core performance, use multi-core CPUs? Founder Ryan Dahl suggested running multiple Node. js processes and using some communication mechanisms to coordinate various tasks. Currently, many third-party Node. js multi-process support modules have been released.
Apt-get install nodejsapt-get install npm it is recommended to check the version of nodejs after installation, because some nodejs versions that come with ubuntu are relatively old, as a result, npm can not install some node module components for older versions, it is recommended to reinstall nodejswget http://nodejs.org/dist/v0.10.12/node-v0.10.12.tar.gztar zxvf node-v0.10.12.tar.gzcd node-v0.10.12. /configuremake & make install the above is the nodejs installation package required below let everyone to familiarize themselves with nodejs some of the basic suggestions for everyone to see this (http://wenku.baidu.com/view/22a03f6d011ca300a6c39092.html ): I personally feel that it is helpful for some js-based shoes. To help you get started easily. After reading the above article, I believe that you have a preliminary understanding of nodejs. As I am also in the beginner stage, I have learned so much about it, after reading the above, you can learn about nodejs framework express. After continuing to work hard, I will sort out some materials for you.