Php high concurrency solution

PHP high concurrency solution, how to deal with high traffic and high concurrency of websites. This article summarizes common processing methods for everyone, but not details, which are given in a series of subsequent detailed tutorials. I hope you like it.

 

A concept of high concurrency

In the Internet era, concurrency, high concurrency usually refers to concurrent access. That is, how many accesses come at the same time at a certain point in 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, it refers to the number of response requests per second (HTTP requests)

2. PV (Page View): comprehensive views, i.e. 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 pv once

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

4. Response time: the time taken from sending the request to receiving the response

5. Independent visitor (UV): within a certain time range, the same visitor visits the website several times, and only one independent visitor is counted

6. Bandwidth: the calculation of 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 PVs * 80%)/(six hours and seconds * 20%) [representing that 80% of the traffic is concentrated in 20% of the time]

3. Stress test: test the maximum number of concurrent operations and the maximum QPS value

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

 

IV. Optimization

1. When QPS is less than 50

Optimization scheme: for general small websites, optimization is unnecessary

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

Optimization scheme: database cache layer, database load balancing

3. When QPS reaches 800, bandwidth bottleneck is encountered

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 theft chain processing (malicious request removal)

2. Front end optimization

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

(2) Add asynchronous request (do not show all data to the user until the user triggers an event)

(3) Enable browser caching and file compression

(4) CDN acceleration

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

3. Server optimization

(1) Page static

(2) Concurrent processing

(3) Queue Processing

4. Database optimization

(1) Database cache

(2) Database/table/partition

(3) Read write separation

(4) Load balancing

5. Web server optimization

(1) Nginx reverse proxy for load balancing

(2) LVS implements load balancing

 Watson Blog
  • This article is written by Published on April 25, 2019 08:32:25
  • This article is collected and sorted by the website of Mutual Benefit, and the email address for problem feedback is: wosnnet@foxmail.com , please keep the link of this article for reprinting: https://wosn.net/1893.html

Comment