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.
current Rails, each route alone, on Basecamp's own harness in the same sessions. 9.43×–11.75× while a writer posts.
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.
| Group | Workload | theDotNetWay75487b7 | onCrack3770dff | F# port9954ad0 | Railsca9b963 | Rust6dae2fd | C873a51f |
|---|---|---|---|---|---|---|---|
| Each route alone | |||||||
| Each route alone | Room page req/s | 34,9897.08× Rails | 169,088 | 35,619 | 4,944 | 49,902 | 77,135 |
| Messages page req/s | 33,8316.83× Rails | 179,077 | 42,126 | 4,953 | 47,112 | 77,086 | |
| Sidebar req/s | 41,5817.66× Rails | 190,320 | 38,195 | 5,425 | 55,561 | 83,137 | |
| Search req/s | 41,3257.83× Rails | 184,644 | 34,009 | 5,280 | 55,920 | 82,402 | |
| Post a message req/s | 2,9017.24× Rails | 15,149 | 9,516 | 401 | 6,498 | 5,858 | |
| Reads while a writer posts 10/s | |||||||
| Reads while a writer posts 10/s | Room page req/s | 32,88611.75× Rails | 163,174 | 33,217 | 2,800 | 47,411 | 71,829 |
| Messages page req/s | 33,0129.54× Rails | 178,188 | 41,137 | 3,461 | 45,002 | 73,843 | |
| Sidebar req/s | 40,2469.43× Rails | 187,713 | 37,798 | 4,267 | 55,628 | 82,396 | |
| Search req/s | 39,6109.70× Rails | 182,965 | 34,790 | 4,084 | 54,140 | 79,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
- Each route alone
- Room page0.68×7.08×
- Messages page1.51×6.83×
- Sidebar1.47×7.66×
- Search1.42×7.83×
- Post a message5.68×7.24×
- Reads while a writer posts 10/s
- Room page1.06×11.75×
- Messages page2.02×9.54×
- Sidebar1.76×9.43×
- Search1.77×9.70×
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.
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/quick | req/s | × pinned Rails |
|---|---|---|
| Room page | 7,215 | 30.15× |
| Messages page | 7,062 | 18.56× |
| Sidebar | 7,337 | 12.26× |
| Search | 6,887 | 16.89× |
| Post a message | 2,150 | 6.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×.
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/quick | req/s | × pinned Rails |
|---|---|---|
| Room page | 33,418 | 139.65× |
| Messages page | 31,425 | 82.57× |
| Sidebar | 39,313 | 65.67× |
| Search | 37,663 | 92.33× |
| Post a message | 2,464 | 7.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×.
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.
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
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
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
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
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
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
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
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
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
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
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
Check it
Checked against Rails, cell by cell.
Full pixel gate
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 detailsOver TLS
cells equal with the app serving HTTPS from its own certificate cache.
The detailsCookie round trip
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.
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.
Tests
passed of 1,072 in
bin/verifyon 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.Security reviews
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 detailsAssets
network checks on the asset routes (fingerprints, encodings, probes for traversal and dotfiles), 0 failed.
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