to enter the Internet-related company to do development work, more or less understand the distributed expansion and other content, from books to school or to, or find from your blog. But later how to use the time but rarely consider the expansion, how it easier to extend. In this paper, the expansion of the situation I encountered in practical work instantiate explained.
to say a little of the reality phenomenon, how the expansion question who is going to basically do not consider future expansion at the beginning of a new project, a group of other students to a particular asked me: Costa Rica would like to, we have a business line capacity is needed, how to do? I asked him in what way fragmentation, he told me hash modulo. I feel dizzy, this. . . Nothing good way, can only stop taking. If you can not stop taking, shift library method can only be written in pairs.
later consider expansion?
This is typical irresponsible to my years of observation of the project, the general expansion occurs after two years, and the new project if fairly successful, basically the first year to get the prize basically took that to be sure also affirmed. The third year, when the main drive is still not is hard to say, most of the initial project developers are gone. Regard the project without leaving the resale to others, while others with one week to resolve, or two months to resolve the matter to do with the original designer. Of course, except if it is dau straight up into the project, the biggest test of the ability of this initial project architect, if poorly designed, really pit yourself.
Why is difficult to reconstruct the late late?
is a continuation of the business, if it is an important business, certainly not stopped, slowly leave you out of time, you can expect the boss to solve the problem immediately. Then you say, did not consider the initial expansion. . . I first came to Beijing, was doing farm project of the two companies is the same project, the same DAU explosive growth. A company’s expansion project because it is difficult, the results a week later all users are gone, and the other company since the early architecture of easy expansion, opened a brilliant chapter.
double shift library to write, in fact, I thinkA method of comparing LOW’s lazy method is a method of picking up the pit. Speaking of the characteristics:
1. Impact interface speed, double-write undoubtedly increase the number of times of calling Redis, increase time, improve the error rate.
2. Cycle, from 4 libraries, moving hundreds of data, how long is online, whether there is a deviation in the turn of the aircraft. During a business guide data, a REDIS is hanged, causing problems in the online business.
Then there must be clear goals at the beginning of the program design:
1. DBA can be digested based on the formation of fixed instance ports. So, then the problem is good, there is no content.
We have encountered a case, DBA provides 4 ports, and then achieved by internal middleware, however, after about two years, the middleware maintainer left, this method will no longer Maintain it. After 3 years, DBA said that a single machine space is full and needs to be expanded. The RD received at this time is full of tears.
2. What you store is, according to different contents, there is a different solution, if you share the temporary data such as SESSION, then there is no doubt that Hash is the best. Solution, operation and maintenance increases a machine or reduce a machine, which will cause, some users regress in, and will not cause other issues.
If the stored user information is not casually increasing, the node is reduced, because any changes will cause loss of user information, this loss is irreversible, and cannot be resolved by registering. At this point, it is actually the same for your consistency hash, mold, or interval algorithm.
3. Expansion: The goal of expansion should be that there is no problem in solving problems and online business, this should have a maximum goal. That is, optimization is that things on the program architecture are not the product level, and should not cause fluctuations in system services.
Some need to be a client in code in codeASH, then choose the HASH algorithm is especially important. In some projects, architects use the consistent Hash algorithm to make a branch table, which really does not consider the problem of post-retarding and expansion.
The consistency hash algorithm is mainly solved from N to N-1 problem.
Combined with REDIS’s cluster architecture slot assignment ideas, I use interval algorithms in a project, the reasons are as follows: 1. A simple algorithm, such as MD5 (UID), has a total of 256 nodes of hash to 00-FF, assuming assumptions as follows: 00-3F 40-7F 80-BF C0-FF respective 4 REDIS instance abcd. At this time, if 4 Redis is full, you want to increase the port to solve the problem as soon as possible. The steps can be 2.
2. For data from 00-3F, you can take a starting from the library, the most host library. As A A1, the data in A and A1 is the same. Then modify the configuration 00-1f to a above, 20-3F to A1, so that the expansion port is completed. Then write a script, and the offline delete A falls according to the algorithm to 20-3F data, and the A1 falls according to the data of A according to the algorithm. In this way, it should be deleted quickly to the size, undoubtedly deleting data far greater than the speed of mobile writing data.
Redis cluster architecture
Schematic diagram of a consistency HASH:
In short, when you choose to service, you will choose a kind of impact on the line when you expand. It is still a way to work, according to the expansion plan that has nothing to do on the line.