Home>Article>Backend Development> PHP high concurrency and large traffic solution

PHP high concurrency and large traffic solution

藏色散人
藏色散人 forward
2019-12-18 17:25:26 4324browse

PHP solutions for high concurrency and large traffic

1 The concept of high concurrency

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

Video Course Recommendation →:"Concurrency Solution for Tens of Millions of Data (Theory and Practice)"

2 Concepts related to high concurrency architecture

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

2. PV (Page View): page views, that is, page views or clicks, the number of pages visited by a visitor within 24 hours

--Note: The same person views you The same page of the website is only recorded once as pv

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

4 , Response time: The time it takes from the request to the response is received

5. Unique Visitor (UV): Within a certain time range, the same visitor visits the website multiple times and is only counted as 1 independent visitor

6. Bandwidth: Two indicators need to be paid attention to when calculating bandwidth, peak traffic and average page size

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

Three points to note:

1. QPS is not equal to the number of concurrent connections (QPS is the number of HTTP requests per second, concurrent connections The number is the number of requests processed by the system at the same time)

2. Peak requests per second (QPS) = (Total number of PVs * 80%) / (Seconds in six hours * 20%) [Represents 80% of visits The volume is concentrated in 20% of the time]

3. Stress test: The maximum number of concurrencies that the test can bear and the maximum QPS value that the test can bear

4. Commonly used performance testing tools [ab , wrk, httpload, Web Bench, Siege, Apache JMeter】

Four Optimization

1. When QPS is less than 50

Optimization plan: For general small websites, no need to consider optimization

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

Optimization plan: Database cache layer , Database load balancing

3. When QPS reaches 800, bandwidth bottleneck is encountered

Optimization plan: CDN acceleration, load balancing

4. When QPS reaches 1000

Optimization plan: Do html static caching

5. When QPS reaches 2000

Optimization plan: Business separation, distributed storage

5. High concurrency solution case:

1. Traffic optimization

Anti-hotlink processing (removing malicious requests)

2. Front-end optimization

(1) Reduce HTTP requests [merge css, js, etc.]

(2) Add asynchronous request (not display all the data to the user first, the user triggers an event, then the data will be requested asynchronously)

(3) Enable browser caching and file compression

(4) CDN acceleration

(5) Establish an independent image server (reduce I/O)

3. Server-side optimization

(1) Page staticization

(2) Concurrent processing

(3) Queue processing

4. Database optimization

(1) Database cache

(2) Sub-database, sub-table, partition

(3) Read-write separation

(4) Load balancing

5. Web server optimization

(1) nginx reverse proxy to achieve load balancing

(2) lvs to achieve load balancing

More PHP related For knowledge, please visitPHP Tutorial!

The above is the detailed content of PHP high concurrency and large traffic solution. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete