grpc-ecosystem / grpc-spring

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

How to make of use all the CPU cores! #420

Closed vinsguru closed 4 years ago

vinsguru commented 4 years ago

First of all, Thank you so much for your contribution and It works just fine.

I have a simple client & server application. The client sends multiple requests to the server. They get processed successfully. However I never see the cpu utilization goes above 30%. Looks like it does not seem to use all the cores. The client creates a single channel and that is what used for all the communication. Is there anyway for us to make use of all the CPU cores?

ST-DDT commented 4 years ago

There aren't any built-in features for that yet.

However, you can use the built-in configurers https://yidongnan.github.io/grpc-spring-boot-starter/en/client/configuration.html#grpcchannelconfigurer

to set the EventLoopGroup (pools) for it: https://github.com/grpc/grpc-java/blob/master/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java#L234

Unfortunately, I'm not sure what the best settings are to maximize CPU usage. The grpc-java developers/SO should now best which values needs to be adjusted for max performance. If you repeat your question there or find other good configuration recommendations please link it here so I can reference it in the documentation.

vinsguru commented 4 years ago

Thanks @ST-DDT for the quick response. Sure, I will follow up with grpc-java team and update here.

vinsguru commented 4 years ago

Closing this issue as it does not seem to be related this spring boot starter. Instead grpc-java recommends to create multiple channels to increase throughput.

ST-DDT commented 4 years ago

Can you please link the upstream answer here for future reference?

suekto-andreas commented 2 years ago

@ST-DDT do u have a reference on how to ensure multiple ManagedChannel is being served via grpc-spring-boot ? A snippet on it would be much appreciated.

Microsoft has its recommendation here: https://learn.microsoft.com/en-us/aspnet/core/grpc/performance?view=aspnetcore-6.0

"Use a pool of gRPC channels, for example, create a list of gRPC channels. Random is used to pick a channel from the list each time a gRPC channel is needed. Using Random randomly distributes calls over multiple connections."

ST-DDT commented 2 years ago

do u have a reference on how to ensure multiple ManagedChannel is being served via grpc-spring-boot ?

@suekto-andreas Currently, grpc-spring-boot-starter does not provide any additional features over grpc-java in this regard.

I plan to add a placeholder for this here:

https://github.com/yidongnan/grpc-spring-boot-starter/issues/741#issuecomment-1247148603

There I would like to detach the injected stubs from the grpc-java created ManagedChannels and replace it with a dynamic reference. That reference could be used to implement some kind of round robin on the ManagedChannels.

I probably won't get to that until December, though.