Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frameworks/CSharp/aspnetcore/appsettings.postgresql.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"ConnectionString": "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;SSL Mode=Disable;Maximum Pool Size=18;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true;Write Coalescing Buffer Threshold Bytes=1000",
"ConnectionString": "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;SSL Mode=Disable;Maximum Pool Size=512;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this faster than a Maximum Pool Size of 256 (or 128), but with Multiplexing enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some local benchmarks and for 56 cores multiplexing is slower on dotnet.
Also got slightly better results with 512 connections in the pool. Happens to be the number of connections from wrk.

I noticed other dotnet benchmarks on TE were already doing this, I am late to the party ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, eager to see the results once this PR is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not great unfortunately, because multiplexing is supposed to make things faster, here we are just ignoring this advantage because what seems to be a lock contention at the db driver level which is exacerbated by using more cores. The good thing is that the new hardware is exposing this issue and we can work on it which will benefit everyone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @NinoFloris who is working on some stuff related to this.

Yeah, multiplexing is implemented internally via a single write loop, which we knew would be a contention bottleneck given enough cores - this seems have been reached now.

"Database": "postgresql"
}
6 changes: 3 additions & 3 deletions frameworks/CSharp/aspnetcore/aspnetcore-aot.dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
RUN apt-get update
RUN apt-get -yqq install clang zlib1g-dev
WORKDIR /app
COPY src/Platform .
RUN dotnet publish -c Release -o out /p:DatabaseProvider=Npgsql /p:PublishAot=true /p:OptimizationPreference=Speed /p:GarbageCollectionAdaptationMode=0

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
ENV URLS http://+:8080
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
ENV URLS=http://+:8080

WORKDIR /app
COPY --from=build /app/out ./
Expand Down
7 changes: 5 additions & 2 deletions frameworks/CSharp/aspnetcore/aspnetcore-minimal.dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /app
COPY src/Minimal .
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
ENV URLS http://+:8080
ENV DOTNET_GCDynamicAdaptationMode=0
ENV DOTNET_ReadyToRun=0
ENV DOTNET_HillClimbing_Disable=1

WORKDIR /app
COPY --from=build /app/out ./
Expand Down
7 changes: 5 additions & 2 deletions frameworks/CSharp/aspnetcore/aspnetcore-mvc.dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /app
COPY src/Mvc .
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
ENV URLS http://+:8080
ENV DOTNET_GCDynamicAdaptationMode=0
ENV DOTNET_ReadyToRun=0
ENV DOTNET_HillClimbing_Disable=1

WORKDIR /app
COPY --from=build /app/out ./
Expand Down
7 changes: 5 additions & 2 deletions frameworks/CSharp/aspnetcore/aspnetcore-mysql.dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /app
COPY src/Platform .
RUN dotnet publish -c Release -o out /p:DatabaseProvider=MySqlConnector

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
ENV URLS http://+:8080
ENV DOTNET_GCDynamicAdaptationMode=0
ENV DOTNET_ReadyToRun=0
ENV DOTNET_HillClimbing_Disable=1

WORKDIR /app
COPY --from=build /app/out ./
Expand Down
9 changes: 6 additions & 3 deletions frameworks/CSharp/aspnetcore/aspnetcore.dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /app
COPY src/Platform .
RUN dotnet publish -c Release -o out /p:DatabaseProvider=Npgsql

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
ENV URLS http://+:8080
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
ENV URLS=http://+:8080
ENV DOTNET_GCDynamicAdaptationMode=0
ENV DOTNET_ReadyToRun=0
ENV DOTNET_HillClimbing_Disable=1

WORKDIR /app
COPY --from=build /app/out ./
Expand Down
8 changes: 4 additions & 4 deletions frameworks/CSharp/aspnetcore/src/Minimal/Minimal.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<UserSecretsId>38063504-d08c-495a-89c9-daaad2f60f31</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Npgsql" Version="8.0.3" />
<PackageReference Include="Dapper" Version="2.1.21" />
<PackageReference Include="RazorSlices" Version="0.7.0" />
<PackageReference Include="Npgsql" Version="8.0.5" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="RazorSlices" Version="0.8.1" />
</ItemGroup>

</Project>
14 changes: 6 additions & 8 deletions frameworks/CSharp/aspnetcore/src/Minimal/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Text.Encodings.Web;
using System.Text.Unicode;
using Microsoft.AspNetCore.Http.HttpResults;
using RazorSlices;
using Minimal;
using Minimal.Database;
using Minimal.Models;
using System.Text.Encodings.Web;
using System.Text.Unicode;

var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -36,14 +34,14 @@

app.MapGet("/db", async (Db db) => await db.LoadSingleQueryRow());

var createFortunesTemplate = RazorSlice.ResolveSliceFactory<List<Fortune>>("/Templates/Fortunes.cshtml");
var htmlEncoder = CreateHtmlEncoder();

app.MapGet("/fortunes", async (HttpContext context, Db db) => {
var fortunes = await db.LoadFortunesRows();
var template = (RazorSliceHttpResult<List<Fortune>>)createFortunesTemplate(fortunes);
template.HtmlEncoder = htmlEncoder;
return template;
var result = Results.Extensions.RazorSlice<Minimal.Slices.Fortunes, List<Fortune>>(fortunes);
result.HtmlEncoder = htmlEncoder;

return result;
});

app.MapGet("/queries/{count?}", async (Db db, string? count) => await db.LoadMultipleQueriesRows(count));
Expand Down
6 changes: 3 additions & 3 deletions frameworks/CSharp/aspnetcore/src/Mvc/Mvc.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<UserSecretsId>574ff97c-fe74-4b0d-af25-8d7200a036f5</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Npgsql" Version="8.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0-rc.2" />
<PackageReference Include="Npgsql" Version="8.0.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0-rc.2" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions frameworks/CSharp/aspnetcore/src/Platform/Platform.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsTestAssetProject>true</IsTestAssetProject>
<LangVersion>preview</LangVersion>
Expand All @@ -19,9 +19,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Npgsql" Version="8.0.3" />
<PackageReference Include="MySqlConnector" Version="2.3.1" />
<PackageReference Include="Dapper" Version="2.1.21" />
<PackageReference Include="Npgsql" Version="8.0.5" />
<PackageReference Include="MySqlConnector" Version="2.3.7" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="RazorSlices" Version="0.7.0" Condition="$(PublishAot) != 'true'" />
Copy link
Contributor

@n-stefan n-stefan Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the RazorSlices version be 0.8.1, like in Minimal.csproj?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet ... 0.8.1 doesn't support IBufferWriter anymore, I have started a PR to add the support back. So for now I stay on this previous version. The newer version will also allow us to remove conditional directives for AOT.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

</ItemGroup>

Expand Down
1 change: 0 additions & 1 deletion frameworks/CSharp/aspnetcore/src/Platform/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public static IWebHost BuildWebHost(string[] args)
#if DEBUG
.AddUserSecrets<Program>()
#endif
.AddEnvironmentVariables()
.AddEnvironmentVariables()
.AddCommandLine(args)
.Build();
Expand Down
Loading