Front-end optimization:
1. Use cluster deployment for page servers
Share oneserverThe pressure of high concurrency will not all be requested to a server, causing excessive pressure to the server and causing crashes.
2. Use page static technology
Just put the pageGenerate static page.html for display, reduce database access, improve query efficiency, and improveUser ExperienceSpend.
3. Image server separation
Images are more resource-consuming. We need to separate the pictures and pages, store them in a separate picture server, and deploy the picture servers in clusters. This ensures that the server pressure of the page is reduced under high concurrency.
accelerate(Content Delivery Network-Content Distribution Network)
Speed up response speed (caches data to CDN servers. CDN relies on servers deployed in various places to obtain data from CDN servers nearby through load balancing, content distribution, scheduling and other functions of the central platform to improve query efficiency)
5. Use lazy loading
Scrolling loadOr lazy loading does not mean loading the entire content of the page as soon as you enter the page.
6. Use verification code
makeFlow staggeredMinimize concurrency by means of other means(Sliding verification code is a common method)。
Backend optimization:
1. Load balancing + clustering
Use Nginx load balancing to distribute requests to the backend servers deployed by clusters;
2. Database optimization
Avoid select *
Create an index
Subdivides the database and divides the database according to the business module (the database is deployed on different servers), and subdivides the database according to business needs (vertical subdivides and horizontal subdivides).
Read and write separation, separate read operations and write operations, adopting the master-slave replication method, the master node is used for write operations, and the slave node is used for read operations.
3. Cache
Using caching technology (Redis, local cache, etc.) reduces access to databases and improves system query efficiency.
4. Asynchronous processing
Time-consuming operations are processed asynchronously to avoid blocking the main thread.
Message queue: Use message queue (e.g.RocketMQ, kafka), the time-consuming operations are processed asynchronously.
Asynchronous tasks: Use an asynchronous task framework (such as Spring's "@Asyn" annotation), which will take time to operate asynchronously,
5. Distributed architecture
Using a distributed architecture, a large monolithic application is split into multiple small, independent services to improve the scalability and availability of the system.
6. Concurrent control
Control concurrent requests to avoid system overload.
Token bucket algorithm: Use the token bucketalgorithmControl the request rate to avoid system overload.
Current limit: Use flow restriction tools (such asSentinel, Guava RateLimiter) controls the request rate.
7. Use thread pool
Use thread pools to avoid frequent creation and destruction of threads, and improve the system'sperformance。
8. Use distributed locks
AvoidDistributed SystemsAmong them, high concurrency scenarios lead to concurrency security problems and data inconsistency problems.