Using ELB to Distribute gRPC Requests to Improve Concurrency Efficiency
Scenarios
gRPC is an open-source remote procedure calls (RPC) framework for building high-performance, low-latency, language-agnostic APIs for distributed systems, such as microservice communication and mobile applications. You can use an HTTPS listener of a load balancer to distribute gRPC requests across backend servers in a gRPC backend server group. This helps you use gRPC and HTTP/2 multiplexing to improve the throughput efficiency.
Solution Architecture
If your company deploys a gRPC application on an ECS in a region and creates a load balancer in the VPC where the ECS is running, you can add an HTTPS listener to the load balancer, create a gRPC backend server group, and add the ECS to this backend server group. Then the load balancer can route gRPC requests to this ECS, which processes these requests and returns responses back to clients.

Preparations
- There is a dedicated load balancer with an EIP bound to it. If there is not, you can buy one and bind an IPv4 EIP to the load balancer.
- You have either purchased a certificate or uploaded a third-party certificate to SSL Certificate Manager (SCM), and configured a public domain name for the certificate. It is recommended that you purchase an SSL certificate on the CCM console.
- You have purchased an ECS (ECS01) and deployed a gRPC application on it. For more information about gRPC, see What Is gRPC?
Procedure

Step 1: Create a gRPC Backend Server Group
- Go to the backend server group list page.
- Click Create Backend Server Group in the upper right corner.
- Configure the parameters based on Table 1 and retain the default values for other parameters.
Table 1 Parameters required for configuring a routing policy Parameter
Example Value
Description
Backend Server Group Name
server_group_gRPC
Specifies the name of the backend server group.
Type
Dedicated
Specifies the type of the load balancer that can use the backend server group.
Load Balancer
Associate existing
Specifies whether to associate a load balancer now.
Click Associate existing and select a load balancer you have created.
Backend Protocol
GRPC
Specifies the protocol that backend servers in the backend server group use to receive requests from the listeners.
Select GRPC.
Load Balancing Algorithm
Weighted round robin
Specifies the load balancing algorithm used by the load balancer to distribute traffic.
Weighted round robin: Requests are routed to different servers based on their weights. Backend servers with higher weights receive proportionately more requests, whereas equal-weighted servers receive the same number of requests.
For more information, see Load Balancing Algorithms.
- Click Next to add backend servers and configure health check.
- Click Add Cloud Server, select ECS01, set a service port, and retain the default values for other parameters.
The service port must be the same as the port used by the gRPC service. The security group of the backend server must allow traffic over this port.
- Enable health check and retain the default values for other health check parameters.
- Click Next.
- Confirm the configurations and click Create Now.
Step 2: Add an HTTPS Listener
- Go to the load balancer list page.
- Locate the target load balancer and click Add Listener in the Operation column.
- On the Add Listener page, set Frontend Protocol to HTTPS and enable HTTP/2 in Advanced Settings (Optional).
Figure 3 Configuring one-way authentication for an HTTPS listenerFigure 4 Enabling HTTP/2
- Click Next: Configure Request Routing Policy and select Use existing for Backend Server Group. Select the gRPC backend server group created in Step 1 and click Next: Confirm.
- Confirm the configurations and click Submit.
Step 3: Configure Domain Name Resolution
You can add an A record set to resolve the domain name to the public IP address of the load balancer so that clients can access the load balancer using the public domain name.
The following provides an example for resolving a website domain name to an IPv4 address. For details about how to configure an A record set, see Routing Internet Traffic to a Website.
- Go to the DNS console.
- In the navigation pane on the left, choose Public Zones.
The zone list is displayed.
- Locate the public zone and click Manage Record Sets in the Operation column.
- Click Add Record Set.
- Configure the parameters based on Table 2.
Table 2 Parameters for adding an A record set Parameter
Example Value
Description
Type
A – Map domains to IPv4 addresses
Type of the record set. In this example, set it to A - Map domains to IPv4 addresses.
Name
www
Prefix of the domain name to be resolved.
Line
Default
Resolution line. The DNS server will return the IP address of the specified line, depending on where end users come from.
The default value is Default.
Default: returns the default resolution result irrespective of where the visitors come from.
TTL (s)
300
Cache duration of the record set on a local DNS server, in seconds.
In this example, the default value 300 is used.
Value
192.168.12.2
IPv4 addresses mapped to the domain name. In this example, set this parameter to the EIPs bound to the load balancer.
Advanced Settings (Optional)
-
Click
to expand the advanced settings, set the alias and weight of the record set, and add a description and tags. In this example, the default settings are used.
- Click OK.
- Switch back to the Record Sets tab.
The added record set is in the Normal state.
Step 4: Verify the gRPC Service Connectivity
After the preceding operations are done, the client can access the gRPC service deployed on the backend server through the load balancer. The browser cannot natively support the gRPC protocol's data frame format. You can perform the following steps to test the connectivity between the client and the gRPC service:
- Remotely log in to the service ECS from the client ECS.
Multiple methods are available for logging in to an ECS. For details, see Logging In to an ECS.
- Install grpcurl, a command-line tool for interacting with gRPC service, on the client.
- Install the grpcurl software package using the following ways:
- Run the yum command to install the grpcurl software package.
yum install grpcurl
- Manually install the grpcurl software package of a specific version.
rpm -ivh grpcurl_1.9.3_linux_386.rpm
- Run the yum command to install the grpcurl software package.
- Verify the installation.
grpcurl --version
Figure 5 Verifying the installation
- Install the grpcurl software package using the following ways:
- Run the following command on the client to access the gRPC service on the backend server:
grpcurl -insecure -proto <.proto-file> <domain-name>:<listening-port> <gRPC-service-name>/<method>
If information similar to the following is displayed, the client can access the backend server where the gRPC service is deployed through ELB.
Figure 6 Verifying the access to the gRPC service
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot