Skip to content

Commit

Permalink
Add benchmark for Saturn using Endpoint Router
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof-Cieslak committed Jun 23, 2020
1 parent d1484a8 commit 79e31f8
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 10 deletions.
12 changes: 9 additions & 3 deletions .paket/Paket.Restore.targets
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@
<PaketBootStrapperExePath Condition=" '$(PaketBootStrapperExePath)' == '' AND Exists('$(PaketRootPath)paket.bootstrapper.exe')">$(PaketRootPath)paket.bootstrapper.exe</PaketBootStrapperExePath>
<PaketBootStrapperExePath Condition=" '$(PaketBootStrapperExePath)' == '' ">$(PaketToolsPath)paket.bootstrapper.exe</PaketBootStrapperExePath>
<PaketBootStrapperExeDir Condition=" Exists('$(PaketBootStrapperExePath)') " >$([System.IO.Path]::GetDirectoryName("$(PaketBootStrapperExePath)"))\</PaketBootStrapperExeDir>

<PaketBootStrapperCommand Condition=" '$(OS)' == 'Windows_NT' ">"$(PaketBootStrapperExePath)"</PaketBootStrapperCommand>
<PaketBootStrapperCommand Condition=" '$(OS)' != 'Windows_NT' ">$(MonoPath) --runtime=v4.0.30319 "$(PaketBootStrapperExePath)"</PaketBootStrapperCommand>

<!-- Disable automagic references for F# DotNet SDK -->
<!-- This will not do anything for other project types -->
<!-- see https://github.com/fsharp/fslang-design/blob/master/tooling/FST-1002-fsharp-in-dotnet-sdk.md -->
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>

<!-- Disable Paket restore under NCrunch build -->
<PaketRestoreDisabled Condition="'$(NCrunch)' == '1'">True</PaketRestoreDisabled>

Expand Down Expand Up @@ -130,7 +136,7 @@
<!-- Parse our simple 'paket.restore.cached' json ...-->
<PaketRestoreCachedSplitObject Include="$([System.Text.RegularExpressions.Regex]::Split(`$(PaketRestoreCachedContents)`, `{|}|,`))"></PaketRestoreCachedSplitObject>
<!-- Keep Key, Value ItemGroup-->
<PaketRestoreCachedKeyValue Include="@(PaketRestoreCachedSplitObject)"
<PaketRestoreCachedKeyValue Include="@(PaketRestoreCachedSplitObject)"
Condition=" $([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `&quot;: &quot;`).Length) &gt; 1 ">
<Key>$([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `": "`)[0].Replace(`"`, ``).Replace(` `, ``))</Key>
<Value>$([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `": "`)[1].Replace(`"`, ``).Replace(` `, ``))</Value>
Expand Down Expand Up @@ -163,7 +169,7 @@
<Exec Command='$(PaketBootStrapperCommand)' Condition=" '$(PaketBootstrapperStyle)' == 'classic' AND Exists('$(PaketBootStrapperExePath)') AND !(Exists('$(PaketExePath)'))" ContinueOnError="false" />
<Error Text="Stop build because of PAKET_ERROR_ON_MSBUILD_EXEC and we need a full restore (hashes don't match)" Condition=" '$(PAKET_ERROR_ON_MSBUILD_EXEC)' == 'true' AND '$(PaketRestoreRequired)' == 'true' AND '$(PaketDisableGlobalRestore)' != 'true'" />
<Exec Command='$(PaketCommand) restore' Condition=" '$(PaketRestoreRequired)' == 'true' AND '$(PaketDisableGlobalRestore)' != 'true' " ContinueOnError="false" />

<!-- Step 2 Detect project specific changes -->
<ItemGroup>
<MyTargetFrameworks Condition="'$(TargetFramework)' != '' " Include="$(TargetFramework)"></MyTargetFrameworks>
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased] - 22.06.2020

### Added

* Added `RouterEndpoint`, `ControllerEndpoint` modules allowing to create routing using ASP.NET Endpoint Routing
* Added `use_endpoint_router` to `application` computation expression allowing to use Endpoint Routing in the application

### Changed

* Updated to Giraffe 5.0-alpha02
* Moved to `Giraffe.ViewEngine` package for view rendering support

## [0.14.1] - 18.06.2020

### Added
Expand Down
15 changes: 15 additions & 0 deletions Saturn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "GiraffeBench", "benchmark\G
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SaturnBench", "benchmark\SaturnBench\SaturnBench.fsproj", "{2885CF04-BCEE-457B-B013-36FE935030BF}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SaturnEndpointBench", "benchmark\SaturnEndpointBench\SaturnEndpointBench.fsproj", "{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -318,6 +320,18 @@ Global
{25F4D226-205F-4498-8FD6-99548A2FAF49}.Release|x64.Build.0 = Release|Any CPU
{25F4D226-205F-4498-8FD6-99548A2FAF49}.Release|x86.ActiveCfg = Release|Any CPU
{25F4D226-205F-4498-8FD6-99548A2FAF49}.Release|x86.Build.0 = Release|Any CPU
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}.Debug|x64.ActiveCfg = Debug|Any CPU
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}.Debug|x64.Build.0 = Debug|Any CPU
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}.Debug|x86.ActiveCfg = Debug|Any CPU
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}.Debug|x86.Build.0 = Debug|Any CPU
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}.Release|Any CPU.Build.0 = Release|Any CPU
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}.Release|x64.ActiveCfg = Release|Any CPU
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}.Release|x64.Build.0 = Release|Any CPU
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}.Release|x86.ActiveCfg = Release|Any CPU
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8DBA089A-7C24-4E87-870B-E0774654F376} = {F2C8C347-845F-42E4-A702-7381C4B4087F}
Expand All @@ -341,5 +355,6 @@ Global
{FC8B2AB6-79A4-48CC-9B83-AF84DEF17BA7} = {CA96E36B-6981-4056-AAE8-1D6FA3CD07E4}
{2885CF04-BCEE-457B-B013-36FE935030BF} = {CA96E36B-6981-4056-AAE8-1D6FA3CD07E4}
{25F4D226-205F-4498-8FD6-99548A2FAF49} = {511FB392-5714-4028-97F3-F883F81B43DB}
{DDCBA764-1E2E-4A1E-A10E-3EF8EEFB6AE3} = {CA96E36B-6981-4056-AAE8-1D6FA3CD07E4}
EndGlobalSection
EndGlobal
26 changes: 26 additions & 0 deletions benchmark/SaturnEndpointBench/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
open System
open Giraffe.ResponseWriters
open Giraffe.Core
open Saturn
open Microsoft.Extensions.Logging
open Saturn.Endpoint

let topRouter = router {
get "/" (text "")
getf "/user/%s" text
post "/user" (text "")

}

let app = application {
use_endpoint_router topRouter
logging (fun loggerBuilder ->
loggerBuilder.ClearProviders()
|> ignore
)
}

[<EntryPoint>]
let main _ =
run app
0
19 changes: 19 additions & 0 deletions benchmark/SaturnEndpointBench/SaturnEndpointBench.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/Saturn/Saturn.fsproj">
<Name>Saturn.fsproj</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
2 changes: 2 additions & 0 deletions benchmark/SaturnEndpointBench/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FSharp.Core
Giraffe
18 changes: 18 additions & 0 deletions benchmark/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ echo 'Giraffe build'
dotnet build ./SaturnBench/SaturnBench.fsproj -c Release
wait $!
echo 'Saturn build'
dotnet build ./SaturnEndpointBench/SaturnEndpointBench.fsproj -c Release
wait $!
echo 'Saturn-Endpoint build'

sh -c 'dotnet GiraffeBench/bin/Release/netcoreapp3.1/GiraffeBench.dll' &
G_PID=$!
Expand Down Expand Up @@ -38,3 +41,18 @@ kill -9 $S_PID
echo 'Saturn tested'

sleep 5
echo ''

sh -c 'dotnet SaturnEndpointBench/bin/Release/netcoreapp3.1/SaturnEndpointBench.dll' &
S_PID=$!
echo ''
sleep 3
echo ''
echo 'Testing Saturn-Endpoint'
wrk -t12 -c400 -d30s http://127.0.0.1:5000/user/test
echo ''
echo ''
kill -9 $S_PID
echo 'Saturn-Endpoint tested'

sleep 5
7 changes: 0 additions & 7 deletions src/Saturn/RouterEndpoint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,6 @@ module Router =
else
(Saturn.Common.succeed |> List.foldBack (fun e acc -> acc >=> e) state.Pipelines) >=> hndl

let v =
match typ with
| RouteType.Get -> "GET"
| RouteType.Post -> "POST"
| RouteType.Put -> "PUT"
| RouteType.Patch -> "PATCH"
| RouteType.Delete -> "DELETE"
let routes, routesf = state.GetRoutes typ
let routes = routes |> Seq.map (fun (p, lst) ->

Expand Down

0 comments on commit 79e31f8

Please sign in to comment.