Solution of high concurrency and large traffic in PHP


Solution of high concurrency and large traffic in PHP


A concept of high concurrency

In the Internet age, concurrency, high concurrency usually refers to concurrent access. That is, at a certain point in time, how many visits come at the same time.

 Related concepts of high concurrency architecture

1. QPS (query rate per second): the number of requests or queries per second. In the Internet domain, it refers to the number of response requests per second (referring to HTTP requests)

2. PV (page view): comprehensive views, that is, page views or hits, the number of pages visited by a visitor within 24 hours

–Note: the same person visits the same page of your website, remember to do PV only once

3. Throughput (fetches / sec): number of requests processed per unit time (usually determined by QPS and concurrency)

4. Response time: the time taken from a request to a response

5. Independent visitor (UV): within a certain period of time, if the same visitor visits the website many times, only one independent visitor will be counted

6. Bandwidth: computing bandwidth needs to focus on two indicators, peak traffic and average page size

7. Daily website bandwidth: PV / statistics time (converted to seconds) * average page size (KB) * 8

 Three points for attention:

1. QPS is not equal to the number of concurrent connections (QPS is the number of HTTP requests per second, and the number of concurrent connections is the number of requests processed simultaneously by the system)

2. Peak number of requests per second (QPS) = (total PV * 80%) / (six hours seconds * 20%) [representing that 80% of the visits are concentrated in 20% of the time]

3. Stress testing: the maximum number of concurrency that the test can bear and the maximum QPS value that the test can bear

4. Common performance testing tools [AB, wrk, httpload, web bench, siege, Apache JMeter]

 4. Optimization

1. When QPS is less than 50

Optimization scheme: for general small website, no need to consider optimization

2. When QPS reaches 100, data query bottleneck is encountered

Optimization scheme: database cache layer, database load balancing

3. When the QPS reaches 800, there is a bandwidth bottleneck

Optimization scheme: CDN acceleration, load balancing

4. When QPS reaches 1000

Optimization scheme: do HTML static cache

5. When QPS reaches 2000

Optimization scheme: business separation and distributed storage

 5、 High concurrency solution case:

1. Flow optimization

Anti leech handling (remove malicious requests)

2. Front end optimization

(1) Reduce HTTP requests [merge CSS, JS, etc.]

(2) Add asynchronous request (do not show all the data to the user, and only when the user triggers an event can the data be requested asynchronously)

(3) Enable browser caching and file compression

(4) CDN acceleration

(5) Set up independent image server (reduce I / O)

3. Server optimization

(1) Static page

(2) Concurrent processing

(3) Queue processing

4. Database optimization

(1) Cache database

(2) Database, table and partition

(3) Separation of reading and writing

(4) Load balancing

5. Web server optimization

(1) Load balancing by nginx reverse proxy

(2) LVS realizes load balance

If you need to learn to communicate, please join us in the exchange group. All the developers in the group have been for 1-7 years. We hope that we can communicate with each other, discuss the technology of PHP and swote, or ask other questions. You can obtain the advanced information of swote or PHP for private chat management

Click here to join the group​