Last change
on this file since 538 was 266, checked in by contact, 5 years ago |
doc/architecture: ring buffers are now per-channel
|
File size:
1.4 KB
|
Line | |
---|
1 | # soju architecture
|
---|
2 |
|
---|
3 | soju manages two types of connections:
|
---|
4 |
|
---|
5 | - Upstream connections: soju maintains persistent connections to
|
---|
6 | user-configured IRC servers
|
---|
7 | - Downstream connections: soju accepts connections from IRC clients
|
---|
8 |
|
---|
9 | On startup, soju will iterate over the list of networks stored in the database
|
---|
10 | and try to open an upstream connection for each network.
|
---|
11 |
|
---|
12 | ## Ring buffer
|
---|
13 |
|
---|
14 | In order to correctly send history to each downstream client, soju maintains
|
---|
15 | for each upstream channel a single-producer multiple-consumer ring buffer. The
|
---|
16 | network's upstream connection produces messages and multiple downstream
|
---|
17 | connections consume these messages. Each downstream client may have a different
|
---|
18 | cursor in the history: for instance a client may be 10 messages late while
|
---|
19 | another has consumed all pending messages.
|
---|
20 |
|
---|
21 | ## Goroutines
|
---|
22 |
|
---|
23 | Each type of connection has two dedicated goroutines: the first one reads
|
---|
24 | incoming messages, the second one writes outgoing messages.
|
---|
25 |
|
---|
26 | Each user has a dedicated goroutine responsible for dispatching all messages.
|
---|
27 | It communicates via channels with the per-connection reader and writer
|
---|
28 | goroutines. This allows to keep the dispatching logic simple (by avoiding any
|
---|
29 | race condition or inconsistent state) and to rate-limit each user.
|
---|
30 |
|
---|
31 | The user dispatcher goroutine receives from the `user.events` channel. Upstream
|
---|
32 | and downstream message handlers are called from this goroutine, thus they can
|
---|
33 | safely access both upstream and downstream state.
|
---|
Note:
See
TracBrowser
for help on using the repository browser.