lowrail-profile 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README-profile.md +307 -0
- data/data/contributions-index.json +1 -0
- data/exe/lowrail-profile +335 -0
- data/ext/lowrail_profile/extconf.rb +4 -0
- data/ext/lowrail_profile/lowrail_profile.c +670 -0
- data/lib/lowrail/load_hooks.rb +133 -0
- data/lib/lowrail/loaded_constant.rb +31 -0
- data/lib/lowrail/profile.rb +521 -0
- data/lib/lowrail/profile_compare.rb +347 -0
- data/lib/lowrail/profile_report.rb +777 -0
- data/lib/lowrail/profile_version.rb +7 -0
- data/lib/lowrail/profile_workloads.rb +157 -0
- data/lib/lowrail/workloads.rb +489 -0
- metadata +60 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5d819dc34a7335f95ea402ab8bdf78a794cc47b49e13809d0a2d39222793e2f6
|
|
4
|
+
data.tar.gz: 0c65fb863b9ffa2ece574ca95cb9058ceaafa47570a7911470f023749d24ad17
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 39a163f995d93938e2af47260aaa977613555496ee530e54f1ce9bb3d397fb1cade34f59307b7388085656679c6f2b794db7a2a02984bbdaf49143e24ed081de
|
|
7
|
+
data.tar.gz: 1a051e40f2196d5b807712cb35db1e68253dd7725832b9516ac62c44211372aa7c95eca62f751823a6a19093211a266514e0e4ba1c1206720c7e364edfd18804
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thomas Klemm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README-profile.md
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
# lowrail-profile
|
|
2
|
+
|
|
3
|
+
**Exact object allocation counts for your Rails app, per request, job, mail and Action Cable action, by source
|
|
4
|
+
line, in your code and in the Rails, Ruby and gem code it calls.** It runs your test suite (or a recorded request
|
|
5
|
+
mix) with allocation counting on and tells you which lines allocate the most per request, which of your lines lead
|
|
6
|
+
there, and whether an upstream pull request already changes that line.
|
|
7
|
+
|
|
8
|
+
It counts objects. It does not measure time, CPU, retained memory or SQL, and it never changes or lowers your app.
|
|
9
|
+
For time, pair it with [vernier](https://github.com/jhawthorn/vernier) or your APM.
|
|
10
|
+
|
|
11
|
+
Experimental (0.1.2). Supported: Ruby 3.3, 3.4 and 4.0; Rails 7.2, 8.0 and 8.1; Linux and
|
|
12
|
+
macOS. Windows is refused with a message.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
# Gemfile
|
|
18
|
+
gem "lowrail-profile", group: [:development, :test], require: false
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Until 0.1.2 is on rubygems.org, build it from a Lowrail checkout. The gemspec's file list is
|
|
22
|
+
relative to `gem/`, so build it there:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
cd lowrail/gem && gem build lowrail-profile.gemspec && gem install --local lowrail-profile-0.1.2.gem
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or let Bundler take it from GitHub:
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
gem "lowrail-profile", github: "thomasklemm/lowrail", glob: "gem/lowrail-profile.gemspec", group: [:development, :test], require: false
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
That checks out the whole Lowrail repository for each revision, about 530 MB of files (700 MB on disk in one
|
|
35
|
+
install, under Bundler's `bundler/gems`), plus about 250 MB of git cache, against 90 KB for the built gem.
|
|
36
|
+
|
|
37
|
+
`require: false` matters: nothing of the gem loads in your app unless you run the command below. The first run
|
|
38
|
+
compiles a small C extension (the counter) into `~/.cache/lowrail/profile/`, outside your app; it needs a C compiler
|
|
39
|
+
and Ruby's headers, which `bundle install` of a Rails app already needs. A compile failure stops the profiler with
|
|
40
|
+
the build log's path; it never touches `bundle install` or your app's boot.
|
|
41
|
+
|
|
42
|
+
## Three commands
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
bundle exec lowrail-profile -- bin/rails test # or: -- bundle exec rspec
|
|
46
|
+
bundle exec lowrail-profile report # rebuild the report (needs --keep-runs)
|
|
47
|
+
bundle exec lowrail-profile compare base/report.json head/report.json --aa base2/report.json
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The first runs the command twice (everything after `--` is passed unchanged) and writes `tmp/lowrail-profile/report.md`
|
|
51
|
+
and `report.json`. It prints the report too. The suite runs as it would, with `SEED` and `--seed` fixed (default
|
|
52
|
+
1234) so both runs order tests the same way. Only the suite's own process gets the seed and the profiler: once
|
|
53
|
+
Minitest or RSpec has read its options, any process the suite starts (a rake task, an `after(:suite)` that runs
|
|
54
|
+
rspec again) sees the environment you gave lowrail-profile. A process the command starts before its suite runs,
|
|
55
|
+
such as `rake test`'s parent, passes both on to the suite. A process started earlier than Minitest's or RSpec's own start (while `test_helper.rb` or `spec_helper.rb` loads, or from a plain `Minitest::Test` suite without `ActiveSupport::TestCase`) still gets the profiler and the seed. lowrail-profile exits with its status: the first failing run's exit
|
|
56
|
+
code, or 128 plus the signal that stopped it (143 for `TERM`), and 124 when a run timed out. A passing suite whose report cannot be built exits 1.
|
|
57
|
+
|
|
58
|
+
Bypass Spring (`DISABLE_SPRING=1`, or `bin/rails test` without a Spring binstub): a Spring server that is already
|
|
59
|
+
running forks the app without loading the profiler, so the run counts nothing and lowrail-profile exits 1 with *no
|
|
60
|
+
runs with requests*.
|
|
61
|
+
|
|
62
|
+
Options, all before `--`:
|
|
63
|
+
|
|
64
|
+
| Option | Default | |
|
|
65
|
+
| --- | --- | --- |
|
|
66
|
+
| `--out DIR` | `tmp/lowrail-profile` | A new or empty directory, or one lowrail-profile made (it leaves a `.lowrail-profile` marker). It refuses any other directory and deletes nothing in it. |
|
|
67
|
+
| `--runs N` | 2 | Runs of the command; their spread is part of compare's noise floor. |
|
|
68
|
+
| `--top N` | 30 | Rows per table. |
|
|
69
|
+
| `--seed N` | 1234 | `SEED` and `--seed` for every run. |
|
|
70
|
+
| `--ledger FILE` | bundled | A newer ledger index (`contributions-index.json`). |
|
|
71
|
+
| `--no-ledger` | | No ledger column. |
|
|
72
|
+
| `--keep-runs` | | Keep each run's raw counts (`run1/`, `run2/`), which `report` rebuilds from. Without it they are deleted once the report is written: compare needs only `report.json`, and on a large parallel suite the counts reach gigabytes. |
|
|
73
|
+
| `--timeout SECONDS` | none | Stop a run that takes longer: `TERM` to the command's process group, `KILL` 10 s later. `TERM` then `KILL` go to every process the run started, also when the first one exits on `TERM`, and to the processes it started in a group of their own (as selenium-webdriver starts its driver and browser) that are still found from the run at the deadline or during those 10 s: its descendants and the members of their groups. A process whose parent exited before the deadline and that is in a group of its own (a daemon) is no longer found and keeps running. lowrail-profile exits once the others are gone, at most about 10 s after the deadline. No further run starts, lowrail-profile exits 124 (also after an earlier failed run), the report says which run timed out, and compare treats the capture as a failed suite (exit 2). With it the command runs in its own process group, and lowrail-profile passes `INT`, `TERM`, `HUP` and `QUIT` on to it; a debugger that reads the terminal (`binding.irb`) stops there, so leave `--timeout` off to debug. |
|
|
74
|
+
| `--help`, `--version` | | |
|
|
75
|
+
|
|
76
|
+
## Reading the report
|
|
77
|
+
|
|
78
|
+
The header says what was counted: command, Ruby, Rails and environment, how many requests, jobs, mails and Cable
|
|
79
|
+
actions, and the ledger's date. Its table gives objects per request by run twice: *all* counts every request with the
|
|
80
|
+
one-time work of each process's first requests, *warm* leaves each line's first request per process out, as the
|
|
81
|
+
noise floor and the tables below do; compare the warm number. A file `ActionDispatch::Static` serves (`public/`,
|
|
82
|
+
precompiled assets) answers before routing: it is a request named `ActionDispatch::FileHandler#serve`, and the
|
|
83
|
+
header says how many there were and the objects per request without them. Assets a mounted Rack app serves (Sprockets
|
|
84
|
+
in development and test) have no action name. Then:
|
|
85
|
+
|
|
86
|
+
* **Your code.** Per app line, the objects Rails, Ruby and gems allocate below it per request: the nearest app
|
|
87
|
+
line on the stack of every allocation (the second run walks the stack to find it). *Own* is what the line itself
|
|
88
|
+
allocates; *Dev/test* is work production mostly does not do (see below).
|
|
89
|
+
* **Actions.** Objects per request by controller action, per run. *Warm* leaves out each action's first request in
|
|
90
|
+
each process, which carries one-time work (route table, template compilation, I18n load); `–` means it ran once
|
|
91
|
+
per process. An action with fewer than 2 warm requests in a run comes last, ranked by all objects: one request is
|
|
92
|
+
a sample, not a mean. *Δ* is the last run minus the first: the noise.
|
|
93
|
+
* **Top lines outside the app.** Per line in Rails, Ruby and gems: warm and all objects per request, *Reach* (the
|
|
94
|
+
share of requests in which it allocated), the object types, the app lines that lead there, and *Ledger*. A † means
|
|
95
|
+
objects from Ruby's `<internal:…>` code charged to the line that called it.
|
|
96
|
+
* **Dev/test-mode work.** Debug logging, error pages, template compilation, route building, asset lookup and reload
|
|
97
|
+
checks, apart, so a suite profile is not read as production cost.
|
|
98
|
+
* **By gem**: warm and all objects per request by group, with dev/test-mode work as a group of its own; groups
|
|
99
|
+
with no warm objects are named in one line below it. A line `:0` has no line number: allocated while Ruby loaded or
|
|
100
|
+
compiled the file, or by code evaluated without one. In *From the app*, *(middleware)* marks app middleware that
|
|
101
|
+
hands the request on: it is the nearest app line of work done after the request's code returned or raised (an
|
|
102
|
+
error page), not the line that raised, which is no longer on the stack.
|
|
103
|
+
* **Outside requests**: jobs (`perform_now`), mails (build and delivery) and Cable actions, counted
|
|
104
|
+
the same way. A job or mail inside a request counts as part of that request.
|
|
105
|
+
|
|
106
|
+
Line keys are `RAILS/<component>/path:line`, `GEM/<name>/path:line`, `RUBY/path:line` and `APP/path:line`.
|
|
107
|
+
|
|
108
|
+
**Ledger.** A dated snapshot of upstream pull requests that reduce allocations ships with the gem. A line matches
|
|
109
|
+
when a pull request changes that very line (same repository, file and method, and the line's code is among the
|
|
110
|
+
lines it removes or adds; a line that opens a brace block, as `fetch(oid) {` in one version, also matches the same call
|
|
111
|
+
written as a one-line block in another). The cell says what that means for the version your lockfile runs: *open upstream work*,
|
|
112
|
+
*fixed in 8.2.0* (upgrade), *merged, not released yet*, or *merged, in 7.2.3, which this app runs*. The ledger covers
|
|
113
|
+
the pull requests its authors track, not every upstream fix, and a snapshot goes stale: the header gives its date.
|
|
114
|
+
|
|
115
|
+
**Counts are not time.** A line with many objects is a place to look; some allocations are cheap. **A suite is not
|
|
116
|
+
traffic**: it requests what tests need, with a test user agent, in test mode. `--workloads` (below) gets closer.
|
|
117
|
+
|
|
118
|
+
## Compare
|
|
119
|
+
|
|
120
|
+
`compare BASE.json HEAD.json --aa BASE2.json` lists the lines and actions that grew or shrank beyond their noise
|
|
121
|
+
floor and exits **0** whatever it lists: in 0.1 it is a report, not a CI gate (below). It exits **2** when the reports
|
|
122
|
+
are not valid evidence: a failing suite, one run, a different command, seed, Ruby or environment, dropped samples,
|
|
123
|
+
unfinished windows, a capture of more than one process, a report of another version, or the base passed as its own
|
|
124
|
+
A/A report; an A/A report with exactly the base's counts (a copy?) is compared with a warning. `BASE2` is a second profile
|
|
125
|
+
of the unchanged base: the A/A pair sets the floor per row (twice the larger of a row's spread across both base
|
|
126
|
+
profiles and head's own spread; for a line at least `--min`, default 1 object per request, for an action at least
|
|
127
|
+
0.1% of its objects and 20 × `--min`). Without `--aa` the floor is the spread inside one capture, which misses how
|
|
128
|
+
much invocations differ. `--json` prints the result as JSON.
|
|
129
|
+
|
|
130
|
+
**Profile in one process.** Warm leaves out each process's first request of an action, and parallel test workers
|
|
131
|
+
split the tests anew in every capture, so which requests those are, where one-time work lands and which code paths
|
|
132
|
+
run change between captures: on openstreetmap-website (8 workers, the same code) `NotesController#index` read 8,063
|
|
133
|
+
warm objects per request in one capture and 26,106 in the next. compare refuses such captures (exit 2), and the
|
|
134
|
+
capture itself says so on the terminal and at the top of the report. Set
|
|
135
|
+
`PARALLEL_WORKERS=1` for `parallelize`, and run `parallel_tests` and similar runners without them.
|
|
136
|
+
|
|
137
|
+
**Why there is no gate in 0.1.** Over every assignment of unchanged captures to base, A/A and head, captured in one
|
|
138
|
+
process, compare listed a regression for 0 of 24 heads on openstreetmap-website, 0 of 120 on Writebook, 0 of 1,320
|
|
139
|
+
on a fresh Rails 8.1 app and 1.7% on a generated Blog, but 12.5% on Hackatime, and 4.4% even when a second profile
|
|
140
|
+
of head had to show it too. Hackatime's `Admin::AdminUsersController#index` reads 14,700–14,730 or 14,785–14,817
|
|
141
|
+
warm objects per request by capture with the same code: a 0.7% move with the data, which one A/A pair does not
|
|
142
|
+
sample. With parallel workers it was worse (openstreetmap-website 79%, Hackatime 52.5%, Writebook 26.7%). A job that
|
|
143
|
+
fails on unchanged code that often does more harm than good, so treat what compare lists as places to look
|
|
144
|
+
([the measurements](https://github.com/thomasklemm/lowrail/blob/main/docs/profile-gate-design.md)).
|
|
145
|
+
|
|
146
|
+
**What it can find.** In one process, an action change of about 20 objects per request, or 0.1% of the action if
|
|
147
|
+
that is larger: a planted `Array.new(200) { Object.new }` in openstreetmap-website's `NotesController#index` showed
|
|
148
|
+
as +168 against a floor of 27 (of 26,402), `20.times { ERB::Util.html_escape("a<b") }` in Campfire's
|
|
149
|
+
`RoomsController#show` as +44 against 26 and in Writebook's `SessionsController#create` as +55 against 20. A line
|
|
150
|
+
needs 1 object per request averaged over all requests of its kind, so a change in one action moves its lines only by
|
|
151
|
+
that action's share of the requests. Not found: the same `html_escape` plant in Hackatime's
|
|
152
|
+
`LeaderboardsController#index` (+40–60 on about 7,900, twice that action's own noise: listed in half the
|
|
153
|
+
comparisons), and with workers Writebook's plant in an action that runs once per worker process. An action that runs
|
|
154
|
+
once per process has no warm value and is not compared. Captures taken at different times differ on the same code
|
|
155
|
+
whenever the app's work depends on the clock or the date: on Forem, half an hour apart, compare listed five actions,
|
|
156
|
+
four by 0.1% to 0.25% and `ResponseTemplatesController#update` 15,028 → 15,154 (+0.8%); in a field test two captures
|
|
157
|
+
three hours apart, compared without `--aa`, listed an index action at +3.1% from app code that allocates by the date
|
|
158
|
+
and time. So a small listed change is a hint, not proof: profile the base twice, right before head, pass the second
|
|
159
|
+
with `--aa`, and freeze time in the tests that depend on it (`travel_to`).
|
|
160
|
+
|
|
161
|
+
**Network connects are left out.** What `Socket.tcp` allocates while it connects follows timing, not code: it races
|
|
162
|
+
its connection attempts on threads and timers. On Hackatime ViteRuby probes its dev server at most once a second,
|
|
163
|
+
and whichever request came first after each second paid about 400 objects for it. Objects allocated inside a
|
|
164
|
+
`Socket.tcp` call without a block, in the thread or fiber of the request, job, mail or Cable action, are left out of
|
|
165
|
+
its action and its lines, and the report and compare say how many by run (*Left out* in the report's header,
|
|
166
|
+
`network` per action and run). Only the connect is left out: a read or write on the socket is compared like any
|
|
167
|
+
other line, and `Socket.tcp` with a block is counted whole, since the block is the app's own work. The hook is a
|
|
168
|
+
module prepended to `Socket` once the app has loaded it; one object per call, allocated before it marks the connect,
|
|
169
|
+
stays in the action.
|
|
170
|
+
|
|
171
|
+
**Reset the test database before every capture** (`bin/rails db:test:prepare`, as the CI job below does). Record IDs
|
|
172
|
+
grow across runs, and their digits change what Rails and Rack allocate to encode them: on CASA,
|
|
173
|
+
`ChecklistItemsController#new` read 3,511 warm objects per request with IDs from 9,000 and 3,494 from 100,000, all of
|
|
174
|
+
it in `uri/common.rb:456`, with the same code. A capture after another one without a reset starts where the last one
|
|
175
|
+
stopped.
|
|
176
|
+
|
|
177
|
+
An action is compared only under the same name in every report: a renamed or new action, or one that ran in base
|
|
178
|
+
only, is listed under *Not compared* with the reason, and nothing about its own cost is listed; how many and why is
|
|
179
|
+
said above the tables. Lines outside the app it reaches are still compared.
|
|
180
|
+
|
|
181
|
+
A GitHub Actions job that profiles the pull request's base twice and its head once, in one process, and publishes
|
|
182
|
+
the comparison as the job summary and the reports as an artifact. It never fails on what compare lists:
|
|
183
|
+
|
|
184
|
+
```yaml
|
|
185
|
+
lowrail-profile:
|
|
186
|
+
runs-on: ubuntu-latest
|
|
187
|
+
env:
|
|
188
|
+
PARALLEL_WORKERS: 1 # one process: compare refuses captures of parallel workers
|
|
189
|
+
steps:
|
|
190
|
+
- uses: actions/checkout@v4
|
|
191
|
+
with: { fetch-depth: 0 }
|
|
192
|
+
- uses: ruby/setup-ruby@v1
|
|
193
|
+
with: { bundler-cache: true }
|
|
194
|
+
- name: Profile base
|
|
195
|
+
run: |
|
|
196
|
+
git checkout ${{ github.event.pull_request.base.sha }}
|
|
197
|
+
bin/rails db:test:prepare
|
|
198
|
+
bundle exec lowrail-profile --out tmp/base -- bin/rails test
|
|
199
|
+
bin/rails db:test:prepare # every capture starts at the same record IDs
|
|
200
|
+
bundle exec lowrail-profile --out tmp/base2 -- bin/rails test
|
|
201
|
+
- name: Profile head
|
|
202
|
+
run: |
|
|
203
|
+
git checkout ${{ github.event.pull_request.head.sha }}
|
|
204
|
+
bin/rails db:test:prepare
|
|
205
|
+
bundle exec lowrail-profile --out tmp/head -- bin/rails test
|
|
206
|
+
- name: Compare
|
|
207
|
+
if: always() # also after a failing suite: compare then exits 2, which the summary shows
|
|
208
|
+
run: |
|
|
209
|
+
bundle exec lowrail-profile compare tmp/base/report.json tmp/head/report.json --aa tmp/base2/report.json \
|
|
210
|
+
>> "$GITHUB_STEP_SUMMARY" || echo "compare exited $?: not valid evidence, see above" >> "$GITHUB_STEP_SUMMARY"
|
|
211
|
+
- uses: actions/upload-artifact@v4
|
|
212
|
+
if: always()
|
|
213
|
+
with: { name: lowrail-profile, path: "tmp/*/report.*" }
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Both checkouts need the gem in their Gemfile; if the base does not have it yet, run the base step with the head's
|
|
217
|
+
Gemfile (`BUNDLE_GEMFILE`). lowrail-profile exits with the suite's status, so a failing suite fails its Profile step
|
|
218
|
+
and the job; Compare and the upload still run (`if: always()`), and compare exits 2, which the summary shows. The job runs the suite three times, twice each, in one process: on openstreetmap-website, whose suite
|
|
219
|
+
takes 81 s on 8 workers, a capture took about 9.5 minutes. `--runs` and a narrower command (`bin/rails test
|
|
220
|
+
test/controllers test/integration`) make it cheaper.
|
|
221
|
+
|
|
222
|
+
## Experimental: `--record` and `--workloads`
|
|
223
|
+
|
|
224
|
+
```sh
|
|
225
|
+
bundle exec lowrail-profile --record -- bin/rails test # also write lowrail/workloads.rb
|
|
226
|
+
RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1 bundle exec lowrail-profile --workloads
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
In production the app needs what a deploy prepares: its database, with the records the file names (`Article.first!`),
|
|
230
|
+
and compiled assets (`RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1 bin/rails db:prepare assets:precompile`). A new
|
|
231
|
+
Rails 7.2 app's SQLite `config/database.yml` names no production database, so set
|
|
232
|
+
`database: storage/production.sqlite3` there first; a default Rails 8 app names one. With neither `RAILS_ENV` nor
|
|
233
|
+
`RACK_ENV` set, `--workloads` runs in development on the development database.
|
|
234
|
+
|
|
235
|
+
`--record [FILE]` writes the suite's 20 most frequent request shapes as `lowrail/workloads.rb` (or
|
|
236
|
+
`tmp/lowrail-profile/workloads.rb` when that file exists): route helpers on each model's first row, values as quoted
|
|
237
|
+
literals, filtered through the app's `filter_parameters` (`[FILTERED]`), only GETs that replay as recorded enabled
|
|
238
|
+
and every other shape commented out with its reason. It is recorded from real requests: check it for secrets the
|
|
239
|
+
filter does not name before you commit it.
|
|
240
|
+
|
|
241
|
+
`--workloads [FILE]` boots the app with `bin/rails runner` in the current `RAILS_ENV`, evaluates the file after boot
|
|
242
|
+
and sends its requests 10 times as warmup and 20 times counted, through the full middleware stack, with a browser's
|
|
243
|
+
headers, the file's sign-in, CSRF tokens and cookies. The file is Ruby in `ActionDispatch::IntegrationTest`'s words:
|
|
244
|
+
|
|
245
|
+
```ruby
|
|
246
|
+
article = Article.first!
|
|
247
|
+
get articles_path
|
|
248
|
+
get article_path(article), headers: { "Accept" => "text/html" }
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
**The requests are real.** Without `--allow-writes` it sends only GETs: a file with a write, a POST sign-in, a
|
|
252
|
+
`setup` block, `jobs: true`, or a GET that would reach the app as another method (an `env:` or header that changes
|
|
253
|
+
it, or a JSON GET with params in an app without `Rack::MethodOverride`) is refused before anything is sent, and so
|
|
254
|
+
is `RAILS_ENV=production` with a writable database on another host (any configuration but a replica, including
|
|
255
|
+
`database_tasks: false` ones) or a database configuration that does not load. The guard checks each request as the
|
|
256
|
+
file declares it; what a block or `alternate:` returns per turn (a path and params, never a method) is not checked
|
|
257
|
+
again. With `--allow-writes` the requests write to the app's database, enqueue through its queue adapter
|
|
258
|
+
and deliver mail as configured: use a disposable database, queue and mail service. `--workloads` needs the gem in a
|
|
259
|
+
group the environment's `bundle install` keeps.
|
|
260
|
+
|
|
261
|
+
## Guarantees
|
|
262
|
+
|
|
263
|
+
Each is checked by a test in this gem or on the apps below.
|
|
264
|
+
|
|
265
|
+
1. **No app changes.** It writes only inside `--out` and the `--record` target, and never edits the Gemfile,
|
|
266
|
+
config or code. Processes the suite starts run unprofiled, without its seed: on Dawarich an `after(:suite)` that
|
|
267
|
+
regenerates `swagger.yaml` with a nested rspec rewrote it in a different order when that rspec got the seed.
|
|
268
|
+
2. **No lowering.** The package holds only the profiler; it never loads Lowrail's runtime.
|
|
269
|
+
3. **Off means off.** With the gem listed and `require: false`, a process the command did not start loads none of
|
|
270
|
+
it.
|
|
271
|
+
4. **Same outcomes.** On Campfire, Lobsters, CodeTriage and a Rails 7.2 / Ruby 3.3 blog, installed from this gem
|
|
272
|
+
on Linux, per-test outcomes were identical plain, listed-but-off and profiled. CodeTriage prints an outcome for
|
|
273
|
+
217 of its 222 tests; for the other 5 only the suite's totals (0 failures) are compared. Each app process loaded
|
|
274
|
+
the same files in the same order as `bundle exec env COMMAND` (the process boundary the profiler starts the
|
|
275
|
+
command at; a plain `bundle exec COMMAND` loads Bundler's own files differently), leaving out Lowrail's,
|
|
276
|
+
Bundler's and RubyGems' files and, on CodeTriage, 27 yard handler and code-object files that yard loads by
|
|
277
|
+
walking `Module#constants`, in an order of its own. On macOS, Campfire's per-test outcomes were identical; its
|
|
278
|
+
load order was not compared there
|
|
279
|
+
([the evidence](https://github.com/thomasklemm/lowrail/blob/main/docs/profile.md)). That is a claim about those
|
|
280
|
+
apps, not every app. Check yours: run the suite plain and profiled with the same seed and diff the
|
|
281
|
+
per-test results (`bin/rails test -v`, `rspec --format documentation`).
|
|
282
|
+
5. **Exit status passes through** (a failed or killed run's status, above), and compare never turns invalid
|
|
283
|
+
evidence green (exit 2).
|
|
284
|
+
6. **Never breaks the app.** A counter that fails to build stops lowrail-profile before the command starts, with
|
|
285
|
+
the build log's path; the app never runs half-profiled. Once the command runs, a counter that fails to load or
|
|
286
|
+
is of another version, or a framework hook that cannot be installed, prints one `[lowrail-profile]` warning and
|
|
287
|
+
leaves the app as it is. Hooks are installed from Active Support's `on_load` hooks, so nothing loads earlier
|
|
288
|
+
than the app loads it.
|
|
289
|
+
|
|
290
|
+
## Troubleshooting
|
|
291
|
+
|
|
292
|
+
* *building the counter failed, see …build.log*: install a C compiler and Ruby's headers (`build-essential` on
|
|
293
|
+
Debian/Ubuntu, Xcode Command Line Tools on macOS).
|
|
294
|
+
* *no runs with requests, jobs or mails*: the command served no request through `Rails.application` (unit tests
|
|
295
|
+
only, a server started in another process, or a warm Spring server: bypass it with `DISABLE_SPRING=1`). Profile
|
|
296
|
+
integration, request or system tests. Controller tests (`ActionController::TestCase`, rspec-rails controller
|
|
297
|
+
specs) call the controller directly, without the app's middleware and routing, and are not counted: a suite of
|
|
298
|
+
only those counts no requests, and in a mixed suite the report covers its integration tests alone. The report and
|
|
299
|
+
this error say how many requests the controller tests made. Rails' generated `test/controllers` tests are
|
|
300
|
+
integration tests and are counted.
|
|
301
|
+
* *exists and was not created by lowrail-profile*: pick another `--out`; it never clears a directory it did not make.
|
|
302
|
+
* Overhead: the first run counts (4–9% of suite time on the four apps measured), the second also walks the stack
|
|
303
|
+
per allocation (31–87%, most on allocation-heavy suites such as Campfire's). Measured per app in the evidence.
|
|
304
|
+
* Code in Ractors other than the main one is not counted.
|
|
305
|
+
|
|
306
|
+
Report issues with `report.json`, `capture.json` and the command at
|
|
307
|
+
[github.com/thomasklemm/lowrail/issues](https://github.com/thomasklemm/lowrail/issues).
|