Evaluating Performance of REST vs. gRPC

What is gRPC?

Benchmark Constraints

  • Test pure communication throughput, and not involve any business logic in the process. I felt that would take away the focus from the main point.
  • Not to have any Database connectivity and instead mock the data with Static fields. Thus eliminating caching issues and random execution time skews.
  • Disable logging so it will not have any impact on the test runs. If not, it could’ve led to highly misleading readings.

Project Structure

  • ModelLibrary contains the REST & GRPC related models. Also to make the test cases more generalized, I’ve chosen a data set which includes string, int, double & date time. The NASA meteorite landings data set of 1000 data points found at https://data.nasa.gov/resource/y77d-th95.json.
Sample Data Point of NASA’s meteorite landings
Protocol Buffer Definition for Messages
Protocol Buffer Definition for Services
  • RestAPI contains the WebAPI which exposes the following three methods targeting three specific scenarios, receiving a small payload, receiving a large payload & sending a large payload
ASP.NET MVC Core WebAPI routes
Decrease Logging verbosity for ASP.NET MVC Core WebAPI
  • GrpcAPI contains the Service Implementation and some bootstrap code to startup the gRPC Server. It was interesting for me to also test how gRPC streaming compares to REST, so I’ve also implemented an extra method “GetLargePayload” which iterates and streams one data point at a time
GrpcAPI Service Implementation
  • RESTvsGRPC contains the Benchmark harness which calls all these methods in two batches of 100 & 200 iterations each to reduce measurement inaccuracies of small execution times. So the below benchmark execution times are actually multiplied by 100 & 200 times the real value.
RESTvsGRPC Benchmark Harness

Benchmark Results

Benchmark Summary on Linux
Benchmark Summary on Windows
REST vs GRPC Performance

Try it out

Start the RestAPI: dotnet run -p RestAPI -c Release
Start the GrpcAPI: dotnet run -p GrpcAPI -c Release
Start the Benchmark: dotnet run -p RESTvsGRPC -c Release

My personal take away

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ruwan Fernando

Ruwan Fernando

55 Followers

Coding Enthusiast | Electronics Hobbyist | Dreamer | Online Gamer