Interview series 37 how to design sub-library sub-table can be dynamically embodiment of the expansion volume reduction

(1) stop expansion

 

This program just stop migration, almost the same steps, the only thing is that the derivative instrument, is to extract data from existing database tables to slowly poured into the new library table and go. Do not be so but the best play, a little less tricky, because since the sub-library sub-table it shows the amount of data is too great, it may be as much as hundreds of millions, even billions, so you play, you may be out problem.

 

Migrating from a single database table to a single sub-library sub-table when the amount of data is not great, also the largest single-table two or three million

 

Write a tool to get more than a few machines running in parallel, one hour data on the finished guide

 

+12 3 library tables, running for some time, the amount of data of 100 million ~ 200 million. 200 million light guide data, to be turned a few hours, 6:00, just finished guide data, configuration also engage subsequent modifications, reboot the system, test validation, we can engage 10:00 End

 

(2) the optimization scheme

 

A start up is 32 banks, each 32 meter, 1024 meter

 

I can tell you students that this points system, first, basically domestic Internet are certainly good enough, second, whether the amount of data concurrency support or support is no problem

 

Writing each bank concurrency normal carrier is 1000, then the library can carry 32 32 * 1000 = 32,000 write concurrent, if each bank 1500 concurrent bearers write, write 32 * 1500 = 48000 concurrent close 5 Wan / s concurrent write, a front plus the MQ, clipping, MQ 8 writes per million data, consumption data per 50,000.

 

Some unless it is the very front rank of these companies, their core database system, there may be such a scale hundreds of databases, 128 libraries, 256 libraries, 512 libraries

 

1024 table, assuming that each data table to put 5 million, you can put five billion data in MySQL

 

50000 concurrent writes per second, a total of 5 billion data for most of the domestic Internet companies, in fact, generally have enough

 

On the expansion of sub-library sub-table, the first sub-library sub-table, give him a one-time fill points, 32 libraries, 1024 table, probably for most small and medium sized Internet companies, has for several years can support the

 

Practice is the use of a 32 * 32 sub-library sub-table, which is divided into 32 banks, each library a table divided into 32 tables. It is a total of 1024 tables. The id of a library according to the first routing modulo 32, and then routed to the table library 32 in accordance with modulo.

 

At the beginning, the library may be the logical library, built on a database, mysql server is a possible build up of n libraries, such as 16 libraries. If you want to split the back, is the constant between the library and the mysql server migration do it. Then the system can be configured with change it.

 

For example, you can scale up to 32 database server, each database server is a library. If not enough? It can be extended up to 1024 database server, each database server on top of a table in a library. Since 1024 up to table it.

 

Such a practice is not to write your own code to do data migration, dba have to come out well, but dba really need to do some work to migrate the database table, but better than you write code, data extraction efficiency guide data much higher.

 

Even if it is to reduce the number of libraries, but also very simple, in fact, that white is in multiples of volume reduction can be, and then modify routing rules.

 

2 ^ n for modulo

 

orderId library mold 32 =

orderId / 32 = 32 die table

 

259            3                8

1189         5                5

352            0                11

4593        17              15

 

1, setting several database servers, several libraries on each server, how many tables each library, the library is recommended is 32 * 32 tables, for most companies, it may be a few years are enough

 

2, the routing rules, the orderId die = 32 library, orderId / 32 = 32 die table

 

3, when the expansion, adding more application server databases, installed mysql, multiple expansion, four servers, servers expanded to 8, 16 servers

 

4, dba responsible for the original database server database migration to a new database server is up, a lot of tools, database migration, more convenient

 

Address 5, our side is to modify the configuration, adjustment migrated library where the database server

 

6, re-release system, on-line, the original routing rules change do not change, you can direct resources based on 2 times the database server, continue to provide services online system

Guess you like

Origin www.cnblogs.com/xiufengchen/p/11259307.html