The flaw of single-threaded asynchronous callback mechanism and node's solution

Source: Internet
Author: User
Tags node server

One, node single-threaded async flaw:

The advantages of single-threaded async Naturally Needless to say, node is able to rise so fast, its single-threaded asynchronous callback mechanism compared to the traditional synchronous execution of programming language advantage is one of the reasons. However, the development of a node program, its shortcomings can not be ignored:

Second, node solution:

1. Node implements access and error logs:

Morgan is a middleware for HTTP request processing

  

  

  

2. The node cluster module supports enabling multiple worker processes to fully invoke CPU resources, as well as preventing bugs from crashing the node process:

App.js Modification:

  

New cluster.js:

  

Command line execution:

  

  Note: Supervisor is a node third party package for monitoring node program, when the node program changes supervisor will listen and restart the server, easy to modify debugging. Installation available: NPM INSTALL-G supervisor;

The process Manager creates the corresponding worker process based on the number of CPU cores you have.

3, Nginx to do reverse proxy forwarding:

If the computer has Apache server, modify the listening port number for the 8080,node process also do not listen to 80 port, left Nginx.

Download Nginx, modify nginx config file nginx.conf,php file forward to Apache,node access forward to node server (e.g. 3000 port)

  

More about Nginx configuration can be self-Baidu Nginx+apache,nginx+node Learn

  

  

The flaw of single-threaded asynchronous callback mechanism and node's solution

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.