This is my .NET controller:
// Change here - so it won't load every run - now we on ~200 RPS
private static readonly GrpcChannel channel = GrpcChannel.ForAddress("http://10.0.0.10:50051");
private static readonly GreeterClient clinet = new Greeter.GreeterClient(channel);
public RegularSungleThreadedController()
{
}
[HttpGet]
public async Task<IActionResult> Get()
{
var reply = await clinet.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });
return Ok(reply);
}
[ApiController]
[Route("[controller]")]
public class JustRespondController : ControllerBase
{
public JustRespondController()
{
}
[HttpGet]
public async Task<IActionResult> Get()
{
return Ok("No-Grpc");
}
}
The .net core runs in a docker, this is how it's built:
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["TestGrpcServerSpeed/TestGrpcServerSpeed.csproj", "TestGrpcServerSpeed/"]
RUN dotnet restore "TestGrpcServerSpeed/TestGrpcServerSpeed.csproj"
COPY . .
WORKDIR "/src/TestGrpcServerSpeed"
RUN dotnet build "TestGrpcServerSpeed.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "TestGrpcServerSpeed.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestGrpcServerSpeed.dll"]
This gRPC c++ server is a server from the gRPC example - no change made.
When I test JustRespond in my machine using Locust I get ~900RPS (which is slow compared to the advertise .NET 7 core performance) when I test RegularSungleThreaded I get ~200RPS (which is really slow).
There is plenty of available CPU and RAM during the tests. What do I do wrong? maybe something in .NET should be set as a multi-threaded/process and I didn't set it? the gRPC performance should be sky-rock (they advertise 30kRPS)...
------- How to reproduce this -------
.net part:
- Create a simple .net 7 in docker using the vs wizard, and copy paste the above logic in the controllers.
- Install the latest Nuget needed to run gRPC client in .net (https://learn.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-7.0&tabs=visual-studio)
- Use the simple Greeter proto from the gRPC open source (https://github.com/grpc/grpc/blob/v1.57.0/examples/protos/helloworld.proto)
The C++ gRpc part:
- Create an Ubuntu docker
- It install and runs as per the instructions here (https://grpc.io/docs/languages/cpp/quickstart/)
- You can run any of the server versions there
Tested on Intel Xeon E-2386G, 32 GB Ram and reached ~700 RPS (without gRpc we reach ~2100RPS, it's looks like .net not using all available cores in the system for some reason - in pick it was ~15% of total CPU cores)