Summary of website performance optimization and spring integration redis

Now more and more places need non relational databases. Recently, the website has been optimized. Of course, after the corresponding optimization from the page to the server, it is found that there is a significant improvement through the online website testing tool compared with the previous optimization.

At present, server optimization mainly optimizes Tomcat. The server under Tomcat directory The XML file is configured as follows:

Website performance optimization refers to the book "guide to high performance website construction" and some knowledge blogs

As far as our project is concerned, I refer to this book and carry out according to these specifications. The book puts forward 14 suggestions for optimization. However, not all the 14 suggestions are adopted. The website performance must improve very well. It should be combined with the actual situation of the project.

This is our front-end performance optimization measures:

1. Reduce HTTP requests, such as external CSS, JS, pictures and other components. When visiting a website, these components will be loaded. There are too many components and the loading time is long, especially pictures. Therefore, reducing HTTP requests can effectively improve the performance of the website

2. The head refers to external CSS and the bottom refers to JS. When you click to enter the website for the first time, the background image of the website and other CSS effects of non JS effects will be loaded first. J if you don't put it on the head, you will first see blank, and then there will be corresponding CSS rendering effect. The bottom refers to JS, which visually makes users feel that the loading is fast, and the external CSS and JS are easy to manage, Excessive use of inline JS and CSS will lead to page code reconstruction and subsequent development by others, which will be difficult. At the same time, it is also a good specification. JS is placed at the end, that is, in front of the < / body > tag, and it will be loaded finally. If it is placed under < head > < / head > and loaded in parallel, it will block the download of subsequent files and slow down the rendering of subsequent CSS. Therefore, it is a better choice to put it at the tail.

3. Compression assembly. At present, gzip compression is implemented through the above configuration in Tomcat

4. Merge CSS and JS files. You should know that the speed of loading one JS file is completely different from that of loading two JS files. As soon as possible, the capacity of the former JS file is greater than that of the latter two. In short, the speed of one request is always greater than that of two requests.

From the perspective of HTTP request, the client sends a request to the server, and the server response data is returned to the client. One request to response is always faster than two requests. Go back to the previous HTTP request reduction. In addition, merging does not mean that an unrelated JS is combined with several other unrelated JS, which is not conducive to later management. Merging should be the combination of related JS functions. If there are many unrelated JS files, it is not necessary to merge them. If there are only one or two separate functions, it can be merged with another one or two functions. Remember to write notes and merge JS at the same time. Do not merge too many

Measures taken in the background:

1. SQL optimization query shall try to find out the fields that meet the needs. It is strictly forbidden to use *. At the same time, in and not in shall be replaced with exists and not exists as much as possible

2. Reuse java code to reduce redundancy. In particular, for many duplicate services in the background, write their common parts into a function for reuse of the controller used (of course, this may not be helpful for optimizing website performance, but it is conducive to subsequent development)

The following is the formal spring integration redis:

Why use redis?

As far as our project is concerned, the background loading of opening PMS is too slow. Of course, the reasons include too many useless JS, long loading time, slow natural speed, frequent HTTP requests, unreasonable layout (JS are all placed in the head), no optimization of SQL, etc.

All the above problems can be solved.

Back to the above question, why use redis. Using redis as the cache, R can save all data to the cache first and then to MYSQL to reduce the pressure on the database and improve efficiency.

Why does redis access data faster than MySQL?

Because the former accesses memory and the latter is disk

Because the CPU interacts with the memory directly

Demo example:

Note the SSM framework, jdk8 and tomcat8 servers

1、 POM dependency

2、 Corresponding application config XML configuration

3、 JavaBean

Remember to implement serialization, otherwise an error will be reported

4、 Interface class

5、 XML file corresponding to the interface

6、 Mybatis config XM configuration

7、 Service and service implementation classes

8、 Controller

9、 Util required

10、 Demonstration effect

At present, I have just used it for a short time. If there is a problem there, you are welcome to give me advice

In fact, the performance bottleneck is related to MySQL. At present, I don't have a special understanding of the principles related to MySQL, so I need to study harder later

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>