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
16 changes: 14 additions & 2 deletions frameworks/CSharp/touchsocket/Benchmarks.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31717.71
# Visual Studio Version 18
VisualStudioVersion = 18.0.11109.219 d18.0-oob
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketWebApi", "src\TouchSocketWebApi\TouchSocketWebApi.csproj", "{6BD9363A-D77F-5D90-8444-2BC37495C920}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketHttp", "src\TouchSocketHttp\TouchSocketHttp.csproj", "{A7FB43AB-672B-8854-68D7-C2B383B0BC04}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketHttp31", "src\TouchSocketHttp31\TouchSocketHttp31.csproj", "{DE261A06-A254-FD54-4ACF-EE4D4352BA77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketWebApi31", "src\TouchSocketWebApi31\TouchSocketWebApi31.csproj", "{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +25,14 @@ Global
{A7FB43AB-672B-8854-68D7-C2B383B0BC04}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7FB43AB-672B-8854-68D7-C2B383B0BC04}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7FB43AB-672B-8854-68D7-C2B383B0BC04}.Release|Any CPU.Build.0 = Release|Any CPU
{DE261A06-A254-FD54-4ACF-EE4D4352BA77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE261A06-A254-FD54-4ACF-EE4D4352BA77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE261A06-A254-FD54-4ACF-EE4D4352BA77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE261A06-A254-FD54-4ACF-EE4D4352BA77}.Release|Any CPU.Build.0 = Release|Any CPU
{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
41 changes: 40 additions & 1 deletion frameworks/CSharp/touchsocket/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"port": 8080,
"approach": "Realistic",
"classification": "Fullstack",
"database": "Postgres",
"framework": "touchsocket.webapi",
"language": "C#",
"orm": "Raw",
Expand Down Expand Up @@ -38,7 +39,45 @@
"display_name": "touchsocket.http",
"notes": "",
"versus": "aspnetcore"
},
"http31": {
"plaintext_url": "/plaintext",
"json_url": "/json",
"port": 8080,
"approach": "Realistic",
"classification": "Micro",
"database": "Postgres",
"framework": "touchsocket.http31",
"language": "C#",
"orm": "Micro",
"platform": ".NET",
"flavor": "CoreCLR",
"webserver": "touchsocket",
"os": "Linux",
"database_os": "Linux",
"display_name": "touchsocket.http31",
"notes": "",
"versus": "aspnetcore"
},
"webapi31": {
"plaintext_url": "/plaintext",
"json_url": "/json",
"port": 8080,
"approach": "Realistic",
"classification": "Fullstack",
"database": "Postgres",
"framework": "touchsocket.webapi31",
"language": "C#",
"orm": "Raw",
"platform": ".NET",
"flavor": "CoreCLR",
"webserver": "touchsocket",
"os": "Linux",
"database_os": "Linux",
"display_name": "touchsocket.webapi31",
"notes": "",
"versus": "aspnetcore-mvc"
}
}
]
}
}
26 changes: 26 additions & 0 deletions frameworks/CSharp/touchsocket/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,29 @@ orm = "Raw"
platform = ".NET"
webserver = "touchsocket.http"
versus = "aspcore"

[http31]
urls.plaintext = "/plaintext"
urls.json = "/json"
approach = "Realistic"
classification = "Micro"
database = "Postgres"
database_os = "Linux"
os = "Linux"
orm = "Raw"
platform = ".NET"
webserver = "touchsocket.http31"
versus = "aspcore"

[webapi31]
urls.plaintext = "/plaintext"
urls.json = "/json"
approach = "Realistic"
classification = "Fullstack"
database = "Postgres"
database_os = "Linux"
os = "Linux"
orm = "Raw"
platform = ".NET"
webserver = "touchsocket.webapi31"
versus = "aspcore-mvc"
9 changes: 4 additions & 5 deletions frameworks/CSharp/touchsocket/src/TouchSocketHttp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class Program
{
private static async Task Main(string[] args)
{
int port = 8080;
MyHttpService service = new MyHttpService();
var port = 8080;
var service = new MyHttpService();

await service.SetupAsync(new TouchSocketConfig()
.SetListenIPHosts(port)
Expand All @@ -22,7 +22,6 @@ await service.SetupAsync(new TouchSocketConfig()
options.SendPipeOptions = TransportOption.CreateSchedulerOptimizedPipeOptions();
})
.SetMaxCount(1000000)
.SetBacklog(1000)
.ConfigureContainer(a =>
{
a.AddConsoleLogger();
Expand Down Expand Up @@ -52,8 +51,8 @@ internal sealed class MyHttpSessionClient : HttpSessionClient

protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
{
HttpRequest request = httpContext.Request;
HttpResponse response = httpContext.Response;
var request = httpContext.Request;
var response = httpContext.Response;

switch (request.RelativeURL)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.Worker">

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

<ItemGroup>
<PackageReference Include="TouchSocket.Http" Version="4.0.0-beta.80" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageReference Include="TouchSocket.Hosting" Version="4.0.0-beta.120" />
<PackageReference Include="TouchSocket.WebApi" Version="4.0.0-beta.120" />
</ItemGroup>
</Project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
99 changes: 99 additions & 0 deletions frameworks/CSharp/touchsocket/src/TouchSocketHttp31/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System.Text;
using TouchSocket.Core;
using TouchSocket.Http;
using TouchSocket.Sockets;
using static System.Net.Mime.MediaTypeNames;
using HttpContent = TouchSocket.Http.HttpContent;

namespace TouchSocketHttp;

public class Program
{
static async Task Main(string[] args)
{
int port = 8080;

Console.WriteLine(DateHelper.DateString);
var service = new MyHttpService();

await service.SetupAsync(new TouchSocketConfig()
.SetListenIPHosts(port)
.SetNoDelay(true)
.SetMaxCount(1000000)
.ConfigureContainer(a =>
{
a.AddConsoleLogger();
}));

await service.StartAsync();
service.Logger.Info($"server is started,port:{port}");
while (true)
{
Console.ReadLine();
}
}
}

sealed class MyHttpService : HttpService<MyHttpSessionClient>
{
protected override MyHttpSessionClient NewClient()
{
return new MyHttpSessionClient();
}
}

sealed class MyHttpSessionClient : HttpSessionClient
{
private readonly HttpContent m_contentPlaintext = new StringHttpContent("Hello, World!", Encoding.UTF8, $"text/plain");
private readonly HttpContent m_contentJson = new StringHttpContent("{\"message\":\"Hello, World!\"}", Encoding.UTF8, $"application/json");

protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
{
var request = httpContext.Request;
var response = httpContext.Response;

switch (request.RelativeURL)
{
case "/plaintext":
{
response.StatusCode = 200;
response.StatusMessage = "success";
response.Headers.Add(HttpHeaders.Server, "T");
response.Headers.Add(HttpHeaders.Date, DateHelper.DateString);
response.Content = m_contentPlaintext;
await response.AnswerAsync().ConfigureAwait(false);
}
break;
case "/json":
{
response.StatusCode = 200;
response.StatusMessage = "success";
response.Headers.Add(HttpHeaders.Server, "T");
response.Headers.Add(HttpHeaders.Date, DateHelper.DateString);
response.Content = m_contentJson;
await response.AnswerAsync().ConfigureAwait(false);
}
break;
default:
response.SetStatus(404, "not find");
await response.AnswerAsync().ConfigureAwait(false);
break;
}
}
}

static class DateHelper
{
static Timer m_timer;
static DateHelper()
{
DateString = DateTime.UtcNow.ToGMTString();
m_timer = new Timer((state) =>
{
DateString = DateTime.UtcNow.ToGMTString();
}, null, 0, 1000);
}

public static string DateString { get; private set; }
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<!--<PublishAot>true</PublishAot>-->
<UserSecretsId>dotnet-TouchSocketWebApi-987c185f-10b1-455b-beb6-47d798a5a131</UserSecretsId>
<ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="TouchSocket.Http" Version="3.1.0" />
</ItemGroup>
</Project>
26 changes: 10 additions & 16 deletions frameworks/CSharp/touchsocket/src/TouchSocketWebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public static void Main(string[] args)
options.SendPipeOptions = TransportOption.CreateSchedulerOptimizedPipeOptions();
})
.SetMaxCount(1000000)
.SetBacklog(1000)
.ConfigureContainer(a =>
{
a.AddConsoleLogger();
Expand All @@ -36,28 +35,23 @@ public static void Main(string[] args)
})
.ConfigurePlugins(a =>
{
a.UseTcpSessionCheckClear();

a.UseWebApi()
.ConfigureConverter(converter =>
a.UseWebApi(options =>
{
converter.Clear();
converter.AddSystemTextJsonSerializerFormatter(options =>
options.ConfigureConverter(converter =>
{
options.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
converter.Clear();
converter.AddSystemTextJsonSerializerFormatter(jsonOptions =>
{
jsonOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
});
});
});

#if DEBUG
a.UseSwagger()
.UseLaunchBrowser();
#endif

a.UseDefaultHttpServicePlugin();
});
});

IHost host = builder.Build();
var host = builder.Build();
host.Run();
}
}
Expand All @@ -72,7 +66,7 @@ public partial class ApiServer : SingletonRpcServer
[WebApi(Method = HttpMethodType.Get)]
public async Task Plaintext(IWebApiCallContext callContext)
{
HttpResponse response = callContext.HttpContext.Response;
var response = callContext.HttpContext.Response;
response.SetStatus(200, "ok");
response.Content = m_contentPlaintext;
await response.AnswerAsync().ConfigureAwait(false);
Expand All @@ -86,7 +80,7 @@ public MyJson Json()
}
}

[JsonSerializable(typeof(MyJson))]//ʵ¼ÊÀàÐÍ1
[JsonSerializable(typeof(MyJson))]
internal partial class AppJsonSerializerContext : JsonSerializerContext
{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<!--<PublishAot>true</PublishAot>-->
<UserSecretsId>dotnet-TouchSocketWebApi-987c185f-10b1-452b-beb6-47d798a5a131</UserSecretsId>
<ServerGarbageCollection>true</ServerGarbageCollection>
<UserSecretsId>dotnet-WorkerService1-19b37b17-6043-4334-ad9a-9e0e3c670da3</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="TouchSocket.Hosting" Version="4.0.0-beta.80" />
<PackageReference Include="TouchSocket.WebApi" Version="4.0.0-beta.80" />
<PackageReference Include="TouchSocket.WebApi.Swagger" Version="4.0.0-beta.80" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageReference Include="TouchSocket.Hosting" Version="4.0.0-beta.120" />
<PackageReference Include="TouchSocket.WebApi" Version="4.0.0-beta.120" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
Loading
Loading