Commit 0e6be32
committed
storeliveness: refactor channel-based
Previously, outgoing messages in the transport layer were queued using a
buffered channel (`messages chan slpb.Message`). Messages were processed
by pulling them one-by-one from the channel and batching them using a
timer-based approach.
This patch refactors the queue implementation to use a mutex-protected
slice (`msgs []slpb.Message`) instead of a channel. This change
simplifies the batching logic by allowing all queued messages to be
drained atomically in a single operation, rather than pulling them
individually from a channel. With this refactor, we also increase the
queue capacity to 100,000 messages, since the per-store receive queue
size of 10,000 messages (since the send queue is per-node and serves
multiple stores). The refactor also allows the batching mechansim to
use a "sleep-then-drain" approach when compared to the existing
timer-based approach. The timer-based approach had a subtle issue
where `processQueue` would block in a select statement waiting
on `q.messages` while batching, and when a new message was enqueued
(which signals `q.messages`), it would immediately wake up the
blocked goroutine, causing spikes in runnable goroutines.
The new `sendQueue` struct provides `Append()` to add messages, `Drain()`
to atomically retrieve all messages, and `Size()` to track the total
byte size of queued messages. The `processQueue` method now drains all
messages at once and sleeps for the batch duration, rather than using
the previous timer-based batching approach. By sleeping
first and then draining all messages atomically, we avoid the
aforementioned wake-up spikes and achieve better pacing behaviour.
Part of: cockroachdb#148210
Release note: NonesendQueue with slices of slpb.Message
1 parent d6b18ba commit 0e6be32
File tree
3 files changed
+103
-41
lines changed- pkg/kv/kvserver/storeliveness
3 files changed
+103
-41
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
435 | | - | |
| 435 | + | |
436 | 436 | | |
437 | 437 | | |
438 | 438 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
| |||
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
| 59 | + | |
| 60 | + | |
55 | 61 | | |
56 | 62 | | |
57 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
58 | 104 | | |
59 | 105 | | |
60 | 106 | | |
| |||
248 | 294 | | |
249 | 295 | | |
250 | 296 | | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
| 297 | + | |
| 298 | + | |
257 | 299 | | |
258 | 300 | | |
259 | 301 | | |
| |||
263 | 305 | | |
264 | 306 | | |
265 | 307 | | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
266 | 312 | | |
267 | 313 | | |
268 | 314 | | |
269 | 315 | | |
270 | 316 | | |
271 | 317 | | |
272 | 318 | | |
273 | | - | |
| 319 | + | |
274 | 320 | | |
275 | 321 | | |
276 | 322 | | |
| |||
287 | 333 | | |
288 | 334 | | |
289 | 335 | | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
290 | 339 | | |
291 | 340 | | |
292 | 341 | | |
293 | 342 | | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
305 | 348 | | |
306 | 349 | | |
307 | 350 | | |
| |||
362 | 405 | | |
363 | 406 | | |
364 | 407 | | |
365 | | - | |
366 | | - | |
367 | 408 | | |
368 | 409 | | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
369 | 419 | | |
370 | 420 | | |
371 | 421 | | |
| |||
375 | 425 | | |
376 | 426 | | |
377 | 427 | | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
394 | 453 | | |
| 454 | + | |
| 455 | + | |
395 | 456 | | |
396 | 457 | | |
397 | 458 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
| 401 | + | |
401 | 402 | | |
402 | 403 | | |
403 | 404 | | |
| |||
532 | 533 | | |
533 | 534 | | |
534 | 535 | | |
535 | | - | |
| 536 | + | |
536 | 537 | | |
537 | 538 | | |
538 | 539 | | |
| |||
0 commit comments