Global Monopoly of Technology

Chapter 378 [Solutions and Quotes]

The latest website: pm.

Luo Sheng is still staying at the Bluestar Technology Group. He was going to host a technical meeting at the Azure Coast Laboratory this afternoon, but after learning that the National Railway Group came to seek technical support, he temporarily modified his work arrangement. Choose to give priority to meeting with Vice President Liu.

Mainly because the New Year is approaching, people all over the country, especially migrant workers who go out to work, are rushing to go home for the New Year. This group is very difficult. Luo Sheng feels that he can do something for them. It is also a very meaningful thing for them to buy a ticket to go home for the New Year reunion more easily.

Moreover, you can also gain a big customer.

...

At this moment, in a reception room of the company, Luo Sheng was with seven or eight people from the National Railway Group, including Vice President Liu.

After a brief meeting and a few words of greetings, Vice President Liu found the entry point of the key topic and said: "The development cost of the first phase of the 12306 ticketing system totals 300 million, including hardware. This system needs to be combined with the information database of the Ministry of Railways, and also needs to be combined. A combination of relevant data such as telephone ticketing, window ticketing, etc. 12306 is not a simple online transaction system, but the largest bulk material freight system in the country and even the world.”

After a while, one of the accompanying technical experts also said: "The 12306 technology is indeed very difficult to solve, and the existing distributed database, cache, and load balancing technologies can no longer meet the needs."

Having said that, the technical expert looked at Luo Sheng and added: "You must know that 12306 has nearly 30 billion daily visits during the Spring Festival. Such a day-level train ticket inquiry is an important factor affecting the performance of 12306. One of the reasons is that it has a high probability of accounting for more than 90% of the traffic. What is even more difficult is that the queries between peaks and valleys are very different, and there is almost no way to strike a good balance between cost and concurrency.”

Luo Sheng, who was listening, nodded silently. After the deceased finished speaking, he asked, "How did your cooperation with Ali resolve?"

The technical expert said frankly: "The current practice is to control the flow of several key entrances to ensure the availability of the system, but it will affect the user experience. The phenomenon that the website is still down and cannot be opened has been criticized."

Said that the technical plane also shook his head with a wry smile.

Vice President Liu also said: "Alibaba provides technical support to 12306 for free, but the technology is still not hard enough. We are now putting our hope in Nebula."

Luo Sheng couldn't help but smile,

He also said bluntly: "Mr. Liu, first of all, I can give you a reply for sure, the Nebula system is completely fine, and I can guarantee that within a week, I will be able to tailor a complete set of software to hardware solutions for 12306. solution, but this solution will not be supported for free like Ali.”

President Liu was dumbfounded, but also smiled, and said, "I would like to hear the details."

Luo Sheng thought for a moment, then quickly organized the language and said: "If Nebula supports the 12306 system, put the query and access of the 12306 website on Nebula. Generally speaking, the query is the most visited part of most ticketing systems, and I just listened to you. According to experts, about 90%. In the transaction-related process, query requests will be submitted many times, not to mention the additional workload brought by the emergence of a large number of ticket-sweeping software, all of which make the remaining votes The query system becomes the stress concentration of the whole system.”

"My solution is, after Nebula intervenes, separate the remaining ticket query module from the existing system of 12306, and have the ability to deploy independently; independently deploy a remaining ticket query system on the cloud, so that both 12306 and the cloud have the ability to deploy independently. A set of remaining ticket query system will make scheduling more flexible, and the scale of Nebulas cluster servers has reached more than 50,000."

Several technical experts from the railway group present also secretly smacked their lips when they heard it. No wonder Ali's "Flying" system was so unbearable. The former barely managed to break through 1,000, while the latter has reached a scale of 50,000. No wonder Luo Sheng is so good at it. confidence.

Next, Luo Sheng mainly discussed with several technical experts of the railway group.

"This morning, when I heard the news, I briefly studied the server architecture of '12306'." Luo Sheng said to everyone in an orderly manner: "The vast number of visitors are spraying, but I know that the 12306 service will be accepted as soon as it goes online for trial operation. With a QPS that cannot be surpassed by any instant kill system in the world, millions of concurrency are normal."

Several key technical personnel of the railway group present were deeply moved, and long live their understanding.

Leaders who do not understand technology are the most difficult to communicate and feel that they are not doing their best.

Luo Sheng's words still carry a lot of weight.

After a while, Luo Sheng added: "The high-concurrency system architecture should be deployed in a distributed cluster, the upper layer of the service has layer-by-layer load balancing, and various disaster recovery methods are provided. The so-called disaster recovery methods are dual-fire computer rooms and node fault tolerance. , server disaster recovery, etc. To ensure the high availability of the system, the traffic will also be balanced to different servers according to different load capacities and configuration strategies.”

"Even so, the QPS that a single machine in the cluster can withstand is very high, so how to optimize the performance of a single machine to the extreme? To solve this problem, we must first understand one thing: usually the booking system needs to deal with generating orders, reducing In the three basic stages of deduction of inventory and user payment, what the system needs to do is to ensure that the train tickets are not oversold or sold a lot, and that every ticket sold must be paid for to be valid, and also to ensure that the system can withstand extremely high Concurrent."

Several technical experts from the railway group nodded in agreement, and the technical pain point is here.

Luo Sheng continued: "Place an order to reduce inventory. When a concurrent request from a user arrives at the server, the order is first created, then the inventory is deducted, and the user is waiting for payment. This order is the first solution that most of us think of, and in this case, too It can guarantee that the order will not be oversold, but it will also cause some problems. The first is that in the case of extreme concurrency, the details of any memory operation will affect the performance, especially the logic like creating an order, which basically needs to be stored. When it comes to the disk database, the pressure on the database can be imagined, 12306 should be the Oracle database, don’t spend this unjust money, put it on my Nebula.”

"The second is that if the user places an order maliciously, only placing an order without paying will reduce the inventory and sell a lot of orders. Although the server can limit the number of IP and user purchase orders, this is not really true. A good way."

"Then there is payment to reduce inventory. If you wait for the user to pay for the order and then reduce the inventory, the first impression is that there will be no less sales. But this is a big taboo for concurrent architecture, because in the case of extreme concurrency, users may create a lot of orders. , when the inventory is reduced to zero, many users will find that the grabbed orders cannot be paid, which is the so-called 'oversold', and the concurrent operation of database disk IO cannot be avoided."

"Finally, withholding inventory. From the consideration of the above two schemes, it can be concluded that as long as an order is created, the database IO must be frequently operated. So is there a solution that does not require direct operation of the database IO? The answer is yes , that is, withholding inventory, first deducting inventory to ensure that it is not oversold, and then generating user orders asynchronously, so that the response to users will be much faster.”

"So how do you guarantee a lot of sales? What if the user gets the order and doesn't pay? The order should be valid. For example, if the user does not pay within five minutes, the order will expire and new inventory will be added. The generation of the order is asynchronous. , should be placed in the immediate consumption queue for processing..."

Vice President Liu was confused, but he found that Luo Sheng's exchanges with several technical experts he brought became more and more hot, and it seemed that he had come up with a message.

Find the right person!

At this time, Luo Sheng turned on the large screen on the wall in the room. He also brought a laptop for work and turned it on, motioning everyone to look at the main projection screen. He said while operating the computer:

"The Go language is originally designed for concurrency. I will use the Go language to demonstrate the specific process of single-machine ticket grabbing and my optimized solution."

"The init function in the Go package is executed before the main function, and some preparatory work is also done at this stage. The preparatory work that the system needs to do are: initialize the local inventory, initialize the hash key value of the remote redis storage unified inventory, initialize the redis link pool."

"In addition, an int type chan with a size of 1 needs to be initialized to realize the function of distributed locks. You can also use read-write locks or other methods such as redis to avoid resource competition, but using Channel is more efficient. This is the Go language. The philosophy of not needing to communicate through shared memory, but to share memory through communication. The Redis library uses redigo, and the following is the code:

//localSpike package structure definition

package localSpike

type LocalSpike struct {

LocalInStock int64

LocalSalesVolume int64

}

//remoteSpike's definition of hash structure and redis connection pool

package remoteSpike

//Remote order storage key value

type RemoteSpikeKeys struct {

...

...

Before I knew it, an hour and a half had passed, and Vice President Liu couldn't understand it anyway, and the codes were dizzy.

The technical issues were finally discussed.

The technical expert of the railway group looked at Vice President Liu and nodded lightly with a positive look. Vice President Liu immediately understood, and turned decisively to look at Luo Sheng and asked, "Mr. Luo, if you provide such a complete set of Perfect solution, what is the price?”

Luo Sheng said bluntly: "Pay 1 billion a year."

When Vice President Liu heard this number, he almost spit out a mouthful of blood. The budget for the first phase of the 12306 ticketing system was only 300 million yuan. Such a price was unacceptably high.

...

()

Chinese website

Chapter 389/1049
37.08%
Global Monopoly of TechnologyCh.389/1049 [37.08%]