Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
8 changes: 7 additions & 1 deletion frameworks/CSharp/touchsocket/Benchmarks.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 18
VisualStudioVersion = 18.0.11109.219 d18.0-oob
VisualStudioVersion = 18.0.11109.219
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketWebApi", "src\TouchSocketWebApi\TouchSocketWebApi.csproj", "{6BD9363A-D77F-5D90-8444-2BC37495C920}"
EndProject
Expand All @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketHttp31", "src\To
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketWebApi31", "src\TouchSocketWebApi31\TouchSocketWebApi31.csproj", "{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketHttpPlatform", "src\TouchSocketHttpPlatform\TouchSocketHttpPlatform.csproj", "{BC320C24-941D-2109-FBC8-92780569BBA4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,6 +35,10 @@ Global
{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}.Release|Any CPU.Build.0 = Release|Any CPU
{BC320C24-941D-2109-FBC8-92780569BBA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC320C24-941D-2109-FBC8-92780569BBA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC320C24-941D-2109-FBC8-92780569BBA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC320C24-941D-2109-FBC8-92780569BBA4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
35 changes: 33 additions & 2 deletions frameworks/CSharp/touchsocket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,40 @@

See [touchsocket](https://touchsocket.net/) for more information.

## Variants Included

* `touchsocket.webapi` (`TouchSocketWebApi`) – WebApi style.
* `touchsocket.webapi31` (`TouchSocketWebApi31`) – WebApi targeting .NET 8.
* `touchsocket.http` (`TouchSocketHttp`) – Minimal HTTP implementation.
* `touchsocket.http31` (`TouchSocketHttp31`) – Minimal HTTP targeting .NET 8.
* `touchsocket.httpplatform` (`TouchSocketHttpPlatform`) – High-performance custom pipeline-based HTTP server focusing on low-level parsing and zero-allocation response writing.

## Infrastructure Software Versions

**Language**
**Language / Runtime**

* C# / .NET (8.0 & 9.0 depending on variant)

## Endpoints

All variants implement:

* `/plaintext` – Returns a plain text "Hello, World!" response.
* `/json` – Returns a JSON object `{"message": "Hello, World!"}`.

The `httpplatform` variant manually parses request lines and headers via `System.IO.Pipelines` for maximum throughput.

## Dockerfiles

Each variant has a dedicated Dockerfile named:

* `touchsocket.dockerfile` (webapi)
* `touchsocket-webapi31.dockerfile`
* `touchsocket-http.dockerfile`
* `touchsocket-http31.dockerfile`
* `touchsocket-httpplatform.dockerfile`

## Notes

* C# 8.0
The `httpplatform` variant is intended for benchmarking raw server performance. It omits higher-level abstractions to reduce overhead.

19 changes: 19 additions & 0 deletions frameworks/CSharp/touchsocket/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@
"display_name": "touchsocket.webapi31",
"notes": "",
"versus": "aspnetcore-mvc"
},
"httpplatform": {
"plaintext_url": "/plaintext",
"json_url": "/json",
"port": 8080,
"approach": "Realistic",
"classification": "Platform",
"database": "Postgres",
"framework": "touchsocket.httpplatform",
"language": "C#",
"orm": "Micro",
"platform": ".NET",
"flavor": "CoreCLR",
"webserver": "touchsocket",
"os": "Linux",
"database_os": "Linux",
"display_name": "touchsocket.httpplatform",
"notes": "High-performance custom pipeline-based implementation variant.",
"versus": "aspnetcore"
}
}
]
Expand Down
13 changes: 13 additions & 0 deletions frameworks/CSharp/touchsocket/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,16 @@ orm = "Raw"
platform = ".NET"
webserver = "touchsocket.webapi31"
versus = "aspcore-mvc"

[httpplatform]
urls.plaintext = "/plaintext"
urls.json = "/json"
approach = "Realistic"
classification = "Micro"
database = "Postgres"
database_os = "Linux"
os = "Linux"
orm = "Raw"
platform = ".NET"
webserver = "touchsocket.httpplatform"
versus = "aspcore"
3 changes: 1 addition & 2 deletions frameworks/CSharp/touchsocket/src/TouchSocketHttp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text;
using TouchSocket.Core;
using TouchSocket.Http;
using TouchSocket.Sockets;
using HttpContent = TouchSocket.Http.HttpContent;

namespace TouchSocketHttp;
Expand All @@ -18,7 +17,7 @@ await service.SetupAsync(new TouchSocketConfig()
.SetMaxCount(1000000)
.SetTransportOption(options =>
{
options.BufferOnDemand = true;
options.BufferOnDemand = false;
})
.ConfigureContainer(a =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<ServerGarbageCollection>true</ServerGarbageCollection>
<UserSecretsId>dotnet-TouchSocketWebApi-987c185f-10b1-452b-beb6-47d798a5a131</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageReference Include="TouchSocket.Hosting" Version="4.0.0-rc.44" />
<PackageReference Include="TouchSocket.WebApi" Version="4.0.0-rc.44" />
<PackageReference Include="TouchSocket.WebApi" Version="4.0.0-rc.46" />
</ItemGroup>
</Project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// ------------------------------------------------------------------------------
// 此代码版权(除特别声明或在XREF结尾的命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://touchsocket.net/
// 交流QQ群:234762506
// 感谢您的下载和使用
// ------------------------------------------------------------------------------

using System.Buffers.Text;
using System.Diagnostics;
using TouchSocket.Core;
using TouchSocket.Sockets;

namespace TouchSocketHttpPlatform;

internal static class DateHeader
{
private const int dateTimeRLength = 29;
private const int prefixLength = 6; // "Date: ".Length is 6 in bytes for ASCII
private const int suffixIndex = dateTimeRLength + prefixLength;

// Wed, 14 Mar 2018 14:20:00 GMT
private const int suffixLength = 2; // crlf
private static readonly Timer s_timer = new((s) =>
{
SetDateValues(DateTimeOffset.UtcNow);
}, null, 1000, 1000);

private static byte[] s_headerBytesMaster = new byte[prefixLength + dateTimeRLength + 2 * suffixLength];
private static byte[] s_headerBytesScratch = new byte[prefixLength + dateTimeRLength + 2 * suffixLength];

static DateHeader()
{
var utf8 = "Date: "u8;

utf8.CopyTo(s_headerBytesMaster);
utf8.CopyTo(s_headerBytesScratch);
s_headerBytesMaster[suffixIndex] = (byte)'\r';
s_headerBytesMaster[suffixIndex + 1] = (byte)'\n';
s_headerBytesMaster[suffixIndex + 2] = (byte)'\r';
s_headerBytesMaster[suffixIndex + 3] = (byte)'\n';
s_headerBytesScratch[suffixIndex] = (byte)'\r';
s_headerBytesScratch[suffixIndex + 1] = (byte)'\n';
s_headerBytesScratch[suffixIndex + 2] = (byte)'\r';
s_headerBytesScratch[suffixIndex + 3] = (byte)'\n';

SetDateValues(DateTimeOffset.UtcNow);
SyncDateTimer();
}

public static ReadOnlySpan<byte> HeaderBytes => s_headerBytesMaster;

public static void SyncDateTimer()
{
s_timer.Change(1000, 1000);
}
private static void SetDateValues(DateTimeOffset value)
{
lock (s_headerBytesScratch)
{
if (!Utf8Formatter.TryFormat(value, s_headerBytesScratch.AsSpan(prefixLength), out var written, 'R'))
{
throw new Exception("date time format failed");
}
Debug.Assert(written == dateTimeRLength);
(s_headerBytesScratch, s_headerBytesMaster) = (s_headerBytesMaster, s_headerBytesScratch);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ------------------------------------------------------------------------------
// 此代码版权(除特别声明或在XREF结尾的命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://touchsocket.net/
// 交流QQ群:234762506
// 感谢您的下载和使用
// ------------------------------------------------------------------------------

using TouchSocket.Sockets;

namespace TouchSocketHttpPlatform;

internal sealed class MyServer : TcpService<MyTcpSessionClientBase>
{
/// <inheritdoc/>
protected override MyTcpSessionClientBase NewClient()
{
return new MyTcpSessionClientBase();
}
}
Loading
Loading