grpc-ecosystem / grpc-spring

Spring Boot starter module for gRPC framework.
https://grpc-ecosystem.github.io/grpc-spring/
Apache License 2.0
3.48k stars 815 forks source link

How to achieve load balancing #908

Closed Layfolk-zcy closed 1 year ago

Layfolk-zcy commented 1 year ago

The postman call does not implement load balancing.The servers of both GRPCS start before the clients

image image

result is constant. image

ST-DDT commented 1 year ago

Postman doesnt need load balancing. If your call is like this Postman -RestApi-> Server -grpc-> ServerN and you want the load balancing to happen between the servers. One important thing to check is whether Server actually knows both ServerNs. You can debug that in https://github.com/yidongnan/grpc-spring-boot-starter/blob/ec610d22753dd38227c39f4d8c3ec251227e3cd7/grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/nameresolver/DiscoveryClientNameResolver.java#L309

If you have only one server there then there is an issue with the nacos registration. If two are there then this is a grpc-java behavioral question that is easier to directly ask there/upstream. Also try to execute more requests in parallel, otherwise it might try to safe connections.

result is constant.

Not sure why you added this comment. I dont expect it to differ unless you changed the implementation of one of the servers.

Does that help you?

Layfolk-zcy commented 1 year ago

Postman doesnt need load balancing. If your call is like this Postman -RestApi-> Server -grpc-> ServerN and you want the load balancing to happen between the servers. One important thing to check is whether Server actually knows both ServerNs. You can debug that in

https://github.com/yidongnan/grpc-spring-boot-starter/blob/ec610d22753dd38227c39f4d8c3ec251227e3cd7/grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/nameresolver/DiscoveryClientNameResolver.java#L309

If you have only one server there then there is an issue with the nacos registration. If two are there then this is a grpc-java behavioral question that is easier to directly ask there/upstream. Also try to execute more requests in parallel, otherwise it might try to safe connections.

result is constant.

Not sure why you added this comment. I dont expect it to differ unless you changed the implementation of one of the servers.

Does that help you?

I thought the @GrpcClient annotation would enable a custom implementation load on service instances in the nacos registry, so I sent a request through postman for a simple case test, but the request results were consistent so I raised the issue

At this time, in the example project in the source code, I directly copied a cloud-grpc-server, only modified the port number of the service, and started the two servers to register with nacos at the same time, and called the restful interface of the client through postman

ST-DDT commented 1 year ago

The @GrpcClient ist basically just a @Autowired annotation with some additional configuration from grpc.client properties for stubs and channels.

All grpc connection/load-balancing logic is provided by grpc-java and we just provide options to configure and inject them. (The DiscoveryClient lookup is also provided by this library, but it is just a lookup like DNS, the actual connection is created and handled by grpc-java)