Problem description

If the project encountered a large amount of data and high concurrency, it may cause server crash, user page crash, lag and other phenomena, so need some means to deal with this situation!

From the front end

Assuming that the back end is clearly returning a large amount of data, there are three ways to start from the front end! 1. Loading in segments 2. Minimizing useless data 3

load

This way is mainly through the modification of interaction, in front of the use of paging or rolling loading way, the purpose is to make the data do not at a time to all processing! Thus increasing the loading speed.

Minimize unwanted data

There may be a large number of useless fields in the data returned by the back-end. You should write in the background to remove these useless fields and reduce the volume of data as much as possible.

Run in background

If the loaded data still needs to be calculated, the page will not be affected to continue loading, and this part of the request can be switched to the background operation, so the worker in H5 will be used here. The so-called worker is able to independently start a thread to run scripts in the background. The usage method is also very simple, and the general usage is as follows:

const worker = new Worker(aURL,options)
// aURL specifies the address of the script to run, which must comply with the same origin policy
// options specifies the name of the worker to distinguish between multiple threads
Copy the code

From the back end

For large amounts of data, we can optimize the backend in the following ways

  1. HTML static
  2. File server
  3. Load balancer and reverse proxy
  4. Dynamic and static separation
  5. Database and SQL statement optimization

HTML static

Some page views, but the content does not often change the page, directly generate static pages. This greatly relieves server data processing and database interaction.

File server

Providing systems that focus on handling file storage and reading, such as images, is one of the most expensive resources in Web services. Separate out the file system to take the load off the server and share the risk.

Load balancer and reverse proxy

First of all, load balancing is the ultimate solution for large websites to solve high load and large number of concurrent requests. In this way, a large amount of work can be distributed to multiple operation units for execution, such as: Web server, FTP server, enterprise critical application server, etc., so as to complete the task together.

Dynamic and static separation

The static resources of the server, such as HTML, CSS, JS, pictures and background applications, can be deployed separately. The static resources can also be deployed on the CDN to improve access speed. Dynamic data is provided through the interface API.

Database SQL optimization

Because a large amount of data need to interact with the database, so the NEED to optimize SQL, optimized SQL and not optimized SQL processing performance is still very different. The main means of optimization are

  1. Adding an index to a database
  2. Appropriate library and table
  3. Using database caching
  4. SQL statement tuning
  5. Use auto-increment primary keys
  6. Database read/write separation
  7. Database active data separation