Introduction to PHP optimization solutions for high concurrency and large traffic

不言
Release: 2023-04-04 20:28:02
forward
4330 people have browsed it

This article brings you an introduction to optimization solutions for high concurrency and large traffic in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1 The concept of high concurrency

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

II Concepts related to high concurrency architecture

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

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

--Note: The same person browsing the same page of your website will only be recorded as one 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 time the request is sent to the time the response is received

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

6. Bandwidth: To calculate bandwidth, you need to pay attention to two indicators, peak traffic and average page size

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

Three points to note:

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 by the system at the same time)

2. Peak number of requests per second (QPS) = (Total number of PVs * 80%) / (Seconds in six hours *20%) [Represents that 80% of the visits are 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: Do 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 requests (all data will not be displayed to the user first, and the user will trigger an event before requesting the data 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 static

(2) Concurrent processing

(3) Queue processing

4. Database Optimization

(1) Database cache

(2) Sub-database and 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

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

Related labels:
php
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template