Kafka, ActiveMQ, RabbitMQ, RocketMQ there is no difference, the message queue what advantages and disadvantages

Interview questions

  • Why use a message queue?
  • Message Queue What are the advantages and disadvantages?
  • Kafka, ActiveMQ, RabbitMQ, RocketMQ what's the difference, and what scenarios fit?

Interviewer psychological analysis

In fact, the interviewer mainly want to see:

  • First , do you know how to use your system message queue this thing?
    Many candidates say in their own projects with the Redis, MQ, but in fact he did not know why they use this stuff. In fact, plainly, it is to use and use, or someone else's design architecture, he never thought about from start to finish.
    No infrastructure of their own people asked why, some people do not usually think of is, the interviewer usually very good candidate for this type of impression. Because the job interviewer worried after you stay dry into the team only Mutoumunao will not think about their own.

  • Second , since you use the message queue this thing, you know what good use & harm?
    If you have not considered this, then you get hold of MQ blindly into the system, behind you is not a problem on their own company slipped to leave the pit? If you have not considered the possible introduction of a technical drawbacks and risks, the interviewer put such candidates to recruit them, and basically probably the digging-type players. Afraid you do a bunch of pit dug year he quit, leaving the company to endless troubles.

  • Third , since you use the MQ, may be a certain kind of MQ, then you do at that time did not do the research?
    Do not racking our brains silly own personal preference on the blind with a MQ, such as Kafka, or even have never been popular industry research, which has several MQ in the end. What are the advantages and disadvantages of each MQ Yes. Each MQ is no absolute good or bad , but it is to see a scene in which you can avoid weaknesses, take advantage of their strengths and avoid their weaknesses .
    If it is not considered a candidate for selection of technical recruited into the team, leader gave him a task to design what system he used some techniques that may never have considered in the selection inside the last election and possible technical not necessarily appropriate, as is leaving pit.

Face questions analysis

Why use Message Queue

In fact, the message queue is to ask you what are the usage scenarios, then your project's what the specific scene, you talk about what is the message queue in this scene?

The interviewer ask you this question, expect an answer is, what your company has a business scenarios later, the business scenario there is any technical challenge, if not MQ can be cumbersome, but you now use the MQ brought you a lot of benefits.

Let me talk about the message queue common usage scenarios, in fact, there are a lot of scenes, but more central there are three: decoupled , asynchronous , clipping .

Decoupling

To see such a scene. A three BCD data to be sent to the system via the transmission interface calls. If the E-System have this information? If the C system that now do not need it? A person in charge of the system almost collapsed ......

)

In this scenario, A system coupled with a variety of other serious mess of the system, A system to produce a more critical data, many systems require A system to send over the data. A system should always consider if BCDE four systems linked to the country? Not to retransmit, the message they would want to save up? White hair ah!

If you are using MQ, A system generates a data sent to the MQ go inside, which system requires data inside themselves MQ consumption. If the new system requires data, it can be consumed directly from the MQ years; if a system does not require this data, the consumer can cancel it for MQ message. So down, A system simply did not need to consider who to send data, no need to maintain this code does not need to consider whether people call success, failure timeout situation.

Summary : through a MQ, Pub / Sub publish-subscribe messaging is such a model, A system just like other systems completely decoupled.

Interview Tips : You need to consider whether there is a similar scenario in charge of your system is a system or a module, called multiple systems or modules, calls between each other is very complex and cumbersome to maintain. But in fact, this call is no direct call interface synchronous, asynchronous to it if MQ and decoupling, is also possible, you need to consider in your project, is not it possible to use the MQ system of decoupled . Reflected this stuff in your resume, using MQ as decoupling.

asynchronous

Let's look at a scene, A system receives a request, it is necessary to write in his local library, but also need to write three BCD library system, the library to be 3ms own local write, write library BCD three systems are to 300ms, 450ms, 200ms. The final request total delay is 3 + 300 + 450 + 200 = 953ms, close to the 1s, the user feels put forward something, slow dead slow death. The user initiates a request through the browser, a wait 1s, which is almost unacceptable.

General Internet business class, direct manipulation for the user, the general requirement is that each request must be completed within 200 ms, the user is almost no perceptible.

If using MQ , then A system continuously sending three messages to the MQ queue, if time-consuming 5ms, a request is received from the A system to return a response to the user, the total length is 3 + 5 = 8ms, for the user to actually feel it is on the point of a button, directly returned after 8ms, cool! Website doing good, really fast!

Clipping

0:00 to day 12: 00, A calm system, the number of concurrent requests per second to 50. The result of each one to 12:00 and 13:00, the number of concurrent requests per second to 5k + suddenly surge strip. But the system is directly based on MySQL and MySQL influx of a large number of requests, about 5k per second execution of the SQL MySQL.

MySQL in general, to span 2k requests per second on the same subject, if the requests per second to 5k, it may give directly to the MySQL killed, resulting in a system crash, the user also can not re-use the system.

However, the peak period is over, in the afternoon, when it becomes low peak, may also 1w of simultaneous users on the site, the number of requests per second may also 50 requests, hardly any of the whole system pressure.

If MQ, 5k write requests per second MQ, A 2k up system requests processed per second, per second up process because the 2k MySQL. A time to slowly pull system from MQ requests per second to pull 2k request, do not exceed the maximum number of requests per second that he can handle it ok, so down, even if it is peak, and there is absolutely no A system It will hang. The MQ 5k per second requests come in, they go out of 2k request, the results lead to the noon peak period (one hour), there may be hundreds of thousands or even millions of requests backlog in the MQ.

This brief peak backlog is ok, because after the peak of the past, requests per second to 50 into the MQ, but still A system in accordance with 2k requests per second speed in the process. So, as long as the peak period is over, A system will quickly backlog of messages to get rid of.

What are the advantages and disadvantages message queue

Advantage has been said above, it is to have its corresponding benefits under the special scene , decoupling , asynchronous , clipping .

There are several disadvantages:

  • Reducing system availability
    external dependencies introduced by the system, the more easy to hang. A system call that you had three BCD system interfaces like, four people ABCD system properly, nothing issue, you add a partial MQ come in, if MQ hung up zezheng, MQ a hanging, the whole system crashes you would be finished? How to ensure high availability of the message queue

  • Consistency
    A system to process over direct return is successful, people think that you request will be successful; but the problem is that if the three systems where BCD, BD two write library system is successful, the results of C write library system failed, Zezheng? You data is inconsistent.

So the message queue is actually a very complex architecture, you introduced it has many advantages, but also have to do all kinds of additional technical solutions and architecture for the harm it brings to circumvent the fall, well after, you will find that the mother die, to enhance the complexity of the system a number of stages, the complex may be 10 times. But the key moment, use, or use statistics.

Kafka, ActiveMQ, RabbitMQ, RocketMQ what advantages and disadvantages?

characteristic ActiveMQ RabbitMQ RocketMQ Kafka
Stand-alone Throughput Ten thousand, lower than RocketMQ, Kafka an order of magnitude With ActiveMQ 100,000, supporting high throughput 100,000, high throughput, large data classes with the general system for real-time calculation data, the log collection and other scenes
The impact on throughput topic number topic can reach levels of hundreds / thousands of throughput will decrease to a lesser extent, this is RocketMQ a big advantage, in the same machine, you can support a large number of topic topic from tens to hundreds of times, throughput could drop significantly, in the same machine, Kafka try to ensure that the number of topic not too much, if you want to support a large-scale topic, need to add more machine resources
Timeliness ms level Microsecond, which is a major feature of RabbitMQ, lowest latency ms level Within ms delay stage
Availability High, based on a master-slave architecture to achieve high availability With ActiveMQ Very high, distributed architecture Very high, multiple copies of distributed data, a small number of machine downtime, no data is lost, it does not result in unavailable
Message reliability Have a lower probability of data loss Basic is not lost After parameter optimization configuration, it can do 0 loss With RocketMQ
Support functions MQ extremely functional areas of complete Based on the development of erlang, concurrency is very strong, excellent performance, low latency MQ function more perfect, or distributed, scalability Function is relatively simple, the main support simple MQ function, real-time computing, and log data collected in the field is large scale use

In summary, after all kinds of contrast, there are the following recommendations:

General business systems to be introduced MQ, the earliest we all use ActiveMQ, but now we do not much use, no proven large-scale throughput scene, the community is not very active, so we still forget it, I personally do not We recommend the use of this;

Later, it began to use RabbitMQ, but it does prevent a lot of erlang language Java engineers go in-depth study and control it, for companies, almost in an uncontrollable state, but people are really open source, relatively stable support activity also high;

But now more and more companies will indeed go with RocketMQ, really good, after all, Ali produced, but the risk community may have suddenly lost the yellow (currently RocketMQ has been donated to the Apache , but activity is actually not high on GitHub ) have their own technical strength absolutely confident, recommended RocketMQ, otherwise go back and honestly with RabbitMQ it, others have an active open source community, will not yellow.

So small and medium companies , technical strength is more general, the technical challenges are not particularly high, with RabbitMQ is a good choice; large companies , infrastructure, strong R & D strength, with RocketMQ is a good choice.

If it is a large area of data calculated in real time, log collection and other scenes, with Kafka is the industry standard and is definitely no problem, a high degree of community activists, will not yellow, not to mention the fact that almost the norm all over the world in this field.

Original Address: https: //juejin.im/post/5d79ca19e51d4561fa2ec10d

Guess you like

Origin www.cnblogs.com/jpfss/p/11511509.html