Revision | 1d3db89e375b1c39ce8db2fcd8f4ce61795cce5f (tree) |
---|---|
Time | 2022-09-04 21:15:48 |
Author | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
asis
@@ -133,6 +133,7 @@ | ||
133 | 133 | |BR| |
134 | 134 | Notice: As the compiler will insert the (low level) Semaphores_, the risk that a developer forgets one is gone! |
135 | 135 | |
136 | + | |
136 | 137 | Messaging Aspects |
137 | 138 | ----------------- |
138 | 139 |
@@ -160,14 +161,35 @@ | ||
160 | 161 | (Un)Buffered |
161 | 162 | ~~~~~~~~~~~~ |
162 | 163 | |
163 | -Despide it’s is not truly a characteristic of the messages itself, messages can be *buffered*, or not. This about the | |
164 | -channel that transports the messages: How many messages can be stored ‘in’ the channel (often depicted a a queue). When | |
165 | -there is no storage at all, the writer and reader needs to rendezvous: send and receive at the same (wall) time. | |
164 | +Despide it’s is not truly a characteristic of the messages itself, messages can be *buffered*, or not. It is about | |
165 | +piping, transporting the message: can this “connection” (see below) *contain/save/store* messages? When there is no | |
166 | +storage at all the writer and reader needs to rendezvous: send and receive at the same (wall) time. | |
167 | +|BR| | |
168 | +With a buffer (often depicted as a queue) multiple messages may be sent, before they need to be picked-up by the | |
169 | +receiver; the number depends on the size of the buffer. | |
166 | 170 | |
167 | -This is not needed when a buffer is available. Depending on the size of the buffer, some messages can be send before | |
168 | -the are picked-up by the receiver. | |
171 | +Note: this is always asymmetric; messages need to be send before the can be read. | |
172 | + | |
173 | +Connected Channels (or not) | |
174 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
175 | + | |
176 | +Messages can be send over (pre-) *connected channels* or to freely addressable end-points. Some people use the term “connection | |
177 | +oriented” for those connected-channels, others use the term “channel” more generic and for any medium that is | |
178 | +transporting messages. I try to use “*connected-channel”* when is a *pre connected* channel. | |
179 | + | |
180 | +When using connected-channels, one writes the message to the channel; there is no need to add the receiver to the | |
181 | +message. Also when reading, the sender is clear. | |
169 | 182 | |BR| |
170 | -Note: this is always asymmetric; messages need to be send before the can be read. | |
183 | +Clearly, the channel has to be set-up before it can be used. | |
184 | + | |
185 | +Without connected-channels, each message needs a recipient; often that receiver is added (“carried”) to the message | |
186 | +itself. | |
187 | +|BR| | |
188 | +A big advantage is, that one does not need to create channels and end-points first -- which especially count when a low | |
189 | +number (possible one) of messages are send to the same receiver, and/or many receivers exist (which would lead to a huge | |
190 | +number of channels). | |
191 | + | |
192 | + | |
171 | 193 | |
172 | 194 | (Non-) Blocking |
173 | 195 | ~~~~~~~~~~~~~~~ |
@@ -182,22 +204,26 @@ | ||
182 | 204 | Then, the developer will commonly “cycle” to poll for a profitable call; and let the task do some other/background work |
183 | 205 | as well. |
184 | 206 | |
207 | + | |
208 | + | |
185 | 209 | Uni/Bi-Directional, Broadcast |
186 | 210 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
187 | 211 | |
188 | -Messages --or actually the channel that transport them-- can be *unidirectional*: from sender to receiver only; | |
212 | +Messages --or actually the channel [#channelDir]_ that transport them-- can be *unidirectional*: from sender to receiver only; | |
189 | 213 | *bidirectional*: both sides can send and receive; or *broadcasted*: one message is send to many receivers [#anycast]_. |
190 | 214 | |
215 | + | |
191 | 216 | Reliability & Order |
192 | 217 | ~~~~~~~~~~~~~~~~~~~ |
193 | 218 | |
194 | 219 | Especially when studying “network messages”, we have to consider Reliability_ too. Many developers assume that a send |
195 | -message is always received and that when multiple messages are sent, they are received in the same order. In most, | |
196 | -traditional --single-core-- applications this is always true. With networking applications, this is not always | |
197 | -the case. Messages can get lost, received out of order, or even read twice. Although it is always possible to add a | |
220 | +message is always received and that when multiple messages are sent, they are received in the same order. In most | |
221 | +traditional --single-core-- applications this is always the chase. With networking applications, this is not always | |
222 | +true. Messages can get lost, received out of order, or even read twice. Although it is always possible to add a | |
198 | 223 | “reliability layer”. |
199 | 224 | |BR| |
200 | -Such a layer makes writing the application easier but introduces overhead. And therefore not always the right solution. | |
225 | +Such a layer makes writing the application easier but introduces overhead too. And therefore not always the right | |
226 | +solution. | |
201 | 227 | |
202 | 228 | In Castle, we have “active components”: many cores are running parallel, all doing a part of the overall (concurrent) |
203 | 229 | program. This resembles a networking application -- even while there is no real network -- where at least three nodes |
@@ -211,9 +237,7 @@ | ||
211 | 237 | receiving a message from ``A`` -- send a short message to the other one (`m3` and `m4`). And that message triggers |
212 | 238 | (again both in ``B1`` and ``B2``) to send an answer to ``A``; so `m5` and `m6`. |
213 | 239 | |
214 | -Now the question is: in which order those answers (in ``A``) are received? | |
215 | -|BR| | |
216 | -The real answer is: you don’t know! | |
240 | +Now the question is: in which order those answers (in ``A``) are received? The real answer is: **You don’t know!** | |
217 | 241 | |BR| |
218 | 242 | It’s clear that ``A`` will get `m5` and `m6` -- given that all messages (aka channels) are reliable. But there are many |
219 | 243 | ways those messages may receive in the opposite order. Presumably, even in more ways, than you can imagine. For example, |
@@ -235,13 +259,16 @@ | ||
235 | 259 | connection, that is not 100% reliable. |
236 | 260 | |BR| |
237 | 261 | When we use it “as is”, there will be a bit of noise, and even some hick-ups. For most people this is acceptable, |
238 | - when needed they will use phrases as “can you repeat that?”. | |
262 | + when needed they will use phrases as *“Can you repeat that?”*. | |
239 | 263 | |
240 | - To make that connection reliable, we need checksums, low-level conformation message, and once in a while send a | |
241 | - message again. To make it an audio-stream all messages will be delayed a bit --so that an automatically resend | |
242 | - messages can be inserted. This is common in a (unidirectional) POD-cast kind of connection. | |
264 | + To make that connection reliable, we need checksums, low-level conformation message, and once in a while have to sent | |
265 | + a message again. This implies some buffering (at both sides), and so the audio-stream will have a bit of delay. | |
266 | + This is a common solution for unidirectional POD-casts, and such. | |
243 | 267 | |
244 | - For a (bidirectional) conversation, this buffering is often not satisfactory. As it makes the connection *slow*. | |
268 | + For a bidirectional conversation however this buffering is not satisfactory. It makes the *slow*, people have to wait | |
269 | + on each-other and will interrupted one-other. | |
270 | + |BR| | |
271 | + Then, a *faster* conversation with a bit of noise is commonly preferred.a | |
245 | 272 | |
246 | 273 | |
247 | 274 | Some examples |
@@ -324,6 +351,10 @@ | ||
324 | 351 | that the number of communications will grow with the number of cores too. As described in the :ref:`sidebar |
325 | 352 | <Threads-in-CPython>` in :ref:`BusyCores`, solving this can give more overhead then the speed we are aiming for. |
326 | 353 | |
354 | +.. [#channelDir] | |
355 | + Strictly speaking, one should not use “channel” here. Non the less, the “direction of a medium”, that is not a | |
356 | + (connected) channel sounds void. Although we do not exclude it, we use a pragmatic way of writing. | |
357 | + | |
327 | 358 | .. [#anycast] |
328 | 359 | Broadcasting_ is primarily know from “network messages”; where is has many variants -- mostly related to the |
329 | 360 | physical network abilities, and the need to save bandwith. As an abstraction, they can be used in “software messages” |