[Spike] First, the system design elements, from selling sick goose Speaking

Original: little sister the taste (micro-channel public number ID: xjjdog), please share, reproduced Please keep the source.

Spike, like a planned economy, the markets, and travelers in a hurry, you come to me. Bustling for a while, after leaving only a lonely deserted street.

Let us look at a story to sell geese. ↓↓↓

Just yesterday. At dawn, about five or six o'clock in the morning, several programmers wore shaggy hair from work go hand in hand. This time, the street lights are not off altogether. Several exercise grandfather, Cha Zhaoyao, leaning forward, bent into a bow.

So, in a fork in the alley hawkers sell goose, is especially conspicuous. To see a great crowd of great promise was kept in a cage, flap its wings. There are a few energetic, craned his neck forward to croak, hawkers hear upset, knock their heads use their branches.

Hawker crooked crooked mouth, and a sweep of the corner of his eye at the phone, after five sixty. At this point, all sides came up on a group of aunt, like from the ground come up the same. The beginning is also leisurely approach, and so see the cage and she has a flock of geese, it holds small bag in his hand, rushed trot.

This raging battle, and it made everyone jump, programmers have stood still. Grandpa waist not bend, and even those goose noisy, not called.

Aunt help hawkers soon have opened the cage, Burongfenshuo, laid hold of a goose's neck to drag out. Then there is another hand laid hold of the wings of the other geese. All of a sudden people are crying geese hiss, noisy, it began to snow goose feather. Soon, all the geese are in the hands of the aunt who. But there are also more did not get Mother Goose, with a handkerchief wiping away tears of remorse jealousy aside.

Aunt Wang most happy, her large hands, caught the three, two of them hapless goose she held in one hand, his neck twisted together into a root twist. There was a crush goose, goose made life aunt would not want to, but there are more aunt did not find it too.

Hawker took a deep breath, trick really works, it staged a spike, the group made a goose of the blast, a low-cost treatment instantly.

All eyes fell on the programmers hiding in the side. And others scattered about, and they put on hawkers around which a sharp-eyed, cried out: "? This geese, not xjjdog it."

"Xjjdog It is coming. Let us find a restaurant fried dough sticks, sit down and wait for me to you slowly come."

Difficulty spike

Spike, so cool words, doomed is not a small sheep, but a scourge. System difference 3w dollars and 3000w, you want to look at it?

Any unequal situation, will have a crisis, the same way for business systems. Spike system is difficult, mainly in the following points.

1, the flow rate beyond the range of the carrier
spike, as a general return 突发流量 , a normal day volume of requests, may be concentrated within a few seconds to complete. Spike scarce resources, resources can also cause a hot, people scramble in the situation. Imagine a small holiday highway toll stations, it will be able to understand how participants get nothing well done.

2, resource conflicts
if the traditional database for data storage, competition for the same resources, it will face serious lock conflicts. Through a generally upstream, faster storage top in front, which relates to the data source and target libraries synchronization problems.

From the shelves of commodity resources, to complete the spike, it will go through a brief state of chaos, data inconsistencies arise. In the case of very concentrated amount requested, it will produce concurrency issues, individual behavior and the results are unpredictable.

3, the high degree of difficulty spike demand for infrastructure and technology is relatively high, from the access layer to the cache to the storage layer, as well as security considerations, require the participation of a number of components, and each component needs to be optimized.

In short, a noisy, will eventually quiet. In order to prepare spike and hardware resources, it can not be placed there idle for it, so there will be a general resource release phase, which is something we do not do too much attention.

Three-stage business

Generally, the spike business will be divided into three stages. Among them, buying stage, we often say that the spike business.

1, the preparatory stage
in the preparation stage, in addition to hardware and software systems are ready, there will be a general warm-up on activities, Internet operators will be something similar to telephone poles small ads, and sent it wide. There was once a customer staged a spike activity, inventory 99 100 individuals involved, 99 people have 90 internal staff, embarrassed Oh.

If you have your own app, by notification, subscriptions, will achieve better results. If the goods involved more, a huge number of participants, will preprocess the data, perform warm-up ahead. Everything is ready, you can smoke a cigarette, waiting for the countdown.

2, snapping
the saying goes, one minute on stage, the audience ten years of practice. Spike start, there will be a lot of instant influx of requests, the time to perform on stage a. At this stage, each of our systems and modules, will quickly rotate up any ill-considered one point, will result in the failure of this spike activity, so a key component to ensure highly available.

3, the end of the liquidation of
the above also said that there will be a short-lived spike chaotic state. Liquidation, it is necessary to complete the final data consistency for falling action may last a lot of time. Some users may, at the moment of payment, regret, goods to be re-homing back to the warehouse. After the return of goods warehouse will generally sell again, such as train tickets, after 30 minutes you can once again grab; Some items can be locked off the shelf, lost forever.

Control theory

Here, we generally talk about the basic principles spike system constraints in terms of technology, detailed description and code, we explained in later chapters.

Data preheat

Some systems spike, probably so few items, manual entry are Wande Zhuan. For platform type, or a huge amount of users app, spike merchandise is no longer so simple.

Middle, some will merge data, or two-dimensional expansion, which is to prepare the data spike. After these data are processed, it will advance to the spike into the system for data preheating.

Whether smooth spike-stage process, to look at data preparation is reasonable.

Request bearer

This request is the outermost layer, belongs to the access layer. Do good system, it is possible to avoid most of the request in the access layer, greatly reducing the pressure of the back-end services.

Bearer connections
to the access layer, the first challenge is the number of connections. General Internet access layer, that is, lvs + nginx. Here involves the optimization of the operating system, as well as optimization for nginx itself.

Concurrent bearer for the request falls on a machine, still there is a high concurrency problems. Use the thread pool to be reasonable, how to filter the merger, there is a certain challenge.

Load balancing
request to be able to achieve true balance can not produce hot issue. For example, the nginx ip_hash, although avoid the problem of distributed session to a certain extent, but the request will be uneven.

Retry?
Do not retry configuration spike business, will aggravate the system load. Request failed? Then do it again.

System isolation
system resources occupied by business spike, and system uptime seriously unequal. If the conditions spike system hardware and service environment, to a certain degree of isolation from normal business systems. To assess in advance the pressure on other services, to avoid affecting the normal course of business.

CDN
for html, js, css, pictures and other content, take up a lot of bandwidth. If these resources are placed on your own server, it will quickly fill up the bandwidth when traffic arrives, causing the normal spike request could not be completed. CDN can effectively solve this problem. The remaining requests, is the real spike business.

Reduction request packet
to the network request packet to be heavily optimized. Can start gzip compression, compression resource itself, remove useless information request packet, the network packet streamline.

Request Interceptor

The principle of a very large spike system, is to take as many invalid request to intercept outside. Intercepting the request can be divided into upstream and intercept interception operations.

Upstream intercept
interception aspect, there is a global setting. When the system determines and reach the bottleneck stage, it can be carried out by full-service degradation limitations stream way, for some secondary services, to be blown process. For front-end, it also requires some optimization. Such as the browser cache, preventing re-entry verification, able to intercept a considerable number of requests.

Business intercept
addition to the overall limits for most requests, and users are closely related. A user may be frequently refreshed, or bypass the front-end, back-end call directly using the software interface. Illegal requests for these users, but also to intercept.

At the same time, users compete for resources, we should not wait indefinitely. For example, 100 inventory of goods, first 1w request comes, do not need to wait in line, and directly return spike finished ok.

Queuing aspect, the JVM will use line, also used external message queue, MQ, buffered request.

Data caching

Cache is probably the most important component of a spike system. Cache from the front end, to jvm cache, then distributed cache, the number of stages will produce lift on the system performance. It is noteworthy that, due to the spike system relies heavily on caching system, so the cache system availability needs to be done.

Cache read operation, to consider the load and synchronize data. Write request, you should consider merging with concurrent data write, data consistency and so on. Although the cache speed compared to DB, a lot faster, but it's always a performance bottleneck, the relevant code should focus on optimization.

Safety

Getting lower and lower the threshold of technology, second-grade students are taught swift commencement, and write a plug-in spike or something, effortlessly. Spike security system is more important, it should be said that the system and deal with money, are easy to go wrong. If you want to pull out of wool, look for marketing, business spike, to be sure.

To try to raise the threshold of cheating, such as dynamic url, cut off from the entrance to most of the attacks; verification code will only increase the cost of the attacker. Some high level of security, but also increase the risk control rules, such as the same ip request excessive ban, are not allowed to participate in the account registration date three days, spike threshold must be a member of the gold medal and so on.

I have experienced once, the other would have a numerical code addition, subtraction, scripts are written. Results spike five minutes, authentication code 12306 possessed, xjjdog directly to give up.

DB hiding behind

Spike throughout the system, the traditional DB, only dingy behind the scenes (except for a small flow rate). If I DB, will hide behind shivering.

DB data, to advance to the load system calculates spike, spike is completed, but also the messy floor and clearing data. In many scenes we've seen in the spike, even without the participation of DB, really skilled are bold.

Which come out of another question. If the cache system problems, requesting not to penetrate it? My advice is not required. Unusual request, will instantly crushed DB, resulting in a more serious data Mansian, if not done isolation, the consequences will be even more wild. Its wrong, as recognized counseling, obediently recovery disk write fault reporting it.

End

Spike, Indiana, p2p, is the creation of the Internet, pocketbook three major killers.

I would say some of the secret things. Not long ago, I had a good group of geese, the result of entering into a long blast of chicken, a few days sickly to die, and if throwing a pity. This timeline geese, but also engage in very compact.

Just yesterday, I would have released a number of low-cost Goose message to be processed. In order to allow more Aunt believe, I called in accordance with half of the market price, in fact, playing a discount can be shot (the goose that vibrato can not sell). 5:00 I will give a few quick not a goose, injected with stimulants, hope they can more than hold for a while, also took a twig knock their heads to confirm. I am not confident that this scene is dead geese are also selling out. But the death of many, after all, is not good. In order to limit the crowded, I deliberately put wire cage corner of the mouth to leak out, a lot of Aunt scratched his hand did not catch the goose, I'm not sure they are, unfortunately, or fortunately.

Who first coined the spike? Really genius. Marketing and hunger as the income tax it is intelligence. Ha ha ha ~

About the author: Little Sister taste (xjjdog), it does not allow the public a number of detours programmer. Focus infrastructure and Linux. Decade architecture, day ten billion flow, and you explore the world of high concurrency, give you a different taste. My personal micro-channel xjjdog0, welcome to add friends, further exchanges.

Guess you like

Origin juejin.im/post/5d6487dcf265da03b638ba8c