Chapter One: node. JS Summary

Source: Internet
Author: User

What is Nodejs

Nodejs is a performance-based JavaScript toolkit for writing high-performance Web servers. (translation is: Using JS to develop the service-side program)

1, single-thread, asynchronous, event-driven,

2, the characteristics are: fast. Consumes more memory.

3. Asynchronous elimination of memory testing:

Online level 1 million concurrency test, which consumes 16G of memory without optimization.

How to understand the characteristics of nodejs execution speed, but memory consumption

Knowledge points for PHP

PHP itself does not support multithreading, because PHP's server Apache itself supports multithreading. When Apache starts, it provides 150 threads to PHP first, assuming that under concurrent conditions, for example, at the same time when more than 10,000 users suddenly open a browser to access this page, then up to 150 users from the thread pool first to get the 150 threads, These 150 threads have uploaded threads, there are downloaded threads, and after the thread finishes executing the task, the results are returned to the customer before being put back into the thread pool and then used by other users.

This process is the process of PHP operation.

Nodejs is a single-threaded, then it is how to run it, if the use of PHP like the above single-threaded operation, the operation will be characterized by slow, so nodejs here to use the asynchronous operation, greatly provides the efficiency of the work. So how does the Nodejs work?

First of all, there is only one thread in Nodejs, assuming that there are 10,000 concurrent accesses, Nodejs will take a different library operation, and when the first user accesses it, the thread will open up a small amount of memory in memory for the user to upload and download. When the second user arrives, the thread will open up a small piece of memory for him, and so on, to complete the concurrent access of the user at the same time in large batches.

To give a proper example, this is the equivalent of a patient to a hospital, a nurse is only responsible for the patient registration, so that patients to the various departments to see the doctor. Nurses play a single-threaded role, and each department plays a role in the memory that is being opened up.

Nodejs This access is characterized by:

Fast, (I don't care what you do, you go to the corresponding memory, you can)

Consumes more memory. (Multiple user concurrent access requires more memory to be opened)

PHP will not be able to run other tasks until the task is completed.

Add:

You may encounter the following interview questions when you are interviewing PHP:

High concurrency, big data volume in the case of how to go faster to complete?

To optimize the situation, and the core of the optimization is to improve the performance of this PHP around the faster end of a thread.

Nodejs vs PHP

Some people say that Nodejs and JavaScript is a competitive relationship, it can actually be said that the two are complementary relations, and Nodejs and PHP competition is the biggest, there are foreign people in the Technical Forum from the performance of the two to make the following comparison:

Advantages of Nodejs:

High performance, (mechanism problem)

High development efficiency, (can not save the optimization of things)

Wide range of applications (can develop desktop systems, ELECTROM framework)

Disadvantages of Nodejs:

New, less people

Less middleware

The IDE is not perfect.

Nodejs's weaknesses and solutions

? multicore is not supported by default, but can be resolved with cluster

? server clusters are not supported by default and Node-http-proxy can be resolved

? using Nginx for load balancing, static nginx processing, dynamic processing by Nodejs

Forever or Node-cluster for disaster recovery

We study framework selection

? The more popular include: Express, KOA, HAPI

? and sails on the express basis

Express: Perfect, stable, document-based, community-wide

KOA: Ahead, being perfected, developed with ex6.

? Hapi: (Not for beginners) complex (a simple hello,world to make a lot of piling up), suitable for complex large projects.

This tutorial learning path

node. JS Basics (let you get a deeper understanding of his underlying principles)

Express Framework

Sail Frame

Project (development):

Sails+vue.js

Sails+react

Code Copy method Teaching: http://www.yuankuwang.com

Editor (IDE):

? Notepad (EditPlus)

? webstorm

? Atom or Sublime

Learning methods:

? Read more Documents

? Groping for Tests

Chapter One: node. JS Summary

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.