In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "Why use message queue". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
What is Part1? Why? 1 what is a message queue
When it comes to queues in Java, you should be no stranger. It has the function of data management through first-in, first-out, or double-end access, and automatic load balancing through blocking.
Message queues are named after queues at first because of their functions and operations, which are similar to java's local queues. Therefore, we can simply think that message queue is an intermediate service to meet the data transmission, management and consumption among distributed services.
2 Why use message queuing
Q: why did you introduce message queuing into your system?
After all, we need to know the value of message queues and the actual pain points in our business scenarios in order to answer the question of why we use message queues, and to answer the value of introducing message queues into the system.
Decoupling between systems
A few days ago, we discussed the operation of advertising update with a boss who followed the official account backstage as an example:
The advertisement retrieval system needs to feel the information changes of the advertisement post to update its index, but in fact, there is no need to rely on the interface to strongly correlate the perceived behavior between the retrieval system and the delivery, materials, assets and other systems. and the way of the interface is not friendly in terms of maintenance and system pressure, then, the role of message queue is very important, each system publishes its own messages, who needs whom to subscribe. Achieving this goal does not add additional system call pressure. (note: the API call of builder is to get the latest information, which can be optimized by compression, etc.)
Therefore, when there is no real-time data interaction between systems, but their business information is still needed, message queues can be used to achieve the role of decoupling between systems. as long as the publisher defines the message queue format, any operation of the consumer can be independent of the publisher, reducing unnecessary co-tuning and release conflicts.
Service asynchronization
The most typical example is the result notification function in the payment scenario.
We know that in general, whether it is app push or SMS notification, it is a relatively time-consuming operation. Therefore, there is no need to affect the core operation of payment because of the time-consuming operation of these non-core functions. As long as we send the payment result to the message topic specified by the SMS center after the payment operation is completed, the SMS center will naturally receive the message and guarantee to notify the user.
The picture comes from Zhihu's answer.
Therefore, it is very effective to use message queue to asynchronize non-core operations and improve the efficiency and stability of the whole business link.
Cut peak and fill valley
This function makes the focus of this article. Under the impulse pressure of trillions of traffic in special scenarios such as seconds kill and Spring Festival Gala red packets, an effective means to protect the services of our system from collapse is message queuing.
Through the high-performance storage and processing capacity of the message center, the excess traffic that exceeds the processing capacity of the system is temporarily stored and released smoothly within the processing capacity of the system to achieve the effect of peak clipping.
For example, in our advertising billing system, in the face of tens of thousands of concurrent commercial post searches and thousands of concurrent clicks, the way of real-time interface must be inappropriate. After all, advertising behavior is different from payment behavior, and users who fail to pay can try again. However, users' commercial post click behavior can not be played back, and this traffic has passed. Therefore, we need to use message queues to cache deduction requests. To ensure the stability of the billing system.
Other
There are also features such as broadcast, transactional, and final consistency, which are also frequently used in message queues.
3 what are the problems with message queuing
Increase response latency in business
As mentioned earlier, message queuing asynchronizes non-core business processes, which can improve the timeliness and fluency of the entire business operation, and enhance the user operation experience. However, it is also because the data enters the queue, it will inevitably delay the speed of consumption. Cause the business to take effect in a timely manner.
For example, in the previous product recommendation, the product requirement should not appear in the recommendation list, in order to eliminate the impact of special products on the recommendation effect. In addition to the second kill, we also need to sense the goods on and off the shelves, blacklists, inventory and so on, and use multiple bit offsets in redis to maintain multiple states of a product. Then receive messages from the promotion group to change the status of goods in the recommended cache cluster, but due to the delay of the message, it may lead to untimely changes in the status of goods. However, as long as the trade-off between business and technology is acceptable, then OK.
Introduce unstable factors into the architecture
The introduction of message queue is equivalent to adding a new system to the original distributed service link, and the complexity of the system becomes larger. At the same time, the role of message queuing requires high performance and high availability.
Therefore, in the face of how to deploy a highly available stable cluster, how to retry if the message is not sent successfully, how to set the broker data synchronization policy, how idempotent the broker exception leads to message retransmission, and how to retry if the consumption is not successful, the middleware team and the business system need to work together to deal with it.
What about Part2? 4 supporting RocketMQ with double 11 zero faults for seven years
The peak of Singles' Day transactions reached 58.3W per second in 2020. RocketMQ has a lot of deep customization for Ali's trading ecology, and here we only introduce the optimizations for high availability.
Personally, push consumption mode is only suitable for scenarios where the consumption speed is much higher than the production speed. If it is a concurrent scenario with large traffic, it is still dominated by Pull consumption.
Before pull, a load balance connection is established between the broker and the client. Once the Client is occupied by the Hang, there will be no rebalance without downtime, and the queue messages associated with the client will not be consumed in time if there is an immediate downtime, resulting in a backlog. What to do: POP, a new consumption model
In POP consumption, there is no need for rebalance to allocate consumption queues. Instead, it requests all broker to get messages for consumption. Within broker, messages from its three queues are assigned to the waiting POPClient according to a certain algorithm. Even if hang appears in PopClient 2, messages from the internal queue will be consumed by Pop Client1 and Pop Client2. This avoids the accumulation of consumption. [1]
5 smooth expansion of Kuaishou trillion-level kafka cluster [2]
To achieve smoothing, you need to let producer implement partition migration without feeling.
The general principle is to synchronize the data to be migrated partition with the new partition data for a period of time until the consumer catches up with the synchronization start node, and then change the route, delete the original partition, and complete the migration.
The same idea of data synchronization is also applied to facebook's distributed queue disaster recovery scheme.
6 Optimization of kafka cache pollution by Kuaishou / Meituan [3]
The high performance of kafka comes from the support of sequential file reading and writing and operating system cache pagecache. Kafka performs very well in the scenario of single partition and single consumer. However, if there are different partition on the same machine, or even if the consumption pattern has a mixed scenario of real-time and delayed consumption, there will be competition for PageCache resources, resulting in cache pollution and affecting the processing efficiency of broker services.
Meituan to deal with real-time / delayed consumption cache pollution
The data is distributed in different devices according to the time dimension, and the near real-time data is cached in SSD, so that when there is PageCache competition, real-time consumer jobs read data from SSD, ensuring that real-time jobs will not be affected by delayed consumption jobs.
When the consumption request arrives at the Broker, the Broker directly obtains the data from the corresponding device and returns it according to the relationship between the message offset and the device it maintains, and the data read in the HDD will not be brushed back to the SSD in the read request to prevent cache pollution. At the same time, the access path is clear, and there will be no additional access overhead due to Cache Miss.
Kuaishou deals with cache pollution caused by follower data synchronization
Two objects have been introduced into broker: one is block cache; and the other is flush queue.
The write request for Producer is first written to flush queue in the form of the original message on the broker side, then the data is written to a block in block cache, and then the whole request ends. Data in flush queue is asynchronously written to disk by other threads (which goes through the page cache process). Ensure that queue is not affected by follower
Consumer first retrieves the data from the block cache and, if it hits, returns directly. Otherwise, the data is read from disk. This read mode ensures that cache miss reads of consumer are not populated with block cache, thus avoiding contamination.
Summary
We can see that the basic starting point to solve cache pollution is to disassemble tasks of different consumption speeds or different sources of data production, and divide and conquer to avoid the impact of cache on each other.
Application of 7CMQ in Red packet payment scenario [4]
The process behind the red packet operation is simplified as follows: read the balance from the An account, then subtract, and then write the result back to the An account; then remove the red packet to add to the B account and write the result to the B account.
However, due to the limited pressure that the accounting system can bear (the systems related to accounting usually affect the processing efficiency due to locks, transactions and other reasons), accounting may fail. If you follow the real-time business logic, you need to roll back the red packet removal in real time (rollback requires another addition to A's account). After the introduction of CMQ, the business link will write the failed request to CMQ, which is used by the high availability of CMQ to ensure data consistency. Until the accounting system is finally successful. It simplifies the additional system operation caused by the accounting system's accounting failure caused by the system pressure, which leads to the red packet account rollback.
This is the end of "Why use message queuing". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.