Node.js can solve any problem?

First, the use Node.js can solve any problem

For PHP, JAVA, Python and other server-side language, create a new thread for each client connection, and each thread needs about 2M of memory, in theory, have 8GB server can simultaneously maximum number of user connections around 4000, to make Web applications to support more users, we need to increase the number of servers, so the hardware cost increases.
The server supports a maximum simultaneous connection of users is a major bottleneck.

Node.js is a server used to develop a variety of Web development tools, running a high-performance V8 JavaScript scripting language,

Second, what is V8JavaScript?

Is to use a high-performance V8 JavaScript JavaScript C ++ language developed by Google, the engine is not limited to running in a browser. Using a new compiler technology inside the V8 engine, high-end JavaScript script code with developers to write low-end C language have very similar efficiency

Three, Node.js of two mechanisms

  1. Non-blocking I / O
    a feature of JavaScript is that it only supports a single thread, there is no need to worry about the phenomenon can cause deadlock.
    And client-side scripting language is different, Node.js provides non-blocking I / O mechanism for the V8 JavaScript.
    For example, when accessing a database to obtain search results, after starting to access the database, the database returns the results before, there is a period of waiting.
    After the traditional single-threaded processing mechanism, after the implementation of the code to access the database, the entire thread will pause and wait for the database to return the query results to continue to implement its code behind. I.e. I / O operations blocking execution of the code, greatly reducing the efficiency of the program execution.
    Because a non-blocking Node.js used in I / O mechanism, thus immediately behind the code is executed instead, after execution of the code to access the database, the database returns the results of the processing code in the execute callback function, thereby improving the performance of programs.
  2. Events ring
    in Node.js, in one moment can only perform one event callback function, but may instead perform other events in an event callback execution halfway, and then return to continue with the original event callback function, which is called event handling mechanism ring mechanism

Four, Node.js development suited to the scene?

Before application needs to handle a large number of concurrent I / O, sent in response to the client, the application does not require internal complex processing time

  1. Chat server
    in a high popularity chat application, there are typically a large number of concurrent connections between the user and the chat server may be at the same time, the server itself does not present a very complicated process
  2. Comprehensive service websites, servers, e-commerce sites
    such sites, it is often possible to receive in one second to as many as thousands of pieces of data and the data needs to be written to the database, if you use other servers (Apache or Tomcat) , take some time to write each data. And Node.js queue mechanism through which data is written to the cache area quickly, and then through a separate process for each extracted data from the cache and then written to the database, as it uses the non-blocking I / O mechanism , it can be achieved at the same time the data is written into the database, without having to wait for some time for each data

Guess you like

Origin www.cnblogs.com/chenqionghe/p/11374483.html