当前位置:网站首页>PHP high concurrency and large traffic solution (PHP interview theory question)

PHP high concurrency and large traffic solution (PHP interview theory question)

2022-07-05 14:59:00 Back end regular developers


PHP High concurrency and high traffic solutions

One 、 The concept of high concurrency

In the age of the Internet , Concurrent , High concurrency usually refers to concurrent access . At some point in time , How many visits come at the same time .

Two 、 Concepts related to high concurrency Architecture

1、QPS ( Query rate per second ) : The number of requests or queries per second , In the field of Internet , It refers to the number of response requests per second ( finger HTTP request )

2、PV(Page View): Comprehensive views , That is, page views or clicks , A visitor is in 24 Number of pages visited in hours

– notes : The same person browsing the same page of your website , Just remember to do it once pv

3、 throughput (fetches/sec) : Number of requests processed per unit time ( Usually by QPS And concurrency )

4、 response time : The time from the request to the response

5、 Independent visitor (UV): Within a certain time frame , The same visitors visit the website many times , Only calculated as 1 An independent visitor

6、 bandwidth : There are two indicators to pay attention to when calculating bandwidth , Peak traffic and average page size

7、 Daily website bandwidth : PV/ Count the time ( Convert to seconds ) * Average page size (kb)* 8

3、 ... and 、 You need to pay attention to :

1、QPS Not equal to the number of concurrent connections (QPS Every second HTTP Number of requests , The number of concurrent connections is the number of requests processed by the system at the same time )

2、 Peak requests per second (QPS)= ( total PV Count 80%)/ ( Six hours and seconds 20%)【 representative 80% All of our visits are focused on 20% In time 】

3、 Pressure test : Test the maximum number of concurrent that can be tolerated And test the most bearable QPS value

4、 Common performance testing tools 【ab,wrk,httpload,Web Bench,Siege,Apache JMeter】

Four 、 Optimize

1、 When QPS Less than 50 when

Optimization plan : For general small websites , Don't think about optimization

2、 When QPS achieve 100 when , Encountered data query bottleneck

Optimization plan : Database cache layer , Database load balancing

3、 When QPS achieve 800 when , Bandwidth bottleneck

Optimization plan :CDN Speed up , Load balancing

4、 When QPS achieve 1000 when

Optimization plan : do html Static cache

5、 When QPS achieve 2000 when

Optimization plan : Do business separation , Distributed storage

5、 ... and 、 High concurrency solution cases :

  1. Traffic optimization

Anti theft chain handling ( Remove malicious requests )

  1. Front end optimization
  • Reduce HTTP request [ take css,js Etc ]
  • Add asynchronous request ( Don't show all the data to the user first , The user triggers an event , To request data asynchronously )
  • Enable browser caching and file compression
  • CDN Speed up
  • Set up an independent image server ( Reduce I/O)
  1. Server optimization
  • Page static
  • Concurrent processing
  • Queue processing
  • Control large file downloads , It is recommended to put large files on another server
  1. Database optimization
  • Database cache
  • Sub database and sub table , Partition
  • Read / write separation
  • Load balancing
  • Try not to query select *
  • Avoid related subqueries
  • Add indexes to frequently queried
  1. web Server optimization
  • nginx Reverse agent to achieve load balancing
  • lvs Load balancing
原网站

版权声明
本文为[Back end regular developers]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140519024739.html