Commit ec33fbb
committed
Untangles the spaghetti of shard management code by removing the
middleman `ShardQueuer` struct, which used a disorienting mess of mpsc
channels to facilitate message passing between the `ShardManager` and
each of its `ShardRunner`s.
The new `ShardManager::run` function takes care of creating/spawning new
runners as needed. This is fine to call without spawning a separate task
(which was being done for `ShardQueuer`) because
`Client::start_connection` previously already waited for the
`ShardQueuer` loop to (essentially) finish before returning. In other
words, the Client would start the `ShardManager` and then block, but the
waiting was just being facilitated through channels, which wasn't
obvious.
The only messages passed across channels now are `ShardRunnerMessage`
(sent from the manager to a given runner), and a new
`ShardManagerMessage` (sent from a runner back to the manager). For
example, the manager can send a message to a runner telling it to
restart, then the runner will shut itself down and ask the manager to
reboot the shard by sending it a message back.
The shard queue now keeps track of if it should dispatch in concurrent
batches or not. Since we only use concurrent startup when first
initializing all shards, and then switch it off once and don't re-enable
it, this should be fine.
1 parent 6d87747 commit ec33fbb
File tree
9 files changed
+434
-817
lines changed- examples/e07_shard_manager/src
- src/gateway
- client
- sharding
9 files changed
+434
-817
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
72 | | - | |
73 | 71 | | |
| 72 | + | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | 38 | | |
40 | | - | |
41 | 39 | | |
42 | 40 | | |
43 | 41 | | |
44 | 42 | | |
45 | 43 | | |
46 | 44 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | 45 | | |
55 | | - | |
56 | | - | |
| 46 | + | |
| 47 | + | |
57 | 48 | | |
58 | | - | |
59 | 49 | | |
60 | 50 | | |
61 | 51 | | |
| 52 | + | |
62 | 53 | | |
63 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
64 | 61 | | |
65 | 62 | | |
66 | 63 | | |
| |||
316 | 313 | | |
317 | 314 | | |
318 | 315 | | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | 316 | | |
323 | 317 | | |
324 | 318 | | |
| |||
337 | 331 | | |
338 | 332 | | |
339 | 333 | | |
340 | | - | |
| 334 | + | |
| 335 | + | |
341 | 336 | | |
342 | 337 | | |
343 | 338 | | |
344 | 339 | | |
345 | 340 | | |
346 | 341 | | |
347 | 342 | | |
348 | | - | |
| 343 | + | |
349 | 344 | | |
| 345 | + | |
350 | 346 | | |
| 347 | + | |
351 | 348 | | |
352 | 349 | | |
353 | 350 | | |
354 | 351 | | |
355 | 352 | | |
356 | | - | |
357 | 353 | | |
358 | | - | |
359 | 354 | | |
360 | 355 | | |
361 | 356 | | |
362 | 357 | | |
363 | 358 | | |
364 | | - | |
365 | 359 | | |
366 | | - | |
| 360 | + | |
367 | 361 | | |
368 | 362 | | |
369 | 363 | | |
| |||
449 | 443 | | |
450 | 444 | | |
451 | 445 | | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | 446 | | |
456 | 447 | | |
457 | | - | |
| 448 | + | |
458 | 449 | | |
459 | 450 | | |
460 | 451 | | |
461 | 452 | | |
462 | 453 | | |
463 | 454 | | |
464 | 455 | | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
| 456 | + | |
489 | 457 | | |
490 | 458 | | |
491 | 459 | | |
| |||
796 | 764 | | |
797 | 765 | | |
798 | 766 | | |
799 | | - | |
800 | | - | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
| 767 | + | |
805 | 768 | | |
806 | 769 | | |
807 | 770 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
29 | 22 | | |
30 | 23 | | |
31 | 24 | | |
| |||
37 | 30 | | |
38 | 31 | | |
39 | 32 | | |
40 | | - | |
| 33 | + | |
41 | 34 | | |
42 | 35 | | |
43 | 36 | | |
| |||
56 | 49 | | |
57 | 50 | | |
58 | 51 | | |
| 52 | + | |
59 | 53 | | |
60 | 54 | | |
61 | 55 | | |
62 | 56 | | |
63 | | - | |
| 57 | + | |
64 | 58 | | |
65 | 59 | | |
66 | 60 | | |
| |||
779 | 773 | | |
780 | 774 | | |
781 | 775 | | |
782 | | - | |
783 | | - | |
784 | | - | |
785 | 776 | | |
786 | 777 | | |
787 | 778 | | |
| |||
0 commit comments