theDotNetWay

Basecamp's ONCE Campfire · the third Campfire in F#

Campfire,
the .NET way.

ASP.NET Core, EF Core with Dapper on the hot reads, Kestrel, the framework's middleware and OutputCache, Falco.Markup, AngleSharp. The code a .NET team would write. Every page is pixel-identical to Rails, the database and cookies are Rails' own, and it serves 6.83×–7.83× the requests of current Rails on Basecamp's harness.

  • F#
  • ASP.NET Core
  • Kestrel
  • EF Core
  • Dapper
  • Microsoft.Data.Sqlite
  • Falco
  • Falco.Markup
  • AngleSharp
  • HybridCache
  • OutputCache
  • MapStaticAssets
  • WebSockets
  • Certes
  • BackgroundService
  • TimeProvider
  • xUnit
  • 26.5KLOC

    of backend F#, by upstream's counting rules (26.0 as cloc prints it). Rust's port is 31.0, Rails 5.5. The port it forked from was 39.4.

  • 6.83×–7.83×

    current Rails, each route alone, on Basecamp's own harness in the same sessions. 9.43×–11.75× while a writer posts.

  • 4,918/4,918

    screenshots pixel-equal to Rails on the full matrix: 5 seeds, 3 engines, 4 viewports and 6 breakpoint widths, light and dark. Accessibility tree and DOM equal too.

Not the fastest Campfire. In the table below it is ahead of Rails in all 9 rows and of the F# port in 4; onCrack, C and Rust are ahead of it in every row. It gives up speed for the framework's way, on purpose. Every number on this page links to the file it came from.

The table

Campfire, six ways.

Requests per second at 16 clients, 4 server CPUs per app, Basecamp's once-campfire-verification harness, all six apps in the same 4 sessions. Higher is better; the fastest in each row is shaded, theDotNetWay is outlined. Every cell is the median of 6 rounds.

Campfire, six ways: requests per second
GroupWorkloadtheDotNetWay75487b7onCrack3770dffF# port9954ad0Railsca9b963Rust6dae2fdC873a51f
Each route alone
Each route aloneRoom page req/s34,9897.08× Rails169,08835,6194,94449,90277,135
Messages page req/s33,8316.83× Rails179,07742,1264,95347,11277,086
Sidebar req/s41,5817.66× Rails190,32038,1955,42555,56183,137
Search req/s41,3257.83× Rails184,64434,0095,28055,92082,402
Post a message req/s2,9017.24× Rails15,1499,5164016,4985,858
Reads while a writer posts 10/s
Reads while a writer posts 10/sRoom page req/s32,88611.75× Rails163,17433,2172,80047,41171,829
Messages page req/s33,0129.54× Rails178,18841,1373,46145,00273,843
Sidebar req/s40,2469.43× Rails187,71337,7984,26755,62882,396
Search req/s39,6109.70× Rails182,96534,7904,08454,14079,870

Method. Upstream's bin/benchmark on this project's Linux VM (not Basecamp's or Ryan Rodemoyer's rig): 3 rounds of 8 s per app per session, the app on 4 CPUs and the load generator on 4, every response checked against the seed's contract and every post audited in the database. The writer group adds one client posting 10 messages a second into the room. Numbers from other rigs or older sessions are not mixed in. Upstream's contract asks a page cache to re-check the session and the room membership on every hit; theDotNetWay and onCrack (its fresh mode) do it on every request, stricter than upstream's own, which serves the session from its epoch.

  • theDotNetWay 64 MB response cache. This repository. The framework's way, with a page cache that re-checks who is asking on every hit.
  • onCrack 64 MB response cache. The F# port with its hands free: finished pages kept until a commit changes them, posts committed together, its own fast paths. Fresh authorization mode.
  • F# port no response cache. The F# port: a line-for-line translation of the Rust port onto ASP.NET Core and Falco, with its own HTTP kit, views and data layer. No page cache.
  • Rails 64 MB response cache. Basecamp's Rails app, current upstream, as their harness runs it: four Puma workers and a page cache.
  • Rust 64 MB response cache. Basecamp's Rust port, current upstream, with its page cache.
  • C 64 MiB cache. Basecamp's C port, current upstream, with its cache.

Method, sessions, images Every cell with its range Phase 10, step by step

About the speed

Five times which Rails?

Through Phase 9, every phase was held to a floor of five times Rails, measured with bench/quick against stored numbers for an old, pinned Rails: about 107 room pages a second with one client, 239 with sixteen. Every phase cleared it, which is where the earlier “five times Rails” came from.

Basecamp's harness runs current Rails with a page cache, and it serves 4,944 room pages a second: 21× the pinned one. The first run there put theDotNetWay at 0.68×–1.51× Rails on the reads (1.06×–2.02× with a writer). The room page was slower than Rails'.

Phase 10 found why: about half a millisecond of CPU a page, most of it the data layer opening a pooled connection and preparing a statement for every one of nine statements, and the JIT still warming up on the first route. It opened one connection per request, set the tiering delay to zero, moved one slow read to Dapper, and added a page cache in the four GET actions on HybridCache that re-reads the session and the membership on every hit. The framework's OutputCache could not do it: it never stores a response that sets a cookie, and the room page always does.

Now every route alone is 6.83×–7.83× current Rails, and the new floor is measured on Basecamp's harness, in the same session. Each step, measured

Phase 9, the first runafter Phase 10the floor, five times RailsRails
  1. Each route alone
  2. Room page0.68×7.08×
  3. Messages page1.51×6.83×
  4. Sidebar1.47×7.66×
  5. Search1.42×7.83×
  6. Post a message5.68×7.24×
  7. Reads while a writer posts 10/s
  8. Room page1.06×11.75×
  9. Messages page2.02×9.54×
  10. Sidebar1.76×9.43×
  11. Search1.77×9.70×
theDotNetWay over the same sessions' current Rails (pooled medians of each run). Before: bench/results/dotnetway-six-ways/before-phase10/table.json; after: bench/results/dotnetway-six-ways/table.json.

The climb

Lines down. Speed lost, then found.

From the fork (39.4 KLOC) to 26.5 KLOC, one layer a phase. The data layer's move to EF Core cost the pages most of their speed, Dapper on the hot reads made them about half again as fast, and Phase 10, the page cache, took the room page from 7,215 to 33,418 requests a second on bench/quick.

Backend KLOC, corrected (bin/kloc)010203040Rust 31.0Rails 5.539.438.435.335.434.833.730.230.027.827.126.226.5The thinnest workload, times Rails0×2×4×6×8×10×12×the floor, 5×pinned Railsbench/quickcurrent Railsupstream's harnessP0P1P2HP3P4P5P6P7P8P9P10

Phase 0

Baseline

The untouched F# port, renamed, with the pixel, aria and loose-DOM gates, the cookie round trip and the bench in place.

39.4 KLOC, corrected

c=16, bench/quickreq/s× pinned Rails
Room page30,751128.50×
Messages page33,74488.66×
Sidebar31,30652.30×
Search17,75243.52×
Post a message4,05512.29×

dotnetway-p0/quick

Phase 1

Data on EF Core

The data layer moves to EF Core. Every page pays for it: the room page drops to a fifth of the port's speed.

38.4 KLOC, corrected

c=16, bench/quickreq/s× pinned Rails
Room page6,01325.13×
Messages page5,17813.60×
Sidebar5,8969.85×
Search5,07112.43×
Post a message1,8575.63×

dotnetway-p1-fix/quick

Phase 2

Kit on ASP.NET Core

The hand-written HTTP kit gives way to HttpContext, authentication and antiforgery.

35.3 KLOC, corrected

c=16, bench/quickreq/s× pinned Rails
Room page5,49822.97×
Messages page5,19113.64×
Sidebar5,5829.32×
Search5,06212.41×
Post a message1,8855.71×

dotnetway-p2/quick

Hybrid reads

Hot reads on Dapper

The per-request reads move to Dapper; EF Core keeps the rest. The pages gain about half.

35.4 KLOC, corrected

c=16, bench/quickreq/s× pinned Rails
Room page8,30534.71×
Messages page7,65720.12×
Sidebar7,79313.02×
Search7,58018.58×
Post a message2,0536.22×

dotnetway-hybrid-2/new

Phase 3

Cable on WebSockets

Action Cable on the framework's WebSocket middleware.

34.8 KLOC, corrected

c=16, bench/quickreq/s× pinned Rails
Room page8,08233.77×
Messages page7,52619.77×
Sidebar7,63412.75×
Search7,54518.50×
Post a message2,0466.20×

dotnetway-p3/quick/new

Phase 4

Views on Falco.Markup

Every template is Falco.Markup; the string-render cost lands here.

33.7 KLOC, corrected

c=16, bench/quickreq/s× pinned Rails
Room page7,43331.06×
Messages page7,28619.14×
Sidebar7,60512.70×
Search6,65016.30×
Post a message1,9956.04×

dotnetway-p4/quick/new

Phase 5

Rich text on AngleSharp

The parser and DOM go; AngleSharp comes in. The biggest single cut in lines.

30.2 KLOC, corrected

c=16, bench/quickreq/s× pinned Rails
Room page7,29930.50×
Messages page7,03118.47×
Sidebar7,50012.53×
Search6,92316.97×
Post a message1,9946.04×

dotnetway-p5/quick/new

Phase 6

Assets on MapStaticAssets

The SDK fingerprints and serves the assets.

30.0 KLOC, corrected

c=16, bench/quickreq/s× pinned Rails
Room page7,45431.15×
Messages page7,39819.44×
Sidebar7,66712.81×
Search7,00417.17×
Post a message1,9976.05×

dotnetway-p6/quick/new

Phase 7

Kestrel, Certes, middleware

The front server is the framework's.

27.8 KLOC, corrected

c=16, bench/quickreq/s× pinned Rails
Room page7,23430.23×
Messages page7,10618.67×
Sidebar7,35712.29×
Search6,80116.67×
Post a message2,1136.40×

dotnetway-p7/quick/new

Phase 8

Jobs, clients, push, time

BackgroundService, HttpClientFactory, WebPush, IOptions, TimeProvider.

27.1 KLOC, corrected

c=16, bench/quickreq/s× pinned Rails
Room page7,20230.09×
Messages page7,08318.61×
Sidebar7,37312.32×
Search6,85616.81×
Post a message2,1356.47×

dotnetway-p8/quick/new

Phase 9

The close

One Rails helpers project, storage trims, the full pixel gate. Then the first run on upstream's harness.

26.2 KLOC, corrected

c=16, bench/quickreq/s× pinned Rails
Room page7,21530.15×
Messages page7,06218.56×
Sidebar7,33712.26×
Search6,88716.89×
Post a message2,1506.51×

On upstream's harness, against current Rails: room page 0.68×, messages page 1.51×, sidebar 1.47×, search 1.42×, post a message 5.68×.

dotnetway-p9/quick/new

Phase 10

Speed on upstream's harness

One connection a request, the tiering setting, a narrower miss, and the page cache with fresh authorization.

26.5 KLOC, corrected

c=16, bench/quickreq/s× pinned Rails
Room page33,418139.65×
Messages page31,42582.57×
Sidebar39,31365.67×
Search37,66392.33×
Post a message2,4647.47×

On upstream's harness, against current Rails: room page 7.08×, messages page 6.83×, sidebar 7.66×, search 7.83×, post a message 7.24×.

dotnetway-p10/quick/new

Which Rails. The violet line is each phase gate's bench/quick run over the stored medians of the pinned Rails (bench/results/phase7-final); the teal pair is the six-ways bench over current Rails in the same sessions. Both show the thinnest of the five workloads at sixteen clients. Hover, tap or tab to a phase for its numbers.Every phase, as a table

Layer by layer

What the framework replaced.

It started as a fork of the F# port and swapped one layer a phase, each behind the pixel gate, the cookie round trip and the database differential. Hand-written code stays only where Rails parity needs it: the cookie formats, Loofah's sanitizer rules, Rails' markup quirks.

  1. Phase 1

    Data

    In the portCampfire.Db's own SQLite layer: a reader pool, a writer thread, hand-mapped columns and SQL text in every model.

    NowEF Core over Microsoft.Data.Sqlite on Rails' schema, no migrations: pooled contexts, LINQ with parameters, interceptors, one writer behind a gate.

    Campfire.Db 3,307 2,280 linesbackend 39,429 → 38,352

    • EF Core
    • Microsoft.Data.Sqlite
  2. Phase 2

    The HTTP kit

    In the portA hand-written kit: its own request context, params, multipart, cookies, sessions, formats, compression and page splicing.

    NowHttpContext, cookie authentication that reads and writes Rails' signed session cookie, antiforgery, sessions and flash, the framework's response compression.

    Campfire.Kit 8,344 2,838 linesbackend 38,352 → 35,283

    • ASP.NET Core
    • Authentication
    • Antiforgery
  3. Between Phase 2 and Phase 3

    Hot reads on Dapper

    In the portEvery per-request read through EF's LINQ pipeline, the room page's nine statements included.

    NowDapper for the per-request read paths only, in one file, parameters only, each read checked against EF's answer over the seed. EF Core keeps every write, every cold query, the model and the schema.

    Why Dapper is still the .NET way. EF Core for the model, the writes and the transactions, a micro-ORM for the hot queries: that split is the read side of the CQRS pattern in Microsoft's own .NET microservices guide, where eShop's ordering service queries with Dapper and writes with EF Core. It was measured first (a spike on its own branch), kept to one file, and every Dapper read is tested against the EF query it replaced. A statement cache or hand-built SQL would have been faster still; neither is the framework's way, so neither is here.

    Campfire.Db 2,323 2,441 linesbackend 35,283 → 35,408

    • Dapper
    • EF Core
  4. Phase 3

    Action Cable

    In the portA hand-written WebSocket server: framing, a ring buffer, its own pub/sub, JSON text and deflate.

    NowASP.NET Core's WebSocket middleware, a bounded Channel per connection, a hosted service for the heartbeat. Rails' JavaScript client is unchanged.

    Campfire.Cable 1,603 1,051 linesbackend 35,408 → 34,837

    • WebSockets
    • Channel<T>
    • IHostedService
  5. Phase 4

    Views

    In the portA hand-written UTF-8 writer, its own fragment cache and recorded pages.

    NowFalco.Markup, one module per ERB file at the same path, fragments on HybridCache, and a lint that refuses any HTML built from a string.

    Campfire.Views 5,792 5,219 linesbackend 34,837 → 33,723

    • Falco.Markup
    • HybridCache
  6. Phase 5

    Rich text

    In the portA port of an HTML5 parser with a DOM of its own, a sanitizer on top of it and Ruby's URI parser.

    NowAngleSharp's HTML5 parser and DOM, Loofah's rules as one walk over its tree, System.Uri. A fuzz against Rails finds no violation.

    Campfire.RichText 6,191 2,264 linesbackend 33,723 → 30,216

    • AngleSharp
    • System.Uri
  7. Phase 6

    Assets

    In the portAn assets project that computed Propshaft's digests and wrote the manifest.

    NowThe SDK's MapStaticAssets: fingerprints, precompressed files and ETags, fed by a staging target.

    Campfire.Assets 429 0 linesbackend 30,216 → 29,974

    • MapStaticAssets
  8. Phase 7

    The front server

    In the portThruster's job by hand: listeners, TLS, an ACME client, logging and compression in the kit's front end.

    NowKestrel's listeners and limits, Certes for ACME, HTTPS redirection, HSTS, HTTP logging, OutputCache for the public responses.

    Campfire.Kit 2,842 0 linesbackend 29,974 → 27,834

    • Kestrel
    • Certes
    • OutputCache
    • HttpLogging
  9. Phase 8

    Jobs, integrations, push, time

    In the portA Net::HTTP replica, hand-written Web Push encryption, a user-agent parser, a clock and config plumbing.

    NowBackgroundService queues, named HttpClients with a guard at connect, AngleSharp for unfurls, Lib.Net.Http.WebPush, IOptions and TimeProvider.

    Campfire.App 13,011 12,284 linesbackend 27,834 → 27,069

    • BackgroundService
    • IHttpClientFactory
    • Lib.Net.Http.WebPush
    • TimeProvider
    • IOptions
  10. Phase 9

    Rails helpers and storage

    In the portThree small projects for Ruby string behavior, Rails' message formats and the route helpers; storage serving by hand.

    NowOne Campfire.Rails project; storage served through the framework's file results.

    Campfire.Ruby, Campfire.RailsCompat, Campfire.Routes, Campfire.Rails, Campfire.Storage 3,792 2,985 linesbackend 27,069 → 26,210

    • Results.File
  11. Phase 10

    The page cache

    In the portNo page cache: every signed-in page queried, rendered and compressed on every request, and nine connection opens a page.

    NowOne connection per request, then HybridCache in the four GET actions, keyed by user and session. The session and membership are read again on every hit; any commit retires every page.

    Campfire.App 12,232 12,474 linesbackend 26,210 → 26,464

    • HybridCache
    • TimeProvider

Lines per project, phase by phase

Check it

Checked against Rails, cell by cell.

  1. Full pixel gate

    4,918/4,918

    cells equal to Rails on screenshots, the accessibility tree and the loose DOM, at the Phase 10 gate: 5 seeds, 3 browser engines, 4 viewports, light and dark, and a sweep of 6 breakpoint widths. One WebKit cell differed at first by 136 pixels (a WebP avatar decode flake carried since Phase 4); alone it was equal 3 times of 3.

    The details
  2. Over TLS

    28/28

    cells equal with the app serving HTTPS from its own certificate cache.

    The details
  3. Cookie round trip

    20/20

    checks: sign in on Rails, switch the same storage to theDotNetWay and post, then back. Nobody is signed out by an upgrade or a rollback.

  4. Database differential

    Equal

    Fixtures and a long scenario written by Active Record and by EF Core compare equal; the schemas agree; Rails boots on the database theDotNetWay wrote.

  5. Tests

    1,066

    passed of 1,072 in bin/verify on the closing commit, 0 failed, 6 skipped (Linux-only or reference-image tests, run elsewhere), with the markup lint, the Dapper and EF guards and the zero-compilation check.

  6. Security reviews

    6

    independent reviews of the risky layers: views, rich text, assets, the front server, the integrations, then the page cache and the close. Findings were fixed, or accepted with a recorded reason, before each phase closed.

    The details
  7. Assets

    1,806

    network checks on the asset routes (fingerprints, encodings, probes for traversal and dotfiles), 0 failed.

  8. Known differences

    Listed

    Every difference a person or another system could notice has a README entry, the reference file it departs from and a test that pins it.

    The list