Révision | ef900cf664bc3954d54541e0a8204444ca1ae7a2 (tree) |
---|---|
l'heure | 2022-09-20 05:02:08 |
Auteur | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
More (last part) of Messaging Aspects; now focus on calculus & actors
@@ -15,10 +15,10 @@ | ||
15 | 15 | speed up [useCase: :need:`U_ManyCore`]. I also showed that threads_ do not scale well for CPU-bound (embedded) |
16 | 16 | systems. Last, I introduced some (more) concurrency abstractions. Some are great, but they often do not fit |
17 | 17 | nicely in existing languages. |
18 | - | |
18 | + |BR| | |
19 | 19 | Still, as Castle is a new language, we have the opportunity to select such a concept and incorporate it into the |
20 | 20 | language. |
21 | - |BR| | |
21 | + | |
22 | 22 | In this blog, we explore a bit of theory. I will focus on semantics and the possibilities to implement them |
23 | 23 | efficiently. The exact syntax will come later. |
24 | 24 |
@@ -202,21 +202,42 @@ | ||
202 | 202 | --------------- |
203 | 203 | |
204 | 204 | Both the writer and the reader can be *blocking* (or not); which is a facet of the function-call. A blocking reader it |
205 | -will always return when a message is available -- and will pauze until then. | |
206 | -|BR| | |
207 | -Also, the write-call can be blocked: it will pauze until the message can be sent -- e.g. the reader is available | |
208 | -(rendezvous) or a message buffer is free. | |
205 | +will always return when a message is available -- and will pauze until then. Equally, the write-call can block: pauze | |
206 | +until the message can be sent -- e.g. the reader is available (rendezvous) or a message buffer is free. | |
209 | 207 | |
210 | 208 | When the call is non-blocking, the call will return without waiting and yield a flag whether it was successful or not. |
211 | 209 | Then, the developer will commonly “cycle” to poll for a profitable call; and let the task do some other/background work |
212 | 210 | as well. |
213 | 211 | |
212 | +Futures (or promises) | |
213 | +~~~~~~~~~~~~~~~~~~~~~ | |
214 | 214 | |
215 | -Uni/Bi-Directional, Broadcast | |
216 | ------------------------------ | |
215 | +A modern variant of non-blocking makes uses of “Futures_”. The call will always return this opaque data-structure | |
216 | +immediately. It may be a blank -- but the procedure can continue. Eventually, that data will be filled in “by the | |
217 | +background”. It also contains a flag (like ``done``), so the programmer can check (using an if) [#future-CS]_ whether | |
218 | +the data is processes. | |
217 | 219 | |
218 | -Messages --or the channel [#channelDir]_ that transports them-- can be *unidirectional*: from sender to receiver only; | |
219 | -*bidirectional*: both sides can send and receive; or *broadcasted*: one message is sent to many receivers [#anycast]_. | |
220 | + | |
221 | +Uni/Bi-Directional, Many/Broad-cast | |
222 | +----------------------------------- | |
223 | + | |
224 | +Message can be sent to one receiver, to many, or even to everybody. Usually this is modeled as an characteristic of the | |
225 | +channel. And at the same time, that channel can be used to send message in oneway, or in two-ways. | |
226 | + | |
227 | +It depends on the context on the exact intent. By example in (TCP/IP) networking, `Broadcasting | |
228 | +<https://en.wikipedia.org/wiki/Broadcasting_(networking)>`_ (and al variants that are not point-to-point) focus on | |
229 | +reducing the amount of data on the network itself. In distributed computing `Broadcasting | |
230 | +<https://en.wikipedia.org/wiki/Broadcast_(parallel_pattern)>`_ is a parallel Design pattern. Whereas the `Broadcast flag | |
231 | +<https://en.wikipedia.org/wiki/Broadcast_flag>`_ in TV steaming is a complete other idea: is it allowed to save | |
232 | +(record) a TV broadcast... | |
233 | + | |
234 | +We use those teams on the functional aim. We consider the above mentioned RCP connection as **Unidirectional** -- even | |
235 | +the channel can carry the answer. When both endpoints can take the initiative to sent messages, we call it | |
236 | +**Bidirectional**. | |
237 | +|BR| | |
238 | +With only 2 endpoints, we call the connection **Point-to-Point** (*p2p*). When more endpoints are concerned, it’s | |
239 | +**Broadcast** when a message is send to all other (on that channel), and **Manycast** when the user (the programmer) can | |
240 | +(somehow) select a subset. | |
220 | 241 | |
221 | 242 | |
222 | 243 | Reliability & Order |
@@ -229,7 +250,7 @@ | ||
229 | 250 | “reliability layer”. |
230 | 251 | |BR| |
231 | 252 | Such a layer makes writing the application easier but introduces overhead too. And therefore not always the right |
232 | -solution. | |
253 | +solution. | |
233 | 254 | |
234 | 255 | In Castle, we have “active components”: many cores are running parallel, all doing a part of the overall (concurrent) |
235 | 256 | program. This resembles a networking application -- even while there is no real network -- where at least three nodes |
@@ -333,9 +354,10 @@ | ||
333 | 354 | that the number of communications will grow with the number of cores too. As described in the :ref:`sidebar |
334 | 355 | <Threads-in-CPython>` in :ref:`BusyCores`, solving this can give more overhead then the speed we are aiming for. |
335 | 356 | |
336 | -.. [#channelDir] | |
337 | - Strictly speaking, one should not use “channel” here. Non the less, the “direction of a medium”, that is not a | |
338 | - (connected) channel sounds void. Although we do not exclude it, we use a pragmatic way of writing. | |
357 | +.. [#future-CS] | |
358 | + Remember: to be able to “fill in” that Future-object “by the background” some other thread or so is needed. And so, a | |
359 | + Critical-Section_ is needed. For the SW-developer the interface is simple: read a flag (e.g. ``.done()``. But using | |
360 | + that to often can result is in a slow system. | |
339 | 361 | |
340 | 362 | .. [#anycast] |
341 | 363 | Broadcasting_ is primarily know from “network messages”; where is has many variants -- mostly related to the |
@@ -362,3 +384,4 @@ | ||
362 | 384 | .. _Broadcasting: https://en.wikipedia.org/wiki/Broadcasting_(networking) |
363 | 385 | .. _Reliability: https://en.wikipedia.org/wiki/Reliability_(computer_networking) |
364 | 386 | .. _Process-Calculus: https://en.wikipedia.org/wiki/Process_calculus |
387 | +.. _Futures: https://en.wikipedia.org/wiki/Futures_and_promises |