Part III and Part IV chapters as written during the course
The two chapter files are not yet in the profiles' chapter lists, so the built book does not show them yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f7fa60ba81
commit
54338b3ea2
2 files changed
+385
No files matched your search
@@ -0,0 +1,224 @@
|
||||
# [Part III — Make it actually distributed]{.en}[Partie III — Le rendre réellement distribué]{.fr}[Teil III — Es wirklich verteilen]{.de} {#sec-part-iii}
|
||||
|
||||
<!-- MULTILINGUAL: see the comment at the top of index.qmd.
|
||||
A figure for the two-machine replication is still to be drawn; the
|
||||
measurements below carry the argument in the meantime. -->
|
||||
|
||||
::: {.en}
|
||||
Five processes on one computer still share one filesystem. Steps 19 to 27 put them on two machines, replicate the message board between them with Syncthing, measure what that costs, and then break a mediator on purpose. By the end, the mediators' price is a number rather than an opinion.
|
||||
:::
|
||||
|
||||
::: {.fr}
|
||||
Cinq processus sur un seul ordinateur partagent encore un même système de fichiers. Les étapes 19 à 27 les répartissent sur deux machines, répliquent le tableau de messages entre elles avec Syncthing, mesurent ce que cela coûte, puis cassent délibérément un médiateur. À la fin, le prix des médiateurs est un chiffre, non une opinion.
|
||||
:::
|
||||
|
||||
::: {.de}
|
||||
Fünf Prozesse auf einem Rechner teilen immer noch ein Dateisystem. Die Schritte 19 bis 27 verteilen sie auf zwei Maschinen, replizieren das Nachrichtenbrett mit Syncthing zwischen ihnen, messen die Kosten und zerbrechen dann absichtlich einen Vermittler. Am Ende ist der Preis der Vermittler eine Zahl und keine Meinung.
|
||||
:::
|
||||
|
||||
## [Syncthing replicates; it does not deliver]{.en}[Syncthing réplique ; il ne distribue pas]{.fr}[Syncthing repliziert; es liefert nicht aus]{.de} {#sec-syncthing-not-a-broker}
|
||||
|
||||
::: {.en}
|
||||
Syncthing keeps a directory replicated between machines. That is all it is asked to do here. It knows nothing about Intent, Status, Event, ROT13 or mediators, and it has no concept of a consumer: no subscriptions, no topics, no delivery guarantees, no notion that anybody is waiting.
|
||||
|
||||
The trigger is still ours. Each service runs its own `WatchService` on a **local** directory; Syncthing only makes files appear there. That is why none of the three services changed a single line when the system became distributed.
|
||||
|
||||
Two consequences follow, and both show up later as observations rather than warnings:
|
||||
|
||||
- replication is **asynchronous** — the `.tmp → .msg` rename is atomic on each machine separately, and nothing promises ordering or atomicity between machines;
|
||||
- the filesystem is a serious transport with its own strengths: files can be large, replicas survive a reboot, and every message is readable with `cat`.
|
||||
:::
|
||||
|
||||
::: {.fr}
|
||||
Syncthing maintient un répertoire répliqué entre plusieurs machines. C'est tout ce qu'on lui demande ici. Il ne sait rien d'Intent, de Status, d'Event, de ROT13 ni des médiateurs, et il n'a aucune notion de consommateur : pas d'abonnement, pas de sujet, aucune garantie de livraison, aucune idée que quelqu'un attend.
|
||||
|
||||
Le déclencheur reste le nôtre. Chaque service exécute son propre `WatchService` sur un répertoire **local** ; Syncthing fait seulement apparaître les fichiers à cet endroit. C'est pourquoi aucun des trois services n'a changé d'une ligne lorsque le système est devenu distribué.
|
||||
|
||||
Deux conséquences en découlent, et toutes deux apparaîtront comme des observations plutôt que comme des avertissements :
|
||||
|
||||
- la réplication est **asynchrone** — le renommage `.tmp → .msg` est atomique sur chaque machine séparément, et rien ne promet d'ordre ni d'atomicité entre machines ;
|
||||
- le système de fichiers est un transport sérieux, avec ses forces : les fichiers peuvent être gros, les répliques survivent à un redémarrage, et chaque message se lit avec `cat`.
|
||||
:::
|
||||
|
||||
::: {.de}
|
||||
Syncthing hält ein Verzeichnis zwischen Maschinen repliziert. Mehr wird hier nicht verlangt. Es weiss nichts von Intent, Status, Event, ROT13 oder Vermittlern, und es kennt keinen Konsumenten: keine Abonnements, keine Topics, keine Lieferzusagen, keine Vorstellung davon, dass jemand wartet.
|
||||
|
||||
Der Auslöser bleibt unser eigener. Jeder Dienst betreibt seinen eigenen `WatchService` auf einem **lokalen** Verzeichnis; Syncthing lässt die Dateien dort nur erscheinen. Deshalb musste keiner der drei Dienste eine Zeile ändern, als das System verteilt wurde.
|
||||
|
||||
Daraus folgen zwei Dinge, die später als Beobachtung und nicht als Warnung auftreten:
|
||||
|
||||
- Replikation ist **asynchron** — das Umbenennen `.tmp → .msg` ist auf jeder Maschine einzeln atomar, und nichts verspricht Reihenfolge oder Atomarität zwischen Maschinen;
|
||||
- das Dateisystem ist ein ernstzunehmender Transport mit eigenen Stärken: Dateien dürfen gross sein, Replikate überleben einen Neustart, und jede Nachricht lässt sich mit `cat` lesen.
|
||||
:::
|
||||
|
||||
## [Test one layer at a time]{.en}[Tester une couche à la fois]{.fr}[Eine Schicht auf einmal prüfen]{.de} {#sec-one-layer}
|
||||
|
||||
::: {.en}
|
||||
Before any Java touched the replicated folder, the dullest possible test ran first: write `hello.txt` on one machine, confirm it appears on the other, delete it, confirm the deletion travels back. Both directions worked.
|
||||
|
||||
That order matters. When the distributed run later failed, the question "is it replication or is it my program?" had already been answered for the transport, and the search could start one layer up.
|
||||
:::
|
||||
|
||||
::: {.fr}
|
||||
Avant que le moindre programme Java ne touche au dossier répliqué, le test le plus ennuyeux possible a été fait d'abord : écrire `hello.txt` sur une machine, vérifier qu'il apparaît sur l'autre, le supprimer, vérifier que la suppression revient. Les deux sens fonctionnent.
|
||||
|
||||
Cet ordre compte. Quand l'exécution distribuée a échoué plus tard, la question « est-ce la réplication ou mon programme ? » était déjà tranchée pour le transport, et la recherche pouvait commencer une couche plus haut.
|
||||
:::
|
||||
|
||||
::: {.de}
|
||||
Bevor irgendein Java-Programm den replizierten Ordner berührte, lief der langweiligste denkbare Test: `hello.txt` auf einer Maschine schreiben, prüfen, dass es auf der anderen erscheint, es löschen, prüfen, dass die Löschung zurückkommt. Beide Richtungen funktionierten.
|
||||
|
||||
Diese Reihenfolge ist wichtig. Als der verteilte Lauf später scheiterte, war die Frage „Replikation oder mein Programm?" für den Transport schon beantwortet, und die Suche konnte eine Schicht höher beginnen.
|
||||
:::
|
||||
|
||||
## [What one keystroke costs]{.en}[Ce que coûte une frappe]{.fr}[Was ein Tastendruck kostet]{.de} {#sec-keystroke-cost}
|
||||
|
||||
::: {.en}
|
||||
With the sensor on one machine and the mediators, ROT13 and the actuator on the other, one typed line produced **four** `.msg` files, one per mailbox:
|
||||
|
||||
| mailbox | content | timestamp inside |
|
||||
|---|---|---|
|
||||
| `consoleIn/outbox` | `Hello World` | 23:02:05.315 |
|
||||
| `rot13/inbox` | `Hello World` | 23:02:05.315 |
|
||||
| `rot13/outbox` | `Uryyb Jbeyq` | 23:02:13.471 |
|
||||
| `consoleOut/inbox` | `Uryyb Jbeyq` | 23:02:13.471 |
|
||||
|
||||
The repeated timestamps are the evidence that two of those four publications are **pure copies**: the mediators republish the message unchanged, timestamp included. They compute `identity(x) = x`, as separate distributed processes.
|
||||
|
||||
The timing, taken from the four files' modification times on one machine so that no clock skew enters: the sensor's file appears at `01:02:05.432`, the other three at `01:02:13.460`, `.504` and `.532` — **8.10 s** later, and within **72 ms of each other**. So the chain's own work took milliseconds; the eight seconds are Syncthing's propagation. The same chain, run entirely on one machine, completes in about 24 ms.
|
||||
:::
|
||||
|
||||
::: {.fr}
|
||||
Avec le capteur sur une machine et les médiateurs, ROT13 et l'actionneur sur l'autre, une ligne tapée a produit **quatre** fichiers `.msg`, un par boîte :
|
||||
|
||||
| boîte | contenu | horodatage interne |
|
||||
|---|---|---|
|
||||
| `consoleIn/outbox` | `Hello World` | 23:02:05.315 |
|
||||
| `rot13/inbox` | `Hello World` | 23:02:05.315 |
|
||||
| `rot13/outbox` | `Uryyb Jbeyq` | 23:02:13.471 |
|
||||
| `consoleOut/inbox` | `Uryyb Jbeyq` | 23:02:13.471 |
|
||||
|
||||
Les horodatages répétés prouvent que deux de ces quatre publications sont de **pures copies** : les médiateurs republient le message inchangé, horodatage compris. Ils calculent `identity(x) = x`, sous forme de processus distribués distincts.
|
||||
|
||||
Le temps, mesuré sur les dates de modification des quatre fichiers d'une seule machine pour qu'aucun décalage d'horloge n'intervienne : le fichier du capteur apparaît à `01:02:05.432`, les trois autres à `01:02:13.460`, `.504` et `.532` — **8,10 s** plus tard, et à **72 ms** l'un de l'autre. Le travail propre de la chaîne a donc pris des millisecondes ; les huit secondes sont la propagation de Syncthing. La même chaîne, exécutée entièrement sur une machine, termine en 24 ms environ.
|
||||
:::
|
||||
|
||||
::: {.de}
|
||||
Mit dem Sensor auf einer Maschine und den Vermittlern, ROT13 und dem Aktor auf der anderen erzeugte eine getippte Zeile **vier** `.msg`-Dateien, eine pro Postfach:
|
||||
|
||||
| Postfach | Inhalt | Zeitstempel darin |
|
||||
|---|---|---|
|
||||
| `consoleIn/outbox` | `Hello World` | 23:02:05.315 |
|
||||
| `rot13/inbox` | `Hello World` | 23:02:05.315 |
|
||||
| `rot13/outbox` | `Uryyb Jbeyq` | 23:02:13.471 |
|
||||
| `consoleOut/inbox` | `Uryyb Jbeyq` | 23:02:13.471 |
|
||||
|
||||
Die wiederholten Zeitstempel belegen, dass zwei dieser vier Veröffentlichungen **reine Kopien** sind: die Vermittler veröffentlichen die Nachricht unverändert erneut, Zeitstempel eingeschlossen. Sie berechnen `identity(x) = x`, als eigene verteilte Prozesse.
|
||||
|
||||
Die Zeiten, gemessen an den Änderungszeiten der vier Dateien auf einer Maschine, damit keine Uhrendifferenz hineinspielt: die Datei des Sensors erscheint um `01:02:05.432`, die drei anderen um `01:02:13.460`, `.504` und `.532` — **8,10 s** später und innerhalb von **72 ms** zueinander. Die eigentliche Arbeit der Kette dauerte also Millisekunden; die acht Sekunden sind Syncthings Verbreitung. Dieselbe Kette, vollständig auf einer Maschine, braucht etwa 24 ms.
|
||||
:::
|
||||
|
||||
## [Break a mediator]{.en}[Casser un médiateur]{.fr}[Einen Vermittler zerbrechen]{.de} {#sec-break-a-mediator}
|
||||
|
||||
::: {.en}
|
||||
Stop the first mediator and type two lines. ConsoleIn is alive, ROT13 is alive, ConsoleOut is alive, Syncthing is alive — and the business flow is dead. The two lines pile up in `consoleIn/outbox`; nothing moves past it. The mediators are part of the availability chain.
|
||||
|
||||
Then restart the mediator. **Nothing is delivered.** `FileMessageBoard.watch` registers a directory for `ENTRY_CREATE` and blocks in `watcher.take()`; it never lists what is already there. The two files are still on disk, in both replicas — so no data was lost. What has no memory is the *subscription*.
|
||||
|
||||
That distinction is worth keeping: **the messages survived, the delivery did not.** A broker answers this with session state and retained messages; in our own code it would be one line — list the existing `.msg` files before entering the watch loop — which the material deliberately does not write yet.
|
||||
:::
|
||||
|
||||
::: {.fr}
|
||||
Arrêtez le premier médiateur et tapez deux lignes. ConsoleIn est vivant, ROT13 est vivant, ConsoleOut est vivant, Syncthing est vivant — et le flux métier est mort. Les deux lignes s'accumulent dans `consoleIn/outbox` ; rien ne va plus loin. Les médiateurs font partie de la chaîne de disponibilité.
|
||||
|
||||
Redémarrez ensuite le médiateur. **Rien n'est livré.** `FileMessageBoard.watch` enregistre un répertoire pour `ENTRY_CREATE` et se bloque dans `watcher.take()` ; il ne liste jamais ce qui est déjà là. Les deux fichiers sont toujours sur le disque, dans les deux répliques : aucune donnée n'a été perdue. Ce qui n'a pas de mémoire, c'est l'*abonnement*.
|
||||
|
||||
La distinction mérite d'être retenue : **les messages ont survécu, la livraison non.** Un courtier répond à cela par l'état de session et les messages retenus ; dans notre propre code, ce serait une ligne — lister les fichiers `.msg` existants avant d'entrer dans la boucle d'observation — que le matériel se garde volontairement d'écrire pour l'instant.
|
||||
:::
|
||||
|
||||
::: {.de}
|
||||
Halten Sie den ersten Vermittler an und tippen Sie zwei Zeilen. ConsoleIn lebt, ROT13 lebt, ConsoleOut lebt, Syncthing lebt — und der Geschäftsfluss ist tot. Die zwei Zeilen stapeln sich in `consoleIn/outbox`; weiter kommt nichts. Die Vermittler gehören zur Verfügbarkeitskette.
|
||||
|
||||
Starten Sie den Vermittler neu. **Nichts wird ausgeliefert.** `FileMessageBoard.watch` registriert ein Verzeichnis für `ENTRY_CREATE` und blockiert in `watcher.take()`; es listet nie, was schon da ist. Die zwei Dateien liegen weiter auf der Platte, in beiden Replikaten — es ging also nichts verloren. Kein Gedächtnis hat das *Abonnement*.
|
||||
|
||||
Diese Unterscheidung lohnt sich: **die Nachrichten überlebten, die Auslieferung nicht.** Ein Broker antwortet darauf mit Sitzungszustand und retained messages; im eigenen Code wäre es eine Zeile — die vorhandenen `.msg`-Dateien auflisten, bevor die Beobachtungsschleife beginnt — die das Material bewusst noch nicht schreibt.
|
||||
:::
|
||||
|
||||
## [The mediator becomes an ordinary service]{.en}[Le médiateur devient un service ordinaire]{.fr}[Der Vermittler wird ein gewöhnlicher Dienst]{.de} {#sec-configurable-mediator}
|
||||
|
||||
::: {.en}
|
||||
Before removing the mediators, one asymmetry gets removed: the services receive their *work* as messages, while the mediator received its *route* as shell arguments. So the mediator is given only a name, `ConfigurableMediator mediator1`, from which it derives one permanent control mailbox, `mediators/mediator1/inbox`, and the route arrives as a message:
|
||||
|
||||
```text
|
||||
ROUTE
|
||||
consoleIn/outbox
|
||||
rot13/inbox
|
||||
```
|
||||
|
||||
`from` and `to` travel in **one** message on purpose: as two, the mediator would briefly hold a new source with the old destination and forward to the wrong place. A route is one fact, and one fact belongs in one message.
|
||||
|
||||
A short-lived orchestrator publishes both routes and exits, so the topology is visible in one place and is **not** in the data path. Running it after the services, and typing a line before it, shows both halves at once: the early line is stranded, the later one flows.
|
||||
|
||||
What improved: the mediator now has an identity, takes configuration through its own inbox, keeps a generic capability, and gets its topology from an orchestrator. What did not improve: the data path. It is still `event → mediator → copied event`, still a process in the availability chain, still copying every message without adding meaning. And this version accepts exactly **one** route: `waitForRoute(...)` returns, then the mediator enters `watch(route.from(), …)` and never reads its control inbox again. Live rewiring is not promised, because one blocking `watch` cannot serve a control inbox and a source at the same time — the reason a subscription helper appears later.
|
||||
:::
|
||||
|
||||
::: {.fr}
|
||||
Avant de supprimer les médiateurs, une asymétrie disparaît : les services reçoivent leur *travail* sous forme de messages, alors que le médiateur recevait sa *route* en arguments de shell. On ne lui donne donc qu'un nom, `ConfigurableMediator mediator1`, dont il dérive une boîte de contrôle permanente, `mediators/mediator1/inbox`, et la route arrive comme message :
|
||||
|
||||
```text
|
||||
ROUTE
|
||||
consoleIn/outbox
|
||||
rot13/inbox
|
||||
```
|
||||
|
||||
`from` et `to` voyagent dans **un seul** message, volontairement : en deux, le médiateur combinerait brièvement une nouvelle source avec l'ancienne destination et transmettrait au mauvais endroit. Une route est un seul fait, et un fait tient dans un message.
|
||||
|
||||
Un orchestrateur éphémère publie les deux routes puis s'arrête : la topologie est visible en un seul endroit et n'est **pas** dans le chemin des données. Le lancer après les services, en ayant tapé une ligne avant, montre les deux moitiés d'un coup : la ligne précoce reste bloquée, la suivante circule.
|
||||
|
||||
Ce qui s'améliore : le médiateur a une identité, reçoit sa configuration par sa propre boîte, garde une capacité générique et tient sa topologie d'un orchestrateur. Ce qui ne s'améliore pas : le chemin des données. Il reste `event → médiateur → copie de l'event`, toujours un processus dans la chaîne de disponibilité, qui copie chaque message sans rien y ajouter. Et cette version accepte exactement **une** route : `waitForRoute(...)` retourne, puis le médiateur entre dans `watch(route.from(), …)` et ne lit plus jamais sa boîte de contrôle. Le recâblage à chaud n'est pas promis, car un `watch` bloquant ne peut pas servir à la fois une boîte de contrôle et une source — d'où l'aide à l'abonnement qui apparaît plus tard.
|
||||
:::
|
||||
|
||||
::: {.de}
|
||||
Bevor die Vermittler verschwinden, fällt eine Asymmetrie weg: die Dienste erhalten ihre *Arbeit* als Nachrichten, der Vermittler erhielt seine *Route* als Shell-Argumente. Er bekommt daher nur einen Namen, `ConfigurableMediator mediator1`, aus dem er ein dauerhaftes Steuerpostfach ableitet, `mediators/mediator1/inbox`, und die Route kommt als Nachricht:
|
||||
|
||||
```text
|
||||
ROUTE
|
||||
consoleIn/outbox
|
||||
rot13/inbox
|
||||
```
|
||||
|
||||
`from` und `to` reisen absichtlich in **einer** Nachricht: als zwei hielte der Vermittler kurz eine neue Quelle mit dem alten Ziel und leitete an die falsche Stelle weiter. Eine Route ist ein Fakt, und ein Fakt gehört in eine Nachricht.
|
||||
|
||||
Ein kurzlebiger Orchestrator veröffentlicht beide Routen und endet, damit die Topologie an einer Stelle sichtbar ist und **nicht** im Datenpfad liegt. Startet man ihn nach den Diensten und hat vorher eine Zeile getippt, zeigen sich beide Hälften auf einmal: die frühe Zeile bleibt liegen, die späte läuft durch.
|
||||
|
||||
Was besser wird: der Vermittler hat eine Identität, nimmt Konfiguration über sein eigenes Postfach, behält eine generische Fähigkeit und bezieht seine Topologie von einem Orchestrator. Was nicht besser wird: der Datenpfad. Er bleibt `event → Vermittler → kopiertes event`, weiter ein Prozess in der Verfügbarkeitskette, der jede Nachricht ohne Bedeutungsgewinn kopiert. Und diese Fassung nimmt genau **eine** Route an: `waitForRoute(...)` kehrt zurück, dann betritt der Vermittler `watch(route.from(), …)` und liest sein Steuerpostfach nie wieder. Umverdrahten im Betrieb wird nicht versprochen, weil ein blockierendes `watch` nicht gleichzeitig ein Steuerpostfach und eine Quelle bedienen kann — der Grund für die Abonnement-Hilfe später.
|
||||
:::
|
||||
|
||||
## [What part III moved]{.en}[Ce que la partie III a déplacé]{.fr}[Was Teil III verschoben hat]{.de} {#sec-part-iii-result}
|
||||
|
||||
::: {.en}
|
||||
| stage | where the topology lives | in the data path? |
|
||||
|---|---|---|
|
||||
| step 18 | the operator's command lines | the mediators are |
|
||||
| step 27 | an orchestrator, published as Intent | the mediators still are |
|
||||
|
||||
The question the part ends on is therefore sharp rather than rhetorical: **why can't the service interested in the data simply listen to it itself?**
|
||||
:::
|
||||
|
||||
::: {.fr}
|
||||
| étape | où vit la topologie | dans le chemin des données ? |
|
||||
|---|---|---|
|
||||
| étape 18 | les lignes de commande de l'opérateur | les médiateurs y sont |
|
||||
| étape 27 | un orchestrateur, publiée comme Intent | les médiateurs y sont encore |
|
||||
|
||||
La question sur laquelle se referme la partie est donc précise et non rhétorique : **pourquoi le service intéressé par la donnée ne pourrait-il pas l'écouter lui-même ?**
|
||||
:::
|
||||
|
||||
::: {.de}
|
||||
| Stufe | wo die Topologie liegt | im Datenpfad? |
|
||||
|---|---|---|
|
||||
| Schritt 18 | die Befehlszeilen des Bedieners | die Vermittler sind es |
|
||||
| Schritt 27 | ein Orchestrator, als Intent veröffentlicht | die Vermittler sind es weiterhin |
|
||||
|
||||
Die Frage, mit der der Teil schliesst, ist daher scharf und nicht rhetorisch: **warum kann der Dienst, der sich für die Daten interessiert, sie nicht selbst hören?**
|
||||
:::
|
||||
Reference in new issue
Block a user