MySQL Network with the speed and passion

These two days looking at MySQL's classic book "High Performance MySQL", for which the data type selection became interested. At the same time think of traffic bottlenecks in high concurrency while back to see, and when asked about the level before the interview when MySQL index to find data by time-consuming. It was decided to calculate these hands-on time.

Basic data types

For the computer memory, we know that the smallest unit of computer data storage is the internal " 'bit bit", a bit 0 or 1 may be stored. But, after all, a bit of information stored is limited, so using 8 bit byte to represent a Byte, Byte Byte is the basic unit of computer data processing, can represent 8 bit 2 ^ 8 = 256 information, storing English letters and other ASCII code is enough. The following are some basic Java and MySQL data type storage space.

Java and MySQL basic data types

MySQL storage

Here a single character type varchar speaking, when using the first MySQL storage varchar 1 ~ 2 byte tag varchar length, so presumably can reach up varchar (2 ^ 16-1) -2 = 65,532 characters, but do not forget MySQL predetermined maximum length of each row is (2 ^ 16-1) = 65535 bytes, and the database is generally used utf8 encoding, so that each Chinese character varchar stored as 3 bytes, the memory of all Chinese varchar maximum length is defined as ((2 ^ 16-1) -2) / 3 = 21844, i.e. VARCHAR (21844), this is of course without consideration of the other columns.

MySQL search speeds

For innodb storage engine, we know that its default index data structure is B + Tree, the file system and memory are read and stored by the page, each page 16K, probably tables are stored in general 1 to 3 layers of B + Tree, then we calculate, B + Tree 3 layers about how much data can be stored it?

B+Tree

According to B + Tree height is 3, ⻚ to 16K, ⼀ rows 1K, the primary key bigint 8 bytes is calculated, non-leaf Submenu sub available with 16K / (8 + 6 pointer) = 1170 leaf nodes, is largest large number 1170 in an amount of 2.19 * 1170 * 16 = million rows of data. Get each layer, MySQL needs a disk IO, and general disk one second would be able to carry out 100 times IO, so if the index is a layer structure, then the primary key query only needs 0.01s. As shown below.

Primary key query
Empty rumor, how to prove disk IO is about one second IO 100 it? We know that the disk access time data seek time + = rotation time and the rotational delay depending on the disk rotational speed, the time required for one rotation of the disk is generally used represents 1/2. For example, 7200 revolutions disk average rotational delay of approximately (1000ms / s * 60s / min) / (7200r / min) /2=4.17ms/r, i.e. 4.17 milliseconds each revolution, i.e. a rotation of roughly 4.17 times IO milliseconds, so in theory you can calculate the maximum disk IOPS (IO Per Second). The average seek time of the disk is assumed that the physical 3ms, the disk rotational speed is 7200, the theoretical maximum IOPS of the disk, IOPS = 1000 / (3 + 1000 * 60/7200/2) = 140.

QPS website concurrent with the order

Having MySQL data through the index to find the time, let's look at the order of several concurrent web site. Suppose now that there is a restful interface to a server, the request and return the interface parameters of maximum 10KB. The following is Ali cloud bandwidth cost, bandwidth rate shows the station.

Ali cloud Bandwidth

Fast Bandwidth - 1250QPS

Stand-alone single interface to the size of 10KB, Fast bandwidth means the actual bandwidth site exit is 100Mb / 8b / B = 12.5MB, can be hard to resist for maximum concurrency (100Mb / 8b / B) / 10KB = 1250.

C10K -- 10KQPS

C10K is the Client 10000 question, namely, "while the number of clients connected to the server over 10,000 of the environment, even the hardware adequate performance, is still unable to provide normal services," but said Taobao when 12-year double 11, QPS has been able to reached the 40K.

DB limit type - 15100QPS

This is only a hypothesis, as we analyzed if the database is taking the clustered index, then it is probably time to each IO 0.01s, MySQL default maximum number of connections is 151, so 151 can handle one-time requests, as qps 151 * (1s / 0.01s) = 15100. Of course, this is an extreme state, however, complicated by concurrent reach 151, MySQL is not possible in 0.01s but also to maintain the IO.

Reference material

  1. Web site of the order of several concurrent: www.cnblogs.com/aspirant/p/...
  2. Some high concurrent data: colobu.com/2015/04/30/...

Guess you like

Origin juejin.im/post/5d86d5b3f265da03be49164e