1024programmer Nginx A lightweight RPC framework that supports hundreds of billions of Weibo calls: Motan

A lightweight RPC framework that supports hundreds of billions of Weibo calls: Motan

Editor’s note: High-availability architecture sharing and dissemination of articles with typical significance in the field of architecture, this article is shared by Zhang Lei in the high-availability architecture group. For reprinting, please indicate that it is from the high-availability architecture public account “ArchNotes”.

Zhang Lei, technical expert of Sina Weibo, technical director of MotanRPC framework. Joined Sina Weibo in 2013, participated in several key projects such as Weibo RPC service and hybrid cloud as a core technical member, and is currently responsible for the maintenance and architecture improvement of the MotanRPC framework. Focus on high-availability architecture and service middleware development direction.

” In 2013, the Weibo RPC framework Motan was born in the careful design and hard work of the senior masters (Fulin, fishermen, wheat, Wang Zhe, etc.). Constantly improving, Motan has been widely used in the Weibo platform, completing nearly 100 billion calls for hundreds of services every day.” —— Zhang Lei

With the rapid development of Weibo container deployment and hybrid cloud platform, RPC is becoming more and more important in the process of micro-service, and the demand for RPC has also undergone some changes. Today I will mainly introduce Motan, the Weibo RPC framework, and some improvements to better adapt to hybrid cloud deployments.

The development and status of RPC framework

RPC (Remote Procedure Call) is a remote call protocol. Simply put, it enables applications to call remote procedures or services like calling local methods. It can be applied in many scenarios such as distributed services, distributed computing, and remote service calls. . Speaking of RPC, everyone is no stranger to it. There are many excellent open source RPC frameworks in the industry, such as Dubbo, Thrift, gRPC, Hprose and so on. The following briefly introduces the characteristics of RPC and common remote calling methods, as well as some excellent open source RPC frameworks.

Comparison of RPC and other remote calling methods

RPC, HTTP, RMI, and Web Service can complete remote calls, but the implementation methods and emphases are different.

HTTP

HTTP (HyperText Transfer Protocol) is an application layer communication protocol that uses standard semantics to access specified resources (pictures, interfaces, etc.), and the transfer server in the network can recognize the protocol content. The HTTP protocol is a resource access protocol through which remote requests can be completed and the request results returned.

the

The advantages of HTTP are simplicity, ease of use, strong comprehension, and language independence. It is widely used in remote service calls, including Weibo. The disadvantage of HTTP is that the protocol header is heavy, and generally the link from the request to the specific server is long, and there may be DNS resolution, Nginx proxy, etc.

RPC is a protocol specification. HTTP can be regarded as an implementation of RPC, and HTTP can also be applied as a transport protocol of RPC. RPC services have a relatively high degree of automation, can implement powerful service governance functions, are more friendly to language integration, and have excellent performance. Compared with HTTP, the disadvantage of RPC is that it is relatively complicated and the learning cost is slightly higher.

RMI

RMI (Remote Method Invocation) refers to the remote method invocation in the Java language. Each method in RMI has a method signature, and the RMI client and server perform remote method invocation through the method signature. RMI can only be used in the Java language, and RMI can be regarded as an object-oriented Java RPC.

Web Services

Web Service is a web-based architectural approach for publishing, querying, and invoking services, focusing on the management and use of services. Web Services generally describe services through WSDL, and use SOAP to invoke services through HTTP.

RPC is a remote access protocol, and Web Service is an architecture. Web Service can also make service calls through RPC, so Web Service is more suitable for comparison with the same RPC framework. When the RPC framework provides service discovery and management and uses HTTP as the transport protocol, it is actually a Web Service.

Compared with Web Service, the RPC framework can perform more fine-grained governance on services, including flow control, SLA management, etc., and has greater advantages in micro-service and distributed computing.

Introduction to RPC framework

The RPC protocol only specifies the point-to-point call process between Client and Server, including stub, communication protocol, RPC message parsing, etc. In practical applications, it is also necessary to consider issues such as high availability of services, load balancing, etc., so the RPC framework here It refers to the solution that can complete the RPC call. In addition to the specific implementation of the point-to-point RPC protocol, it can also include more functions such as service discovery and logout, load balancing of multiple Servers providing services, and high availability of services. The current RPC framework roughly has two different directions of focus, one focuses on service governance, and the other focuses on cross-language calls.Limit expansion of other policies.

6. It feels similar to Dubbo. The serialization protocol, communication protocol, framework module definition, architecture layering, and service grouping are all the same. It seems that it is not convenient to change the configuration from the command line. The management interface of Dubbo is very convenient. Compared with How is Dubbo lightweight? It seems that Dubbo only needs one registration center to use.

Compared with Dubbo’s layering, Motan’s module layer is simpler, without exchange and directory, etc. Motan provides some SLA policies, such as concurrency restrictions, etc.

7. If monitoring is designed, which indicators are generally involved, how to quickly find service problems?

Generally, service problems are discovered by monitoring the time-consuming, framework exceptions, and business exceptions in the statistical logs

RPC calls are counted in memory through Metric, and then output to the statistics log in a unified manner.

8. What is the reason for re-implementing a set of Dubbo, or what business needs can Dubbo not solve?

Dubbo is rich in functions, but at that time we wanted a relatively lightweight RPC framework, which was convenient for us to do some transformation and functional features suitable for our own business scenarios, so as to achieve the purpose of smooth transformation and migration of internal business. In this case, the cost of modifying on dubbo may be higher than rewriting a set. Eventually we decided to develop motan RPC. From another perspective, the choice of reuse or self-development depends on the R&D capabilities and resources of the team. We happened to have suitable engineers who were interested in doing this.

9. Does Motan support function extension?

Supports expansion via SPI

10. How does Registry ensure high availability? Are Server and Registry two-way heartbeat or one-way? Or how to ensure timely perception of the server’s online and offline status?

Registry itself needs strong disaster recovery to ensure high availability. For example, ZK and Consul both support strong disaster recovery. In addition, when Registry unfortunately hangs up all nodes, it will affect the release and logout of the service, and will not affect the normal call of the Client. Server and Registry are one-way heartbeats. There may be a delay in the perception of the server when it goes online and offline, and the client is generally on the order of seconds.

12. Can you talk about the load strategy of consistent hash in detail?

Calculate a hashcode according to the Request parameter, and request the same server every time according to the hashcode. The consistent hash strategy is mainly used in stateful RPC service scenarios, such as IM services with sessions. the

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/a-lightweight-rpc-framework-that-supports-hundreds-of-billions-of-weibo-calls-motan/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索