Node. js and node. js
Is Node. js Running Based on Chrome JavaScript? Is it easy to build a fast and scalable platform? Networking ?. Node. js uses event-driven, lightweight and non-blocking I/O models? Effect ,? It is often suitable for data-intensive real-time applications running on distributed devices. The V8 engine executes Javascript very quickly and performs very well. Node is a Javascript runtime environment ). In fact, it encapsulates the Google V8 engine. Node optimizes some special use cases and provides an alternative API to make V8 run better in a non-browser environment.
Nodejs is a JS runtime environment based on the Chrome V8 engine, that isLet javascript run on the server side,
NodeJS uses an event-driven, non-blocking I/O model, making it lightweight and efficient.
Nodejs Package Manager npm is the world's largest open-source ecosystem.
Nodejs is the js platform of the server.
Npm grunt express and other powerful code and project management applications on nodeJS.
Differences between NodeJS and traditional server processing platform (Apache)
Apache multi-thread high concurrency Mode
Apache is a type of multi-threaded processing concurrency, but it also blocks some large web applications.
Threads and processes
A thread is the smallest CPU unit that can run independently.
Threads can run concurrently in the same process and share the memory address space of the process.
Processes can support multiple threads, which seem to be executed simultaneously but are not synchronized with each other.
Multiple Threads in a process share the same memory address space, which means they can access the same variables and objects and allocate objects from the same heap.
This makes it easy to share information between threads, but make sure they do not interfere with other threads in the same process.
Asynchronous I/O principle of NodeJS
Example of database call:
Apache will wait for the query to return the result when it runs to the first thread. On the one hand, it will cause the thread to block for a long time, and on the other hand, it will continuously increase the thread for new requests, which will waste a lot of resources, at the same time, increasing threads will take a lot of CPU time to process memory context switching.
NodeJS isAsynchronous single threadThe application isAsynchronous callbackMethod, that isAsynchronous I/O.
Explanation: when a process is executed, it will not wait for the result to be returned, but directly execute the following statement until it enters the event loop. When the database executes the returned result, it will send the event to the event queue, the previous callback function will be called only after the thread enters the event loop.
That is, the working principle of nodejs is actuallyEvent Loop. The logic of each node. JS is written in the callback function, and the callback function is asynchronously executed only after the result is returned.
NodeJS will also be congested, but blocking occurs in a single thread, not in the subsequent callback process.
Differences from php
Using node for website application opening is the multipart loading mode, so you do not need to load all the data to the client at one time like php.
NodeJS saves the CPU memory and context switching time compared with the new thread opened by php and Apache.
NodeJS application scenarios
NodeJs is suitable for applications in a large number of small http request environments, such as web instant chat programs or game servers with tens of thousands of online users simultaneously. You do not need to consider the problem of excessive http requests.
The above is my preliminary understanding of node. js, hoping that these will allow more friends to understand node. js.