Now there are many complete open source rpc architectures. If you want to understand how the program can run efficiently and stably, it is necessary to understand the process of rpc establishment. The self-construction process can be roughly divided into two parts, the communication part and the coordination part.
The communication part includes the server and the client. The server listens to the agreed port and waits for connection. The client establishes a link with the server. For efficient information transmission, data needs to be serialized before transmission and deserialized after reception.
With the above two requirements, summarize some server and client functions.
Server functions can include: listening to ports, responding to connection requests, receiving data packets, parsing data packets, calling response methods, assembling request processing result data packets, and sending result data packets; client functions can include: establishing Connect, assemble data, send data packets, receive processing result data packets, parse data packets and return results.
This completes a simple rpc function.
As a production-level product, only core communication functions are not enough. Coordination and management functions are also needed to make the functions run stably and efficiently.
A connection pool is needed to speed up link establishment. Consumers deployed in clusters need load balancing. Nodes in the cluster need routing management. Service status needs to be maintained at all times and erroneous nodes need to be eliminated. Graceful shutdown is required to avoid messages caused by restarts. Lost, requiring overload protection, discarding timeout requests, etc.
Okay, to sum up the above, let’s summarize the functional requirements of consumers and producers.
Consumers can have: connection management, load balancing, request routing, timeout processing, health check; producers can have: thread pool, timeout discard, graceful shutdown, overload protection.
The above is a summary of the functions required for self-built rpc. If there are any omissions, please feel free to add them.
Related recommendations: "java video tutorial"
The above is the detailed content of What functions are needed to build a self-built RPC?. For more information, please follow other related articles on the PHP Chinese website!