Skip to content

Add a blog benchmark that writes - #575

Open
thomasklemm wants to merge 1 commit into
ruby:mainfrom
thomasklemm:thomasklemm/blog-benchmark
Open

thomasklemm wants to merge 1 commit into
ruby:mainfrom
thomasklemm:thomasklemm/blog-benchmark

Conversation

@thomasklemm

@thomasklemm thomasklemm commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

The Rails benchmarks here mostly read: in their timed iterations none of them submits a form, fails a validation, or runs after-commit callbacks.

This adds blog, the app built by the create-blog script from Sam Ruby's Roundhouse (MIT or Apache-2.0): a rails new --css tailwind app on Rails 8.1.4.1 with Article and Comment scaffolds, validations and Turbo broadcasts, on the default SQLite, Solid Cache, Queue and Cable. Each iteration makes about 420 in-process requests (reads, creates, updates, deletes, comments and a create that fails with 422) with real CSRF tokens, checks every response, and rolls back one transaction per database at the end, as Rails tests do. It works on Rails 8.1 and main.

It runs code the others don't: a small busy loop in save and destroy adds 2.3% to blog's instructions and never runs in railsbench's or lobsters' timed iterations. From Rails 8.1.4.1 to main, its reads take about a tenth fewer instructions while creates and updates don't get faster.

An iteration takes about 2 s in the interpreter and about 1 s with YJIT or ZJIT. The README lists every change to the generated app and what the rollback leaves out.

Would a write workload like this be welcome? Happy to reshape it.

@thomasklemm thomasklemm changed the title The Rails benchmarks here mostly read. In their timed iterations none of them submits a form, fails a validation, or runs after-commit callbacks, while real apps spend much of their time saving records. Add a blog benchmark that writes Nov 6, 2026
@thomasklemm
thomasklemm force-pushed the thomasklemm/blog-benchmark branch 2 times, most recently from d761531 to 24a4eda Compare November 18, 2026 00:29
@thomasklemm
thomasklemm marked this pull request as ready for review November 18, 2026 00:29
The Rails benchmarks here mostly read. In their timed iterations none
of them submits a form, fails a validation, or runs after-commit
callbacks and broadcasts; lobsters' only writes are its read-ribbon
bookkeeping. Real apps spend much of their time saving records:
validations, callbacks, transactions, INSERT/UPDATE/DELETE and
enqueuing jobs.

The app is the one the create-blog script from Sam Ruby's Roundhouse
(roundhouse-rb/roundhouse, MIT or Apache-2.0, used here under MIT)
builds: rails new --css tailwind on Rails 8.1.4.1, with Article and
Comment scaffolds, validations and Turbo broadcasts. It keeps the
production defaults of rails new: SQLite, Solid Cache, Solid Queue,
Solid Cable, Propshaft and importmap, no external services. The built
Tailwind CSS is checked in, so no CSS build runs.
benchmarks/blog/README.md lists the changes to the generated tree.

Generated files that only deployment, development, tests or a web
server use are left out: .kamal/, config/deploy.yml, bin/ except
rails and rake, public/, test/, the development and test environments,
the Puma, recurring-task, CI, bundler-audit and RuboCop config,
Procfile.dev, db/migrate (db/schema.rb creates the tables), the PWA
views, the mailer and its layouts, ApplicationJob, the empty helpers
and the .keep files in lib/, script/, vendor/, log/, tmp/,
app/assets/images/ and the concerns/ directories. Every response is
the same without them. The Gemfile keeps its default group without
kamal, thruster, puma, bootsnap and tailwindcss-rails, since the app
runs in-process and the CSS is already built; setup installs 43 fewer
gems.

Each iteration runs 200 seeded visits in-process, like railsbench:
reads (index, show, JSON) and writes (create, update and delete
articles, add and delete comments, a create that fails validation
with 422). Writes submit the CSRF token from the page's form, as a
browser does, and every response's status is checked, along with a
body marker or the redirect target. The iteration runs in one
transaction per database that is rolled back at the end, as in Rails
tests, so every iteration sees the same rows and IDs. Rails 8.1 opens
that transaction in pin_connection!; since rails/rails 9e8fe3955b it
no longer does, so benchmark.rb opens it itself when none is open,
and works on both. Time.now starts at a fixed date and advances one
second per visit, so the work doesn't depend on the date and updates
still write updated_at.

Saves run as savepoints inside that transaction, and their
after-commit callbacks run when the savepoint is released, as in Rails
tests. Solid Cable inserts each broadcast in the request rather than
on its batching writer thread, so it lands in the transaction; the
later broadcasts are enqueued into Solid Queue. Since nothing commits,
a real COMMIT is not measured.
@thomasklemm
thomasklemm force-pushed the thomasklemm/blog-benchmark branch from 24a4eda to eb8364d Compare November 18, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant