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