Skip to content

Commit 027150a

Browse files
authored
🐦 Falco v5.x (#9580)
1 parent ea96185 commit 027150a

File tree

8 files changed

+99
-170
lines changed

8 files changed

+99
-170
lines changed

frameworks/FSharp/falco/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Falco Tests on Linux
2+
23
This includes tests for plaintext, json, and fortunes HTML serialization.
34

45
## Infrastructure Software Versions
56

67
**Language**
78

8-
* F# 6.0
9+
* F# 6.0 (or greater)
910

1011
**Platforms**
1112

@@ -18,11 +19,10 @@ This includes tests for plaintext, json, and fortunes HTML serialization.
1819
**Web Stack**
1920

2021
* [Falco](https://github.com/pimbrouwers/Falco)
21-
* [Donald](https://github.com/pimbrouwers/Donald)
2222
* ASP.NET Core
2323

2424
## Paths & Source for Tests
2525

26-
* [Plaintext](src/App/Value.fs): "/plaintext"
27-
* [JSON serialization](src/App/Value.fs): "/json"
28-
* [Fortunes using Donald](src/App/Fortune.fs): "/fortunes"
26+
* [Plaintext](src/App/Program.fs): "/plaintext"
27+
* [JSON serialization](src/App/Program.fs): "/json"
28+
* [Fortunes using Donald](src/App/Program.fs): "/fortunes"

frameworks/FSharp/falco/benchmark_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"webserver": "Kestrel",
1919
"os": "Linux",
2020
"database_os": "Linux",
21-
"display_name": "Falco, Donald",
21+
"display_name": "Falco",
2222
"notes": "",
2323
"versus": "aspcore"
2424
}

frameworks/FSharp/falco/falco.dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:7.0.100 AS build
1+
FROM mcr.microsoft.com/dotnet/sdk:9.0.100 AS build
22
WORKDIR /app
33
COPY src/App .
44
RUN dotnet publish -c Release -o out
55

6-
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS runtime
6+
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
77
# Full PGO
8-
ENV DOTNET_TieredPGO 1
9-
ENV DOTNET_TC_QuickJitForLoops 1
8+
ENV DOTNET_TieredPGO 1
9+
ENV DOTNET_TC_QuickJitForLoops 1
1010
ENV DOTNET_ReadyToRun 0
1111

1212
ENV ASPNETCORE_URLS http://+:8080
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<DebugType>portable</DebugType>
66
<AssemblyName>App</AssemblyName>
77
<OutputType>Exe</OutputType>
@@ -11,17 +11,12 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<Compile Include="UI.fs" />
15-
<Compile Include="Fortune.fs" />
16-
<Compile Include="Server.fs" />
1714
<Compile Include="Program.fs" />
1815
</ItemGroup>
1916

2017
<ItemGroup>
21-
<PackageReference Update="FSharp.Core" Version="7.0.0" />
22-
<PackageReference Include="Donald" Version="3.0.*" />
23-
<PackageReference Include="Falco" Version="2.0.*" />
24-
<PackageReference Include="Npgsql" Version="8.0.3" />
18+
<PackageReference Include="Falco" Version="5.*" />
19+
<PackageReference Include="Npgsql" Version="9.*" />
2520
</ItemGroup>
2621

2722
</Project>

frameworks/FSharp/falco/src/App/Fortune.fs

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 86 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,99 @@
11
module Program
22

3+
open System.Data
34
open Falco
4-
open App
5+
open Falco.Markup
6+
open Falco.Routing
7+
open Microsoft.AspNetCore.Builder
8+
open Microsoft.Extensions.Logging
9+
open Npgsql
510

611
[<Literal>]
712
let connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;SSL Mode=Disable;Maximum Pool Size=1024;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true;Write Coalescing Buffer Threshold Bytes=1000"
813

914
[<Literal>]
1015
let defaultMsg = "Hello, World!"
1116

12-
type JsonModel = { message : string }
17+
type JsonResponse =
18+
{ message : string }
19+
20+
type Fortune =
21+
{ id : int
22+
message : string }
23+
24+
static member Default =
25+
{ id = 0
26+
message = "Additional fortune added at request time." }
27+
28+
let handleFortunes (connStr : string) : HttpHandler = fun ctx -> task {
29+
use conn = new NpgsqlConnection(connStr)
30+
31+
use comd = conn.CreateCommand()
32+
comd.CommandText <- "SELECT id, message FROM fortune"
33+
34+
do! conn.OpenAsync()
35+
use! redr = comd.ExecuteReaderAsync(CommandBehavior.SequentialAccess)
36+
37+
let! dbFortunes =
38+
task {
39+
let mutable shouldContinue = true
40+
let fortunes = ResizeArray<Fortune>()
41+
42+
while shouldContinue do
43+
let! fortunesRead = redr.ReadAsync()
44+
45+
if not fortunesRead then
46+
shouldContinue <- false
47+
else
48+
fortunes.Add { id = redr.GetInt32(0)
49+
message = redr.GetString(1) }
50+
return fortunes |> List.ofSeq
51+
}
52+
53+
redr.Dispose()
54+
comd.Dispose()
55+
conn.Dispose()
56+
57+
let sortedFortunes =
58+
Fortune.Default ::
59+
dbFortunes
60+
|> List.sortBy (fun f -> f.message)
61+
62+
let html =
63+
Elem.html [] [
64+
Elem.head [] [
65+
Elem.title [] [ Text.raw "Fortunes" ]
66+
]
67+
Elem.body [] [
68+
Elem.table [] [
69+
yield Elem.tr [] [
70+
Elem.th [] [ Text.raw "id" ]
71+
Elem.th [] [ Text.raw "message" ]
72+
]
73+
for fortune in sortedFortunes ->
74+
Elem.tr [] [
75+
Elem.td [] [ Text.raw (string fortune.id) ]
76+
Elem.td [] [ Text.enc fortune.message]
77+
]
78+
]
79+
]
80+
]
81+
82+
return Response.ofHtml html ctx
83+
}
1384

1485
[<EntryPoint>]
15-
let main args =
16-
Host.startWebHost
17-
args
18-
(Server.configure connectionString)
19-
[
20-
get "/plaintext" (Response.ofPlainText defaultMsg)
21-
get "/json" (Response.ofJson { message = defaultMsg })
22-
get "/fortunes" Fortune.handleIndex
23-
]
86+
let main args =
87+
let bldr = WebApplication.CreateBuilder(args)
88+
bldr.Logging.ClearProviders() |> ignore
89+
90+
let wapp = bldr.Build()
91+
92+
wapp.UseRouting()
93+
.UseFalco([
94+
get "/plaintext" (Response.ofPlainText defaultMsg)
95+
get "/json" (Response.ofJson { message = defaultMsg })
96+
get "/fortunes" (handleFortunes connectionString)
97+
])
98+
.Run()
2499
0

frameworks/FSharp/falco/src/App/Server.fs

Lines changed: 0 additions & 47 deletions
This file was deleted.

frameworks/FSharp/falco/src/App/UI.fs

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)