Debian Codegraph @

docpages/advanced_reference/thread_model.md

raw symbols SCIP
1 \page thread-model Thread Model
2
3 \dot
4 digraph "Thread Model" {
5 graph [ranksep=1];
6 node [colorscheme="blues9",fontname="helvetica"];
7 "Your Program" [style=filled, color=1, shape=rect]
8 "Cluster" [style=filled, color=1, shape=rect]
9
10 subgraph cluster_4 {
11 style=filled;
12 color=lightgrey;
13 node [style=filled,color=2]
14 "Your Program"
15 "Your Program" -> "Cluster"
16 label = "(1)";
17 }
18
19 subgraph cluster_3 {
20 style=filled;
21 color=lightgrey;
22 node [style=filled,color=2]
23 "Cluster" -> "Event Loop"
24 "Event Loop" -> "HTTP(S) requests"
25 "Event Loop" -> "Voice Sessions"
26 "Event Loop" -> "Shards"
27 "Shards" -> "Websocket Events"
28 label = "(2)";
29 }
30
31
32 subgraph cluster_0 {
33 style=filled;
34 color=lightgrey;
35 node [style=filled,color=4]
36 "Voice Sessions" -> "Websocket Events"
37 "HTTP(S) requests" -> "Thread Pool (4..n threads)"
38 "Websocket Events" -> "Thread Pool (4..n threads)"
39 "Thread Pool (4..n threads)"
40 label = "(3)";
41 }
42
43 "Cluster" [shape=rect]
44 "Thread Pool (4..n threads)" [shape=rect]
45 "HTTP(S) requests" [shape=rect]
46 "Shards" [shape=rect]
47 "Websocket Events" [shape=rect]
48 "Event Loop" [shape=rect]
49 "Voice Sessions" [shape=rect]
50
51 }
52 \enddot
53
54 ## Details
55
56 1. User Code - No assumptions are made about how your program threads, if at all.
57 2. The event loop manages all socket IO for the cluster. If you start the cluster with dpp::st_return this will run under its own thread, otherwise if you use dpp::st_wait it will run in the same thread as the caller of the dpp::cluster::start method.
58 The event loop will be either poll, epoll or kqueue based depending on your system capabilities. You should always start a cluster after forking, if your program forks, as various types of IO loop cannot be inherited by a forked process.
59 3. Set thread pool size via cluster constructor. Thread pool uses a priority queue and defaults in size to half the system concurrency value. Every callback or completed coroutine ends up executing here. The minimum concurrency of this pool is 4.