Php concurrent processing capability and high flow large measure has been a Senior PHP development, the consolidation of big thinking direction, details of the program requires an additional finishing summary
First, the concepts
1, QPS (query rate per second): the number of queries or requests per second, in the Internet field, second means in response to requests (HTTP request means)
2, PV (Page View): the number of pages pageviews that page views or hits, a guest access within 24 hours
- Note: the same person browsing the same page of your site, just remember to do a pv
3, the throughput (fetches / sec): number of requests processed per unit time (typically determined by the number of concurrent and QPS)
4. Response time: the time to receive a response sent from the request takes
5, unique visitors (UV): within a certain time frame, the same visitors visit the site several times, only count as one unique visitor
6, Bandwidth: Bandwidth is calculated to be concerned about two indicators, the average peak flow and page size
7, Day website Bandwidth: the PV / Statistical Time (converted to seconds) * average page size ( kB) * 8
Two, QPS optimization
1, when less than 50 QPS
Optimization: for the average small site, regardless of optimization
2, when the QPS of 100, data query bottlenecks encountered
Optimization: Database caching layer load balancing of database
3, when the QPS 800, bandwidth bottlenecks encountered
Optimization: CDN acceleration, load balancing
4, when reaches 1000 QPS
Optimization: do html static cache
5, when the QPS reached 2000
Optimization : separation of doing business , distributed storage
Third, high concurrency solutions Case:
1, traffic optimization
Anti-theft chain processing (removing malicious requests)
2, front end optimization
(1) reduce HTTP requests [The combined css, js, etc.]
(2) adding an asynchronous request (to not all data are presented to the user, the user triggers an event, the request will be asynchronous data)
(3) Enable browser caching and file compression
(4) CDN acceleration
(5) establish an independent image server (reduce I / O)
3, server optimization
(1) static pages
(2) concurrent processing
(3) queue processing
4, database optimization
(1) database cache
(2) sub-library sub-table, partition
(3) separate read and write
(4) load balancing
5, web server optimization
(1) nginx reverse proxy load balancing
(2) lvs load balancing
Sub-library sub-table Additional information:
1, IO bottlenecks
The first: disk read IO bottleneck, too hot data, the database cache does not fit, each will generate a lot of IO query, reduce the query speed -> sub-libraries and vertical sub-table. The second: network IO bottleneck, much requested data, network bandwidth is not enough -> sub-libraries.
2, CPU bottlenecks
The first: SQL problems, such as SQL contains the Join, Group by, Order by, non-indexed fields query conditions, increasing the operation of the CPU operations -> SQL optimization, to establish appropriate index in service for business computing Service layer. The second: single table data is too big, too many line scan query, the low efficiency of SQL, the CPU bottleneck first appeared -> horizontal partition table.