Browse Source

Add Carter (#3805)

* Add Carter

* async Main, update Carter

* Correct C# version
Ben Adams 7 years ago
parent
commit
038cd5fce5

+ 37 - 0
frameworks/CSharp/carter/.gitignore

@@ -0,0 +1,37 @@
+[Oo]bj/
+[Bb]in/
+TestResults/
+.nuget/
+*.sln.ide/
+_ReSharper.*/
+.idea/
+packages/
+artifacts/
+PublishProfiles/
+.vs/
+*.user
+*.suo
+*.cache
+*.docstates
+_ReSharper.*
+nuget.exe
+*net45.csproj
+*net451.csproj
+*k10.csproj
+*.psess
+*.vsp
+*.pidb
+*.userprefs
+*DS_Store
+*.ncrunchsolution
+*.*sdf
+*.ipch
+*.swp
+*~
+.build/
+.testPublish/
+launchSettings.json
+BenchmarkDotNet.Artifacts/
+BDN.Generated/
+binaries/
+global.json

+ 14 - 0
frameworks/CSharp/carter/Benchmarks/Benchmarks.csproj

@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+  <PropertyGroup>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <OutputType>Exe</OutputType>
+    <NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
+    <LangVersion>7.3</LangVersion>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Carter" Version="3.7.0" />
+    <PackageReference Include="Microsoft.AspNetCore.App" />
+    <PackageReference Include="Utf8Json" Version="1.3.7" />
+  </ItemGroup>
+</Project>

+ 32 - 0
frameworks/CSharp/carter/Benchmarks/JsonModule.cs

@@ -0,0 +1,32 @@
+namespace Benchmarks
+{
+    using Carter;
+    using System.Threading.Tasks;
+    using Utf8Json;
+
+    public class JsonModule : CarterModule
+    {
+        private const int _bufferSize = 27;
+
+        public JsonModule() : base("json")
+        {
+            Get("/", (req, res, routeData) =>
+            {
+                res.StatusCode = 200;
+                res.ContentType = "application/json";
+                res.ContentLength = _bufferSize;
+
+                var msg = new JsonMessage { message = "Hello, World!" };
+
+                JsonSerializer.Serialize(res.Body, msg);
+
+                return Task.CompletedTask;
+            });
+        }
+
+        public struct JsonMessage
+        {
+            public string message;
+        }
+    }
+}

+ 22 - 0
frameworks/CSharp/carter/Benchmarks/PlainModule.cs

@@ -0,0 +1,22 @@
+namespace Benchmarks
+{
+    using Carter;
+    using System.Text;
+
+    public class PlainModule : CarterModule
+    {
+        private static readonly byte[] _helloWorldPayload = Encoding.UTF8.GetBytes("Hello, World!");
+
+        public PlainModule() : base("plaintext")
+        {
+            Get("/", (req, res, routeData) =>
+            {
+                var payloadLength = _helloWorldPayload.Length;
+                res.StatusCode = 200;
+                res.ContentType = "text/plain";
+                res.ContentLength = payloadLength;
+                return res.Body.WriteAsync(_helloWorldPayload, 0, payloadLength);
+            });
+        }
+    }
+}

+ 27 - 0
frameworks/CSharp/carter/Benchmarks/Program.cs

@@ -0,0 +1,27 @@
+namespace Benchmarks
+{
+    using System.IO;
+    using System.Threading.Tasks;
+    using Microsoft.AspNetCore.Hosting;
+    using Microsoft.Extensions.Configuration;
+
+    public class Program
+    {
+        public static async Task Main(string[] args)
+        {
+            var config = new ConfigurationBuilder()
+                .AddEnvironmentVariables(prefix: "ASPNETCORE_")
+                .AddCommandLine(args)
+                .Build();
+
+            var webHost = new WebHostBuilder()
+                .UseContentRoot(Directory.GetCurrentDirectory())
+                .UseConfiguration(config)
+                .UseStartup<Startup>()
+                .UseKestrel()
+                .Build();
+
+            await webHost.RunAsync();
+        }
+    }
+}

+ 19 - 0
frameworks/CSharp/carter/Benchmarks/Startup.cs

@@ -0,0 +1,19 @@
+namespace Benchmarks
+{
+    using Carter;
+    using Microsoft.AspNetCore.Builder;
+    using Microsoft.Extensions.DependencyInjection;
+
+    public class Startup
+    {
+        public void ConfigureServices(IServiceCollection services)
+        {
+            services.AddCarter();
+        }
+
+        public void Configure(IApplicationBuilder app)
+        {
+            app.UseCarter();
+        }
+    }
+}

+ 26 - 0
frameworks/CSharp/carter/README.md

@@ -0,0 +1,26 @@
+# Carter Tests on Linux
+This includes tests for plaintext and json serialization.
+
+## Infrastructure Software Versions
+
+**Language**
+
+* C# 7.0
+
+**Platforms**
+
+* .NET Core (Windows and Linux)
+
+**Web Servers**
+
+* [Kestrel](https://github.com/aspnet/KestrelHttpServer)
+
+**Web Stack**
+
+* [Carter](https://github.com/CarterCommunity/Carter)
+* ASP.NET Core
+
+## Paths & Source for Tests
+
+* [Plaintext](Benchmarks/PlainModule.cs): "/plaintext"
+* [JSON Serialization](Benchmarks/JsonModule.cs): "/utf8json"

+ 24 - 0
frameworks/CSharp/carter/benchmark_config.json

@@ -0,0 +1,24 @@
+{
+  "framework": "carter",
+  "tests": [{
+    "default": {
+      "plaintext_url": "/plaintext",
+      "json_url": "/json",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "None",
+      "framework": "Carter",
+      "language": "C#",
+      "orm": "Raw",
+      "platform": ".NET",
+      "flavor": "CoreCLR",
+      "webserver": "Kestrel",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Carter",
+      "notes": "",
+      "versus": "aspcore"
+    }
+  }]
+}

+ 12 - 0
frameworks/CSharp/carter/carter.dockerfile

@@ -0,0 +1,12 @@
+FROM microsoft/dotnet:2.1-sdk-stretch AS build
+WORKDIR /app
+COPY Benchmarks .
+RUN dotnet publish -c Release -o out
+
+FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime
+ENV ASPNETCORE_URLS http://+:8080
+ENV COMPlus_ReadyToRun 0
+WORKDIR /app
+COPY --from=build /app/out ./
+
+ENTRYPOINT ["dotnet", "Benchmarks.dll"]