MySQL high concurrency solutions

First, the criteria of large sites:
views 1.pv (page views) pages: a site all pages, the total number of times within 24 hours of being accessed. Million level, one million level
2, uv value (unique vistor) unique visitors: a website, within 24 hours, the number of users to access our site. 100,000
3. Independent ip (Highlights): a website, within 24 hours, the number of ip to access our site.
uv value is approximately equal to the independent ip. If you want to consider a local area network, uv value slightly larger than the independent ip
Second, some of the problems caused by large sites
1, a large concurrent.
Concurrency: in (within 1 second) at the same time point, the number of users accessing our website. For the same URL, refresh your browser. Up to 500, very big. 
If concurrency is 500, pv value is. 3600 * 500 * 10 = 18000000
2, large flow. 
The site requires a large bandwidth. 10g.
3, large storage. 
Capacity site database tables into a massive trend, gt level, how to quickly find data you want.
Third, the large concurrent solution:
1, the load balancer:
Hardware: f5-bigip performance is better, immediate, expensive, generally suitable for large company websites, online games company.
Software: 
LVS (linux Virtual Server) linux virtual service, added to the linux kernel. 
nginx: you can do a web server (apache), you can do load balancing.
3, the cluster:
Mainly to resolve the computer single point of failure, the computer in a cluster, only one computer working, the other computer is in sleep state, monitors the computer is working, when the computer is working problems, the sleeping computer immediately take over the work.
Expansion:
single point of failure (in English: single point of failure, abbreviated spof) refers to a system that fails, it will make part of the whole system does not work, in other words, that is a single point of failure will be total failure.
Fourth, the large flow solutions:
1, to prevent our website from hotlinking resources: some non-technical means can be used to prevent hotlinking to add a watermark in the picture
2, to reduce the http request: that is the primary means of merging js files, css files, background image file. The browser needs or style files js files, combined into one style or file js file. For example, the background image by example, is to get some of the icons on the icon to a large background, the position taken by an icon icons.
3, enable compression: the amount of data to reduce data transmission, a common compression format is: gzip, the deflate.
4, through the browser cache data content: there are some resources in the site, such as js files, css files, some image files, update the frequency is relatively small. To set the cache by a set of http cache-control expires property, you can set the cache file type, set the cache of cache cycle
5, you can put some resources were more occupied by traffic, set up a separate server: such as pictures servers, video servers, etc. .
Five large storage solutions:
1, cache technology:
by caching, querying the database does not achieve the purpose of the database query or less.
Access speed computer memory "hard disk file" database
caching technology are:
disk cache (static pages), to query a database page into a page does not query the database
Memory cache: save frequently queried data into memory, the next time the query query data directly in memory inside.
(Memcache / redis / mysql engine's memory)
2, in the design of the table, to meet Paradigm 3:
The first paradigm: Atomicity, the field can not be divided. As long as the relational database will automatically meet the first paradigm:
classification database: 
relational database: the concept of rows and columns, a two-dimensional form. Common relational databases: mysql, sql server, oracle, db2
non-relational databases (nosql) for collection and documentation, there is no concept of rows and columns are common redis / mongodb etc.
The second paradigm: You can not have in a table exactly the same record. Can be a primary key by setting the
third paradigm: the table fields are not redundant storage
3, to give the table to add the appropriate index: the index is very important, can improve query speed:
Common index are: primary key index, the only index, the general index, full-text index
4, to create the appropriate stored procedures, functions, triggers, and so on.
5, separate read and write (master and slave server)
6, sub-table technique (vertical division and the horizontal division)
7, partitioning: the contents of a data table, stored in different areas
8, mysql upgrade server (add configuration: increase content, 64)
9 ** ** to tune to sql statement: select * from tablename Do not use the statement, to demand query. Which data fields required, the data on which field of inquiry
10, the configuration files to optimize the allocation
such as the configuration concurrency mysql database: Find the max_connections = 100 The value in mysql configuration file my.ini can regulate the amount of concurrent mysql.

Guess you like

Origin blog.51cto.com/14354846/2408090