The author recently began to learn to improve the Web performance aspects of knowledge. This article will introduce the use of Nginx to do distributed deployment, to achieve static separation, and analysis of performance.
Static and dynamic separation, that is, CSS, JS, jpg and other static resources and JSP dynamic resources, such as processing, to improve server response speed, improve performance.
The following examples are given to achieve static and dynamic separation, where static resources, such as CSS, JS, jpg, etc. by the Nginx server processing, direct access to disk resources, dynamic resources, such as JSP by the Tomcat server processing.
First configure Nginx.
The specific configuration of the nginx.conf is as follows:
The Nginx server acts as a proxy server, listens to 80 ports, and determines if access to dynamic resources is handled by a Tomcat server listening on port 8080, otherwise accessing static resources in the local Disk HTML folder.
Start the Nginx server and Tomcat server, Access port 80 in the browser, and view the Firefox browser's developer tools as follows:
It can be found that static resources are directly obtained from the disk, the response header has the Cache-control field, the static resource request time is 0ms.
Using the 8080-port access page directly, you get the following:
Each resource requires a 1-3ms to be fetched, and the response header has no cache-control field. Thus, static and dynamic separation has been achieved.
Also using the AB instruction for stress testing, the results are as follows:
Static and dynamic separation:
No static separation:
You can also see the performance of the static separation version is better, the total time *1000 (because the value is too small), throughput rate, transmission rate to make a bar chart comparison is as follows:
The performance level is obvious.
The above content is only the simplest use of nginx, nginx to raise high-performance content there are many, including caching and so on. I will continue to learn, update the blog.