GRPC is a high-performance, open source, general-purpose RPC framework designed based on the HTTP/2 standard, bringing features such as bidirectional streaming, flow control, header compression, multiplexing requests over a single TCP connection, and more. During the development of EasyCVR video module, as the video video synthesis processing module consumes CPU performance, it is planned to deploy multiple video processing servers in distributed mode and adopt gRPC mode for communication.

GRPC protocol is supported after Nginx1.13, so we decided to use Nginx for load balancing.

The specific implementation process is as follows:

Upstream indicates the address of the upstream reverse proxy server. Server exposes the actual external port for Nginx.

The following is an example of server-side code:

The server can listen on any port and enable the service by configuring the server IP and port to the Upstream module on Nginx.

Example client code is as follows:

All the client programs here need to connect to is the port exposed by Nginx.

The execution effect is as follows:

Nginx will automatically load balance all connections based on the access weight Settings of the configuration file. Because of the uncertainty about which server RPC requests are going to, a unified file server is also required, but we won’t go into too much detail in this article.