.NET Core 3.1 REST and gRPC performance testing

Seeing the Evaluating Performance of REST vs. gRPC on the little brother of Vietnam , using .NET Core 3.0, today I upgraded it to .NET Core 3.1 and also did a test. The results of the article and his blog post are The same: https://dev.to/thangchung/performance-benchmark-grpc-vs-rest-in-net-core-3-preview-8-45ak .

I wrote an article 8 years ago: WCF and ASP.NET Web API in application selection . It is now 2020, WCF is replaced by gRPC, ASP.NET Web API is replaced by ASP.NET Core Web API, and standardized REST services are provided to the outside. The use of gRPC for internal communication is also a good thing for .NET applications in the new era. Choice, similar to how the Kubernetes architecture uses the payload format for the transport protocol.

image

Let's take a look at the performance of REST and gRPC under .NET Core 3.1? Download the code from https://github.com/geffzhang/RESTvsGRPC . Install .NET Core 3.1 on the test machine.

  • REST API:
 cd RESTvsGRPC\RestAPI
 dotnet run -p RestAPI.csproj -c Release
  • gRPC API :
 cd RESTvsGRPC\GrpcAPI
 dotnet run -p GrpcAPI.csproj -c Release
  • Benchmark items:
 cd RESTvsGRPC\RESTvsGRPC
 dotnet run -p RESTvsGRPC.csproj -c Release

等待完成测试后,我们将会得到类似下面的结果,具体的结果依赖于你的测试机器配置,我使用Win10 的Surface Book 2上面完成的下面的测试结果:
image
When the amount of data returned by the interface is relatively small, the performance of REST is better than gRPC. When the amount of data becomes larger, the performance advantages of gRPC are more obvious. .NET Core 3's json has been optimized a lot, and it will make a huge difference when dealing with small data in the message payload, but in fact, for big data payload, the difference no longer exists. Overall, gRPC is still a winner in this area. I am not saying which is better than the other. What I want to say is that we need an appropriate strategy for which protocol to use in your business case. We usually use REST communication in external communication with the outside world (such as external service integration and communication with the front end), and gRPC is used for internal service communication.

references:

Guess you like

Origin www.cnblogs.com/shanyou/p/12679093.html