Commit ece2bd0
committed
riverlog: use sjson for log append and pruning
The raw-message iteration still rebuilt log arrays through json
marshaling, which left append performance significantly worse than the
baseline implementation used on master.
Switch riverlog history to gjson/sjson so operations stay on raw JSON
arrays. The middleware reads only `river:log` with `gjson`, appends with
`sjson.SetRawBytes` using `-1`, and enforces `MaxTotalBytes` by deleting
oldest entries with `sjson.DeleteBytes("0")`.
Comparison for `BenchmarkMiddlewareWorkAppend` (`-benchtime=100ms`):
case: 256 KB
impl ns/op B/op allocs/op
baseline 976052 645856 291
rawmessage 1605106 698233 293
sjson 614433 1167265 25
case: 2 MB
impl ns/op B/op allocs/op
baseline 7762435 5920954 2096
rawmessage 12516198 6651551 2098
sjson 4485274 6482082 32
The pruning test changed only to avoid a brittle exact-byte boundary.
`MaxTotalBytes` is now set slightly above the two-entry payload so the
test consistently verifies the intended behavior: appending a third
entry drops the oldest and keeps the newest two.1 parent ba3a95e commit ece2bd0
3 files changed
Lines changed: 32 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
162 | 166 | | |
163 | 167 | | |
164 | 168 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | 169 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
| 170 | + | |
174 | 171 | | |
175 | 172 | | |
176 | 173 | | |
| |||
182 | 179 | | |
183 | 180 | | |
184 | 181 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | 182 | | |
190 | 183 | | |
191 | 184 | | |
| |||
221 | 214 | | |
222 | 215 | | |
223 | 216 | | |
224 | | - | |
| 217 | + | |
225 | 218 | | |
226 | 219 | | |
227 | 220 | | |
| |||
242 | 235 | | |
243 | 236 | | |
244 | 237 | | |
245 | | - | |
246 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
247 | 256 | | |
248 | 257 | | |
249 | 258 | | |
| |||
253 | 262 | | |
254 | 263 | | |
255 | 264 | | |
| 265 | + | |
256 | 266 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
| 267 | + | |
| 268 | + | |
261 | 269 | | |
262 | 270 | | |
263 | 271 | | |
| 272 | + | |
| 273 | + | |
264 | 274 | | |
265 | 275 | | |
266 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
| 283 | + | |
| 284 | + | |
284 | 285 | | |
285 | 286 | | |
286 | 287 | | |
| |||
0 commit comments