diff --git a/frameworks/CSharp/touchsocket/.gitignore b/frameworks/CSharp/touchsocket/.gitignore new file mode 100644 index 00000000000..d20fe97fddd --- /dev/null +++ b/frameworks/CSharp/touchsocket/.gitignore @@ -0,0 +1,343 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ +# ASP.NET Core default setup: bower directory is configured as wwwroot/lib/ and bower restore is true +**/wwwroot/lib/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb +*.snupkg +SHFB/Help diff --git a/frameworks/CSharp/touchsocket/Benchmarks.sln b/frameworks/CSharp/touchsocket/Benchmarks.sln new file mode 100644 index 00000000000..9e760787179 --- /dev/null +++ b/frameworks/CSharp/touchsocket/Benchmarks.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31717.71 +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 +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6BD9363A-D77F-5D90-8444-2BC37495C920}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6BD9363A-D77F-5D90-8444-2BC37495C920}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6BD9363A-D77F-5D90-8444-2BC37495C920}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6BD9363A-D77F-5D90-8444-2BC37495C920}.Release|Any CPU.Build.0 = Release|Any CPU + {A7FB43AB-672B-8854-68D7-C2B383B0BC04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {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 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {69C5D834-F31B-4F07-97EC-E4DD5AF417DE} + EndGlobalSection +EndGlobal diff --git a/frameworks/CSharp/touchsocket/README.md b/frameworks/CSharp/touchsocket/README.md new file mode 100644 index 00000000000..22524d6f70a --- /dev/null +++ b/frameworks/CSharp/touchsocket/README.md @@ -0,0 +1,10 @@ +# touchsocket benchmarks + +See [touchsocket](https://touchsocket.net/) for more information. + +## Infrastructure Software Versions + +**Language** + +* C# 8.0 + diff --git a/frameworks/CSharp/touchsocket/benchmark_config.json b/frameworks/CSharp/touchsocket/benchmark_config.json new file mode 100644 index 00000000000..7590b2a1866 --- /dev/null +++ b/frameworks/CSharp/touchsocket/benchmark_config.json @@ -0,0 +1,44 @@ +{ + "framework": "touchsocket", + "tests": [ + { + "default": { + "plaintext_url": "/plaintext", + "json_url": "/json", + "port": 8080, + "approach": "Realistic", + "classification": "Fullstack", + "framework": "touchsocket.webapi", + "language": "C#", + "orm": "Raw", + "platform": ".NET", + "flavor": "CoreCLR", + "webserver": "touchsocket", + "os": "Linux", + "database_os": "Linux", + "display_name": "touchsocket.webapi", + "notes": "", + "versus": "aspnetcore-mvc" + }, + "http": { + "plaintext_url": "/plaintext", + "json_url": "/json", + "port": 8080, + "approach": "Realistic", + "classification": "Micro", + "database": "Postgres", + "framework": "touchsocket.http", + "language": "C#", + "orm": "Micro", + "platform": ".NET", + "flavor": "CoreCLR", + "webserver": "touchsocket", + "os": "Linux", + "database_os": "Linux", + "display_name": "touchsocket.http", + "notes": "", + "versus": "aspnetcore" + } + } + ] +} diff --git a/frameworks/CSharp/touchsocket/config.toml b/frameworks/CSharp/touchsocket/config.toml new file mode 100644 index 00000000000..4e386939aff --- /dev/null +++ b/frameworks/CSharp/touchsocket/config.toml @@ -0,0 +1,28 @@ +[framework] +name = "touchsocket" + +[main] +urls.plaintext = "/plaintext" +urls.json = "/json" +approach = "Realistic" +classification = "Fullstack" +database = "Postgres" +database_os = "Linux" +os = "Linux" +orm = "Raw" +platform = ".NET" +webserver = "touchsocket.webapi" +versus = "aspcore-mvc" + +[http] +urls.plaintext = "/plaintext" +urls.json = "/json" +approach = "Realistic" +classification = "Micro" +database = "Postgres" +database_os = "Linux" +os = "Linux" +orm = "Raw" +platform = ".NET" +webserver = "touchsocket.http" +versus = "aspcore" diff --git a/frameworks/CSharp/touchsocket/src/TouchSocketHttp/NuGet.Config b/frameworks/CSharp/touchsocket/src/TouchSocketHttp/NuGet.Config new file mode 100644 index 00000000000..f05d5867888 --- /dev/null +++ b/frameworks/CSharp/touchsocket/src/TouchSocketHttp/NuGet.Config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/frameworks/CSharp/touchsocket/src/TouchSocketHttp/Program.cs b/frameworks/CSharp/touchsocket/src/TouchSocketHttp/Program.cs new file mode 100644 index 00000000000..f326d1bd78c --- /dev/null +++ b/frameworks/CSharp/touchsocket/src/TouchSocketHttp/Program.cs @@ -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) + .SetBacklog(1000) + .ConfigureContainer(a => + { + a.AddConsoleLogger(); + })); + + await service.StartAsync(); + service.Logger.Info($"server is started,port:{port}"); + while (true) + { + Console.ReadLine(); + } + } +} + +sealed class MyHttpService : HttpService +{ + 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() + { + m_timer = new Timer((state) => + { + DateString = DateTime.UtcNow.ToGMTString(); + }, null, 0, 1000); + } + + public static string DateString { get; private set; } +} + diff --git a/frameworks/CSharp/touchsocket/src/TouchSocketHttp/TouchSocketHttp.csproj b/frameworks/CSharp/touchsocket/src/TouchSocketHttp/TouchSocketHttp.csproj new file mode 100644 index 00000000000..861df016264 --- /dev/null +++ b/frameworks/CSharp/touchsocket/src/TouchSocketHttp/TouchSocketHttp.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + Exe + enable + true + + dotnet-TouchSocketWebApi-987c185f-10b1-452b-beb6-47d798a5a131 + true + + + + + + diff --git a/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/NuGet.Config b/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/NuGet.Config new file mode 100644 index 00000000000..f05d5867888 --- /dev/null +++ b/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/NuGet.Config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/Program.cs b/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/Program.cs new file mode 100644 index 00000000000..9ff88e76fa2 --- /dev/null +++ b/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/Program.cs @@ -0,0 +1,94 @@ +using System.Text; +using System.Text.Json.Serialization; +using TouchSocket.Core; +using TouchSocket.Http; +using TouchSocket.Rpc; +using TouchSocket.Sockets; +using TouchSocket.WebApi; +using TouchSocket.WebApi.Swagger; +using HttpContent = TouchSocket.Http.HttpContent; + +namespace TouchSocketWebApi; + +public class Program +{ + public static void Main(string[] args) + { + var builder = Host.CreateApplicationBuilder(args); + + builder.Services.AddServiceHostedService(config => + { + config.SetListenIPHosts(8080) + .SetNoDelay(true) + .SetMaxCount(1000000) + .SetBacklog(1000) + .ConfigureContainer(a => + { + a.AddConsoleLogger(); + a.AddRpcStore(store => + { + store.RegisterServer(); + }); + }) + .ConfigurePlugins(a => + { + a.UseCheckClear(); + + a.UseWebApi() + .ConfigureConverter(converter => + { + converter.Clear(); + converter.AddSystemTextJsonSerializerFormatter(options => + { + options.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default); + }); + }); + +#if DEBUG + a.UseSwagger() + .UseLaunchBrowser(); +#endif + + a.UseDefaultHttpServicePlugin(); + }); + }); + + var host = builder.Build(); + host.Run(); + } +} + +public partial class ApiServer : RpcServer +{ + private HttpContent m_contentPlaintext = new StringHttpContent("Hello, World!", Encoding.UTF8, $"text/plain"); + + public static MyJson MyJson { get; set; } = new MyJson() { Message = "Hello, World!" }; + + [Router("/plaintext")] + [WebApi(Method = HttpMethodType.Get)] + public async Task Plaintext(IWebApiCallContext callContext) + { + var response= callContext.HttpContext.Response; + response.SetStatus(200, "success"); + response.Content= m_contentPlaintext; + await response.AnswerAsync(); + } + + [Router("/json")] + [WebApi(Method = HttpMethodType.Get)] + public MyJson Json() + { + return MyJson; + } +} + +[JsonSerializable(typeof(MyJson))]//ʵ������1 +internal partial class AppJsonSerializerContext : JsonSerializerContext +{ + +} + +public class MyJson +{ + public string? Message { get; set; } +} \ No newline at end of file diff --git a/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/TouchSocketWebApi.csproj b/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/TouchSocketWebApi.csproj new file mode 100644 index 00000000000..87b1299e11e --- /dev/null +++ b/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/TouchSocketWebApi.csproj @@ -0,0 +1,19 @@ + + + + net8.0 + enable + enable + true + + dotnet-TouchSocketWebApi-987c185f-10b1-452b-beb6-47d798a5a131 + true + + + + + + + + + diff --git a/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/appsettings.Development.json b/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/appsettings.Development.json new file mode 100644 index 00000000000..b2dcdb67421 --- /dev/null +++ b/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/appsettings.json b/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/appsettings.json new file mode 100644 index 00000000000..b2dcdb67421 --- /dev/null +++ b/frameworks/CSharp/touchsocket/src/TouchSocketWebApi/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/frameworks/CSharp/touchsocket/touchsocket-http.dockerfile b/frameworks/CSharp/touchsocket/touchsocket-http.dockerfile new file mode 100644 index 00000000000..ba6b39ac880 --- /dev/null +++ b/frameworks/CSharp/touchsocket/touchsocket-http.dockerfile @@ -0,0 +1,13 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /app +COPY src/TouchSocketHttp . +RUN dotnet publish -c Release -o out + +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime + +WORKDIR /app +COPY --from=build /app/out ./ + +EXPOSE 8080 + +ENTRYPOINT ["dotnet", "TouchSocketHttp.dll"] diff --git a/frameworks/CSharp/touchsocket/touchsocket.dockerfile b/frameworks/CSharp/touchsocket/touchsocket.dockerfile new file mode 100644 index 00000000000..a65674ef5d3 --- /dev/null +++ b/frameworks/CSharp/touchsocket/touchsocket.dockerfile @@ -0,0 +1,13 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /app +COPY src/TouchSocketWebApi . +RUN dotnet publish -c Release -o out + +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime + +WORKDIR /app +COPY --from=build /app/out ./ + +EXPOSE 8080 + +ENTRYPOINT ["dotnet", "TouchSocketWebApi.dll"]