Skip to content

Commit bd0442f

Browse files
yujiteshimaclaude
andauthored
README: sizing guidance for message_retention (#95)
Explain what the retention has to cover (the slowest subscriber's polling interval, plus a margin for a reconnecting listener) and what the default costs for high-frequency broadcasts: at 60 messages per second, 1.day keeps about 5 million rows (~3.5 GB on SQLite), 5.minutes about 18,000. Measured on solid_cable 4.0.0 and 4.1.0; numbers and discussion in #94. Claude-Session: https://claude.ai/code/session_016abMvkfuZefDveQYGj6XN6 Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 1e4217e commit bd0442f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The options are:
8181
- `connects_to` - set the Active Record database configuration for the Solid Cable models. All options available in Active Record can be used here.
8282
- `polling_interval` - sets the frequency of the polling interval. (Defaults to
8383
0.1.seconds)
84-
- `message_retention` - sets the retention time for messages kept in the database. Used as the cut-off when trimming is performed. (Defaults to 1.day)
84+
- `message_retention` - sets the retention time for messages kept in the database. Used as the cut-off when trimming is performed. (Defaults to 1.day) Messages only need to outlive the slowest subscriber's polling interval, plus some margin for a listener that is reconnecting, so a few minutes is plenty for most apps. The default is generous: an app broadcasting 60 messages per second keeps about 5 million rows (≈3.5 GB on SQLite) with `1.day`, and about 18,000 rows with `5.minutes`.
8585
- `autotrim` - sets wether you want Solid Cable to handle autotrimming messages. (Defaults to true)
8686
- `silence_polling` - whether to silence Active Record logs emitted when polling (Defaults to true)
8787
- `use_skip_locked` - whether to use `FOR UPDATE SKIP LOCKED` when performing trimming. This will be automatically detected in the future, and for now, you'd only need to set this to `false` if your database doesn't support it. For MySQL, that'd be versions < 8, and for PostgreSQL, versions < 9.5. If you use SQLite, this has no effect, as writes are sequential. (Defaults to true)
@@ -126,7 +126,7 @@ with Rails 7. Solid Cable raises during boot for that unsupported combination.
126126

127127
## Trimming
128128

129-
Messages are autotrimmed based upon the `message_retention` setting to determine how long messages are to be kept around. If no `message_retention` is given or parsing fails, it defaults to `1.day`. For every message written, Solid Cable attempts to trim twice as many expired messages.
129+
Messages are autotrimmed based upon the `message_retention` setting to determine how long messages are to be kept around. If no `message_retention` is given or parsing fails, it defaults to `1.day`. For every message written, Solid Cable attempts to trim twice as many expired messages, so the table settles at roughly `broadcast rate × message_retention` rows. If you broadcast many times per second, lowering `message_retention` matters more than tuning the trim batch size.
130130

131131
Autotrimming can negatively impact performance slightly depending on your workload because it is potentially doing a delete on broadcast. If
132132
you would prefer, you can disable autotrimming by setting `autotrim: false` and you can manually enqueue the job later, `SolidCable::TrimJob.perform_later`, or run it on a recurring interval out of band.

0 commit comments

Comments
 (0)