The guest is introduced

Schod shi, several people cloud CTO

Responsible for research and development and architecture design of Shurenyun. Focus areas include Docker, Mesos clustering, cloud computing and more. Xiao was the Team Leader of Red Hat EngineeringService internal tool group.

Below are a few people cloud “high concurrency” speech transcript

1. Dealing with megapixels is more than just writing good code

Let me start by saying that a million concurrent seckill is not something that can be done by writing good code. The most important thing is to constantly optimize. Today I will talk about how to use Go language to do seckilling. We will not talk about optimization.

What I want to share with you today is whether we can build a system that can support millions of concurrent applications by using public cloud hosts without optimization.

  • Use Go to write SEC kill. As people work long hours, they all have their own architecture in mind. This architecture diagram is the idea of cloud of several people. With the help of many third-party resources, the static part must be carried by CDN. If security cannot be solved, third-party services will be used to solve the problem. Millions of concurrent no matter how to optimize, with CDN again how to block, a million concurrent have to catch. If you can’t catch it, you can’t do it. We recommend using Go.

  • A quick kill is a trick. Shaoxia is different from Double eleven and Double Twelve. The most critical technology of Singles’ Day is to receive 100 million requests for 100 million requests, and to process all the requests until the payment stage. However, there is a trick in the second kill. After receiving 1 million requests, only 1000 requests can be put in. All the previous requests can be forwarded to the CDN.

If we write a second kill system with Go, the most important thing we care about is to write a Proxy, write a Queue Manager.

2. Why do you use “Go” to write “Secakill”?

  • Why do we write SEC kill in Go and not in another language? Because one of the advantages of writing in Go is that the Go language naturally supports high concurrency, supports multi-threaded concurrency management. Many other languages don’t support it and you need to write it yourself, such as writing a highly concurrent program in Java. Many details need to be handled by yourself. When you write in Go, you don’t have to do it. Go does it for you. High concurrency has its own principles, its own best practices. If you don’t have many years of experience, how to maintain multi-threaded mutex operation under high concurrency, I personally feel that programmers can write high concurrency programs with tools why not? The nice thing about using Go is that we only write logical stuff, high concurrency stuff with Go’s Goroutine.

  • Go first has a goroutine concept, which is to put high concurrency requests into a Go Channel for asynchronous processing. In the past, to maintain the high concurrency request processing situation, you need to write, but if you use Go language, only need a grammar, can completely connect all the logic, this is a big change, this is the simplest part of Go language, is also its power.

3. How can we play with high concurrency in cloud computing era?

Originally write high concurrency program, the first need to have a very high configuration of the machine, 10 gigabit network card, but to the era of cloud computing how we play high concurrency, I give you a new idea.

  • First, use standard machine, 2 Core CPU, 4 gb memory, CPU or virtual. In addition, tell you that the public cloud is the most obvious one of the characteristics, are 100 mbit/s, gigabit network card, you want to buy a 10 MBIT/s virtual network card, no. After using Apache AB, the average machine can handle 10,000 concurrent requests, but after adding back end transactions, 1,000 concurrent requests is actually its best capacity, because there is still room to expand. In other words, give it a baseline and let it do 1000 concurrent requests.

  • Second, dynamic request capacity to plan well, a host is not enough to make thousands of, still can support millions, this is a plan I do. Instead of starting from scratch, we can find a ready-made Circuit Breaker program to write this program. After the design is finished, the biggest situation in Go is that there will be emergencies during activities, so a Circuit Breaker mechanism needs to be added. It’s like the stock market. It just got stuck. The Go language supports high concurrency, but it has yet to beat Openresty/Nginx in dynamic request performance. But that doesn’t matter, the Go language is evolving all the time, and it’s currently powerful enough to be a split-kill system. Let’s talk about the cost of seckilling.

4. How do you view the cost of second kill?

Next to show you our cost, think carefully, buy 1000 machines as long as 500 pieces, bandwidth, why use public network bandwidth 20 MB, is a skill, an hour also want 3000 pieces, load balancing two 318 yuan an hour, which has hidden meaning.

  • Coordinate limited resources. First of all, if you are given 500 yuan to open 1000 virtual machines, you cannot open them. You have to find the salesman of IaaS manufacturer, and you tell him that you need cooperation. There are a lot of industry rules, I can only say that in fact, our current network environment, all resources are limited. If IaaS wants to make money, it must find more users to sell the resource, rather than having all the resources in one place.

  • Let IaaS vendors stream dynamic requests. It’s a big loss for IaaS to buy a whole bunch of machines with 2 Core CPUS and 4 gigabytes of memory, because it’s so cheap, but the real money he makes is 64 GIGABytes, and the higher the better. He can oversell because his network card is a gigabit, so you can’t use all 64 gigabytes of resources. Ali is gigabit at most, and a real network card is a gigabit. IaaS has an ELB, and ELB can stream dynamic requests. Let him stream, and then stream it to the bottom, and then get a thousand requests, and that’s the idea of divide and conquer.

  • The most expensive for high-concurrency activities is bandwidth. To sum up, the most expensive thing to do for a million concurrent campaign is bandwidth. And that’s not even taking into account DDoS money, security money like CC, which is mostly spent on traffic, which is a cost bottleneck at the moment.

  • Catch the request put in by the Proxy, and then put it into the queue to send red packets

Architecture has caught millions of orders, caught and did not solve the second step of the problem, that is, how to send a red envelope, to a queue inside, the queue is a skill, that is, after the first to give him a page queue, there is a direct hair.

These two ways are actually a kind of activity planning, with technology should not have much of a positive or negative relationship, direct red envelope effect may be better. So it’s best to keep it all in ram, not on your local hard drive.

Because here, there is no high concurrency, to deal with is logic, the customer may say, you give me the winning rate to improve a little, or can give me a dynamic adjustment, we remember, a million concurrent time a total of one second, haven’t you adjusted it, it is over, because the second kill activity is really fast.

Stability is the most important thing, and this piece of Go will take care of that.” Write a Web Server using a Go framework. Remember that just because a program runs, it doesn’t mean it’s stable. There are two in total, one is CountDown time, one is CountDown to the beginning of the operation, the program is finished and a Queue, Queue is the number of CountDown to release, this is the current most mature solution, of course, this can not be compared with the previous jingdong, Yirendai these big factories, Let’s just say MVP startup, better use the most mature plan.

Because sometimes it lands. We don’t really want it to land, but it’s always best to use up memory. How much can a single Redis run on a 2 Core CPU / 4 gb RAM machine? 60k concurrency is no problem, I let it run 60k because it is cheap, 1000 machines only 500 bucks per hour. And of course this is the theoretical value. If you were offered $500 to go to an IaaS dealer and buy 1,000 machines, you wouldn’t be able to buy them.

Regardless of whether you use scripts or various distributed architectures, when it comes to cloud computing, you are recommended to use distributed clusters, which is used because doing an activity is fast. The cloud control program has no problem on any IaaS, and the cluster is managed by starting the deployment control software directly. The stability of Queue Manager is basically encapsulated by Docker. After encapsulation, it is quickly published to multiple instances in the cluster to be fault-tolerant and stable.

  • Cluster management is fault tolerant and can automatically load and restart services after death, plus some monitoring events. You know when you’re dead and when you’re alive.
  • In case of emergency, it can automatically expand capacity, which is unimaginable. But now, thanks to cloud computing, we finally have the opportunity to do just that. Originally also want to buy a machine, now there is a cloud host can try, this is what I want to do, this is our number of cloud seconds kill environment reference.

Seckill is fast, thank you!