Chapter 18 · Course 1 c18-m01
Which time tells the event's story?
Your goal Rebuild factual order from event time, measure arrival delay, and check clock reliability.
The lesson, the vocabulary, the worked example and the mission are separate blocks. You can follow them in order or return to the one you need.
Video explanation
This English explanation has English subtitles. Its examples may use a separate practice dataset; use the data stated in the written mission for your answers.
Story · optional context
The story so far
You are Aster Motors' new data recruit. Luca was hurt when a car resembling Noctis 01 crashed; the prototype is missing and Voss accuses you. Mara Sol and Imani confirmed two distinct commands under the technical identity SUPPLIER-SVC without identifying its human user. A stream copy shows OPEN-18 received after the crash was reported. Voss calls it a response to the crash. Imani then finds the time recorded by the gate controller: if its clock is reliable, OPEN-18 was issued *before* the crash.
This lesson stands alone. A message can carry when a fact happened (event_at) and when the data system received it (received_at). Network delay or restart may change arrival order. You will read three UTC events, build both orders, and measure OPEN-18's delay. You will also learn to check the source clock: a time written in a message is a clue to verify, not automatic proof.
Before the lesson
Purpose of this course
Rebuild factual order from event time, measure arrival delay, and check clock reliability.
Topics covered
Distinguish event time, receipt time, and processing time.; Read Z as UTC and compare instants in the same time zone.; Sort three events by both timestamps and calculate a delay.; Name an independent check that supports the declared event time.
What you will learn
- Distinguish event time, receipt time, and processing time.
- Read Z as UTC and compare instants in the same time zone.
- Sort three events by both timestamps and calculate a delay.
- Name an independent check that supports the declared event time.
PART 1 · THE LESSON
Understand step by step
Lesson · explanation
A late arrival changes the question
You are Aster Motors' new data recruit. Luca was hurt in a crash involving a car resembling Noctis 01, the prototype is missing, and Voss blames you. Mara and Imani recognized two different commands, OPEN-17 and OPEN-18, under the technical label SUPPLIER-SVC. The stream copy shows OPEN-18 received after the crash signal. Voss says it must therefore have been sent in response to the crash.
Imani finds another time recorded by the gate controller. According to that record, OPEN-18 precedes the crash signal. Two timelines seem to disagree because they sort different moments: one follows message arrivals in the data system; the other follows the times at which sources say events occurred.
Imagine your friend posts a photo taken at 18:00, but your phone gets it only at 19:00, after another photo taken at 18:30. Notification order need not be photo-taking order. Likewise, a slow network or restarted system can delay a message without moving the event it describes.
Your goal is to build both timelines for three fictional messages, calculate E2/OPEN-18's delay, and state which clock needs checking. The scene is urgent, but the exercise has no timer. A timestamp may correct a hasty reading of the case; it does not prove its own reliability or identify the human who used SUPPLIER-SVC.
Pause and think
Why does receiving OPEN-18 after the crash signal not prove it was issued afterward?
See the explanation
The message may have traveled slowly or arrived after a restart; receipt and event time differ.
Lesson · explanation
Three clocks answer three questions
event_at is when the source says the event happened. For OPEN-18, it comes from the gate controller. received_at is when the data system received the message. A third time may exist: when software actually processed the message. These moments are not interchangeable, even if a very quick event sometimes brings them close together.
Imagine a letter. You write it on Monday, the mail delivers it Wednesday, and the recipient opens it Thursday. Monday resembles declared event time; Wednesday receipt time; Thursday processing time. Opening the letter Thursday does not mean you wrote it Thursday. That is the trap in Voss's timeline.
In our copy, E1/OPEN-17 says event time 21:05 and receipt 21:07. The CRASH signal says 21:25 and arrives at 21:26. E2/OPEN-18 says 21:18 but arrives at 21:36. No distinct processing time is supplied, so do not invent one. We can explain what it would mean if a reader recorded it later.
A mistake would be calling received_at=21:36 'the gate-opening time.' That field describes message arrival, not gate mechanics. Ignoring receipt is another mistake: its delay explains why the first chart misled the team. Keep both columns and their names in every note so Mara knows which question each timestamp answers.
Pause and think
Which field says when the data system received E2?
See the explanation
received_at, which is 21:36 UTC in this copy.
Lesson · explanation
Z gives a shared reference: UTC
All full timestamps in this lesson end with Z, such as 2026-04-12T21:18:00Z. This suffix means UTC, a shared reference for comparing moments without confusing local clock displays. Because our six times use the same reference, we can directly sort 21:05, 21:18, and 21:25 for the stated event order.
Picture two railway stations in different countries. Their wall clocks might show the same time even when trains pass at different moments. To compare trips, convert clock readings into one common reference. UTC serves that purpose here. A bare 21:18 without a known time zone should not be treated as identical to 21:18Z.
The Python code replaces Z with offset +00:00 and then calls datetime.fromisoformat. That makes the UTC offset explicit. It avoids comparing dates with missing zone information. It cannot repair a physical clock set incorrectly: the code reads the time format but cannot decide whether the source told the truth.
All example messages have the same fictional date, April 12, 2026, and UTC times. That makes minute subtraction straightforward. In a real case, check date and zone, particularly near midnight or a local clock change. Comparing bare clock numbers could reverse a timeline just as a network delay can.
Pause and think
What does the final Z in 21:18:00Z mean?
See the explanation
The time is written in UTC, the shared reference used here.
Lesson · explanation
Build the receipt timeline
For the first timeline, read only received_at. E1 arrives at 21:07 UTC, the CRASH signal at 21:26, and E2 at 21:36. Sorting earliest to latest gives E1, CRASH, E2. That is Voss's chart. It correctly reflects receipt order in this copy, but need not reflect the order of the reported events.
A receipt timeline answers 'what did the system see, and when?' It helps investigate network delay and reader state after a restart. For example, it shows E2 became visible ten minutes after the CRASH signal in the incoming stream. That ten-minute arrival gap says nothing about when the command was issued.
Picture three notes put in a mailbox at 21:07, 21:26, and 21:36. Their arrival order is easy to establish. If the third note was written before the second, the mailbox does not reveal that. Read the dates written on the notes and check that their writers used reliable clocks.
A bad conclusion would say, 'E2 is third in the box, so the command is third in history.' It jumps from receipt to creation. Instead say 'E2 is third by receipt.' That wording leaves room for a second timeline and avoids building an assumption into the report's heading.
Pause and think
What is the order by received_at?
See the explanation
E1 at 21:07, CRASH at 21:26, then E2 at 21:36.
Lesson · explanation
Build the stated event-time timeline
For the second timeline, read only event_at. E1 reports 21:05 UTC, E2 reports 21:18, and the CRASH signal reports 21:25. The stated order is E1, E2, CRASH. OPEN-18 sits seven minutes before the crash signal's reported time. This differs from the first chart, but the word 'reported' remains necessary.
A program can sort these three objects by event_at and return that list. Sorting does not verify the clocks. It is like arranging cards by dates their writers added: the order written on paper is clear, but a wrongly dated card would mislead. Keep the source of each time and planned checks beside the result.
Voss calls OPEN-18 a reaction to the crash signal because it arrived later. If the controller and CRASH clocks are reliable and comparable, 21:18 contradicts that reading: it precedes 21:25. It does not explain why the command exists. An earlier command may or may not relate to the crash; more evidence is needed.
Nor does stated order accuse Voss. SUPPLIER-SVC is a technical identity, not a confirmed human name. Messages do not reveal who held the key or controlled the program. The timeline changes the investigative question: how could a command precede the crash signal? It does not yet answer 'who?'
Pause and think
What is the event_at order, and where is E2 relative to CRASH?
See the explanation
E1, E2, CRASH; E2's reported time is seven minutes before CRASH's reported time.
Lesson · explanation
Calculate delay without moving the event
E2's arrival delay is receipt time minus reported event time: 21:36 − 21:18 = 18 minutes. This measures the gap between two timestamps in the copy. It does not prove that the network alone took eighteen minutes. Waiting inside a program or restarting it could also contribute.
The gap to the crash signal answers a different question: 21:25 − 21:18 = 7 minutes. Do not mix 18 and 7. Eighteen measures the interval from E2's stated event to its receipt; seven compares two stated event times. Both calculations use 21:18, but pair it with a different second time.
Imagine writing a letter at 21:18, hearing news at 21:25, and seeing the letter delivered at 21:36. Delivery took eighteen minutes and writing preceded the news by seven. Delivery after the news does not automatically shift the writing time. The analogy works only if the time written on the letter is correct.
The code calculates delay = received_at - event_at, then divides seconds by sixty to display eighteen minutes. A negative or enormous value would invite a clock or data check, not silent correction. All data here are fictional. The arithmetic mainly creates a checkable question for Imani.
Pause and think
Why do eighteen minutes and seven minutes answer different questions?
See the explanation
Eighteen is E2's reported-event-to-receipt delay; seven is the stated gap between E2 and CRASH.
Lesson · explanation
A reliable clock needs evidence
E2's event_at comes from the gate controller. If its clock were ten minutes fast, a command actually issued at 21:08 might be stamped 21:18. If slow, the error would go the other way. The Z format gives a time-zone reference; it does not guarantee the device displayed the right minute. Stated order is therefore a conditional lead.
Imani seeks independent checks: controller synchronization status, logs from another device, preserved receipt records, and comparison with events whose times are known. A synchronized clock has been checked against a trusted time source. 'It looks right' is not enough. Explain which evidence supports confidence and for which period.
Preserve raw messages, received_at metadata, and the UTC conversion method. Otherwise another investigator cannot rebuild the timelines. Check the clock behind CRASH too, because comparing two sources assumes they agree on time. Independent records can strengthen the lead, but the chronology depends on the quality of its clocks.
A poor report says, 'E2 has 21:18, so Voss planned the crash.' The message does not name Voss and the clock has not been verified. A good report states what is written, how the orders differ, and what Imani must check. Being clear about limits makes a lead more defensible, not less interesting.
Pause and think
Does Z prove the gate controller clock was set correctly?
See the explanation
No. It specifies UTC, but synchronization and independent logs still need checking.
Lesson · explanation
Give Mara a checkable timeline
For the mission, list both orders with times. Receipt: E1 21:07, CRASH 21:26, E2 21:36. Stated event time: E1 21:05, E2 21:18, CRASH 21:25. State that every value is in UTC because of Z. Someone opening only this lesson can redo both sorts on paper.
Add the calculations: E2 arrives eighteen minutes after its reported event time, and that time is seven minutes before the CRASH signal's reported time. Do not replace 'crash signal' with 'crash directly observed' when the source is a message. Precise wording keeps the chart from seeming more certain than the data behind it.
Then write a conditional sentence: 'If the controller and signal clocks are reliable, E2 precedes the signal by seven minutes despite late receipt.' Request synchronization and independent-log checks. This limit matters: the Python sort cannot validate a real clock, and SUPPLIER-SVC still does not identify a person.
Next lessons cover calculation windows and watermarks for messages that arrive beyond a chosen delay. For now, do not hide E2 because a receipt-based chart was already shown. The strongest reply to Voss corrects the sorting method, preserves originals, and leaves open questions that timestamps alone cannot settle.
Pause and think
What short sentence accurately places E2?
See the explanation
E2 was received after CRASH but reports an event time seven minutes earlier, subject to clock verification.
Visual guide
Two different orders
- 1Receipt: E1 21:07 → CRASH 21:26 → E2 21:36
- 2Event: E1 21:05 → E2 21:18 → CRASH 21:25
- 3E2: 18 minutes between stated event and receipt
Sorting timestamps does not replace checking the clock that produced them.
Code · read each line
Sort by receipt and event time
from datetime import datetime
events = [
{"id": "E1", "kind": "OPEN-17",
"event_at": "2026-04-12T21:05:00Z", "received_at": "2026-04-12T21:07:00Z"},
{"id": "CRASH", "kind": "accident",
"event_at": "2026-04-12T21:25:00Z", "received_at": "2026-04-12T21:26:00Z"},
{"id": "E2", "kind": "OPEN-18",
"event_at": "2026-04-12T21:18:00Z", "received_at": "2026-04-12T21:36:00Z"},
]
def instant(value):
return datetime.fromisoformat(value.replace("Z", "+00:00"))
by_arrival = sorted(events, key=lambda e: instant(e["received_at"]))
by_event = sorted(events, key=lambda e: instant(e["event_at"]))
e2 = next(e for e in events if e["id"] == "E2")
delay = instant(e2["received_at"]) - instant(e2["event_at"])
print("arrival_order", [e["id"] for e in by_arrival])
print("event_order", [e["id"] for e in by_event])
print("E2_delay_minutes", int(delay.total_seconds() / 60))The local program prints arrival order E1, CRASH, E2; stated event order E1, E2, CRASH; and E2's 18-minute delay. Converting Z keeps all instants in UTC.
PART 2 · WATCH IT WORK
A complete worked example
Follow each step, then the result
Worked example: OPEN-18
E2 says 21:18Z and arrives at 21:36Z; the crash signal says 21:25Z.
- Find E2's delay: 21:36 − 21:18 = 18 minutes.
- Compare arrivals: 21:36 follows the crash signal received at 21:26.
- Compare event times: 21:18 is seven minutes before 21:25.
- Ask for evidence that the gate clock was synchronized before making a strong conclusion.
Arrival order may hide an earlier event; clock quality is part of the evidence.
How this helps with your missionFor the mission, build two UTC timelines from three messages: by received_at, E1 21:07, CRASH 21:26, E2 21:36; by event_at, E1 21:05, E2 21:18, CRASH 21:25. Calculate eighteen minutes between E2's reported time and receipt, and seven minutes between E2 and the CRASH signal. Explain Z, request independent clock checks, and remember that the timeline identifies no person behind SUPPLIER-SVC.
PART 3 · YOUR TURN
Use the lesson to solve the mission
Story scene · practical task
Mission: the command that arrived late
Voss puts E2 after the crash on a timeline based on receipt and calls it a reaction. Imani hands you the controller's time and three raw messages. Mara wants a timeline the team can check without accusing anyone from one timestamp. The story's meeting is near; the exercise has no timer.
Your task
- Order E1, CRASH, and E2 by receipt and then event time.
- Calculate E2's delay and its gap from the crash.
- Explain Z and why mixing UTC and local time is dangerous.
- Name one clock check and the limit of today's conclusion.
How to know you have succeeded
- Receipt E1–CRASH–E2; event E1–E2–CRASH.
- E2 arrives 18 minutes after its stated time and precedes the crash by 7 minutes on that clock.
- Z means UTC; comparing unconverted zones can mislead.
- Independent clock check; SUPPLIER-SVC still does not identify a person.
Try code or SQL and keep a local draft. The mission questions are checked separately below.
See the worked answer
- By received_at: E1 21:07, CRASH 21:26, E2 21:36. By event_at: E1 21:05, E2 21:18, CRASH 21:25.
- E2 has 18 minutes between stated event and receipt. 21:25 − 21:18 = 7 minutes before the crash signal according to those clocks.
- Z means UTC. These three values are comparable; local time without a zone needs conversion first.
- Compare the controller clock with independent logs and its synchronization status. The reordered copy is a strong lead, but it does not identify who used SUPPLIER-SVC.
You can place a late arrival in the timeline. Next you will decide when a calculation window can close and how to flag a message that arrives beyond the chosen delay.
Before you leave
Remember this
event_atis stated event time,received_atis receipt time, and processing may happen at a third time.- The
Zsuffix means UTC; do not compare local and UTC times without conversion. - Receipt order is E1, CRASH, E2; stated event order is E1, E2, CRASH.
- E2 reports 21:18 and arrives at 21:36, an eighteen-minute gap; its stated time is seven minutes before CRASH.
- A well-formatted time is not automatically true: check clock synchronization and independent records.
- The timeline corrects an arrival-based reading without proving why OPEN-18 exists or who used SUPPLIER-SVC.
Continue with the integrated lessons
After the lesson and its mission, work through the additional lessons below in order. Each workshop supplies its own fictional data: do not merge identifiers or times from separate exercises into the story timeline.
Part of the lesson · keep nearby
New words, explained
These are the names of ideas used in the lesson above. Return here whenever a word feels unfamiliar.
- Event time
- When the source says the fact happened.
- Receipt time
- When a system received the message.
- Processing time
- When a program actually read or computed from the message.
- UTC
- A shared time reference that avoids mixing local time zones.
- Z
- An ISO timestamp suffix meaning UTC.
- Late event
- An event received after others even though its stated event time is earlier.
- Synchronized clock
- A clock checked against a trusted time source.
Approfondissements de ce cours
Représenter l’heure sans confondre les échelles
Les systèmes utilisent le temps pour les délais, la planification, les statistiques, les journaux, la validité d’un cache et l’ordre des événements. Une horloge physique mesure des secondes ; une horloge logique compte des événements. L’oscillateur d’un circuit numérique et l’horloge qui produit des horodatages sont liés matériellement, mais leurs rôles ne sont pas identiques. Une heure inscrite dans un journal n’est pas une preuve automatique de l’ordre causal entre deux machines.
Le quartz fournit un oscillateur peu coûteux : son effet piézoélectrique couple déformation mécanique et champ électrique, et l’électronique compte ses cycles. Les imperfections et la température modifient sa fréquence ; cette erreur de vitesse est la dérive. Une partie par million vaut une microseconde par seconde, soit environ 86,4 ms par jour ou 31,5 s par année de 365 jours. Les notes donnent quelques dizaines de ppm pour des horloges courantes ; il faut mesurer l’équipement réel. Les horloges atomiques s’appuient sur une transition du césium ou du rubidium ; la seconde SI est définie à partir de 9 192 631 770 périodes de la transition du césium 133.
Les notes montrent un ordre de précision de 10^-14, soit environ une seconde sur trois millions d’années, un appareil au césium illustré autour de 20 000 livres sterling et une référence au rubidium autour de 1 000 livres : ces exemples datés ne sont ni une garantie métrologique de tout appareil ni un devis d’achat actuel. Le schéma GPS mentionne une constellation de 31 satellites à titre illustratif, sans en faire un effectif opérationnel permanent. Les satellites GNSS, dont GPS et Galileo, diffusent une référence de temps et de position ; un récepteur déduit des distances du délai de propagation et applique des corrections, notamment atmosphériques et relativistes. Un centre de données peut nécessiter une antenne extérieure pour obtenir un signal exploitable. Ni le nombre de satellites opérationnels ni la précision locale ne doivent être supposés constants.
Le temps atomique international, TAI, et le temps fondé sur la rotation terrestre, UT1, ne progressent pas exactement de la même façon. La rotation varie notamment sous l’effet de marées et d’autres phénomènes géophysiques. UTC fournit une référence civile liée au temps atomique avec des corrections entières ; les fuseaux locaux et les changements saisonniers sont appliqués à partir de cette référence. GMT désigne aujourd’hui usuellement UTC dans l’usage civil britannique, tandis qu’UT1 décrit le temps solaire moyen au méridien de référence : distinguer les usages historiques du mot GMT.
Le mécanisme étudié dans les notes ajoute éventuellement une seconde positive 23:59:60, ou prévoit une seconde négative, ce qui ferait une journée UTC de 86 401 ou 86 399 secondes au lieu de 86 400. L’annonce intervient à l’avance mais ne permet pas de connaître indéfiniment les corrections futures. La résolution 4 de la CGPM de 2022 prévoit une évolution du lien UTC–UT1 d’ici ou avant 2035 ; ne pas coder la politique historique comme une règle immuable. Consulter les décisions et annonces officielles adaptées à la période traitée.
Un timestamp Unix compte les secondes depuis le 1er janvier 1970 à 00:00 UTC en excluant habituellement les secondes intercalaires ; une représentation ISO 8601 exprime calendrier, heure et décalage, par exemple 2026-11-06T10:00:00+00:00. L’année grégorienne est bissextile si elle est divisible par 4, sauf les siècles non divisibles par 400. Calculer une durée physique précise entre dates lointaines peut exiger les corrections de l’échelle de temps. Python datetime et les timestamps POSIX ne constituent pas un calendrier universel des secondes intercalaires.
L’incident collectif du 30 juin 2012 décrit par le support était lié à une mauvaise gestion d’une seconde intercalaire, avec un problème de vivelock du noyau Linux. Un redémarrage ne suffisait pas nécessairement à corriger l’état de l’horloge. Certains systèmes étalent une correction sur plusieurs heures : c’est le leap smear. Des politiques d’étalement différentes peuvent diverger, et la mesure n’est plus strictement la même que l’échelle UTC pendant la fenêtre. Le smear est un compromis opérationnel à documenter, pas une suppression mathématique des difficultés.
Exemple appliqué aux données
from decimal import Decimal
from datetime import datetime, timezone
dérive = Decimal(6 * 3600) * Decimal(20) / 1_000_000
assert dérive == Decimal('0.432')
date = datetime(2026, 11, 6, 10, tzinfo=timezone.utc)
assert date.isoformat() == '2026-11-06T10:00:00+00:00'
def bissextile(année):
return année % 4 == 0 and (année % 100 != 0 or année % 400 == 0)
assert bissextile(2000) and not bissextile(1900)
Simulation Python locale à exécuter séparément. Les assertions vérifient les cas présentés ; ce code ne constitue pas une implémentation distribuée de production.
À toi de jouer
Calcule la dérive théorique après six heures à 20 ppm. Explique ensuite pourquoi soustraire deux timestamps Unix ne prouve pas toujours le nombre exact de secondes SI écoulées à travers une correction UTC.
Voir la correction expliquée
6×3600×20×10^-6 = 0,432 seconde. Une représentation POSIX ignore les secondes intercalaires, et l’horloge système peut être ajustée ou étalée. Il faut connaître l’échelle et la politique de correction ; pour un intervalle local courant, utiliser une horloge monotone appropriée.
Références : Notes originales de Martin Kleppmann — Cambridge 2025/26 · Définition du SI — BIPM · Évolution UTC — résolution CGPM 2022.
Adapté de Distributed Systems — notes de cours 2025/26, Martin Kleppmann, University of Cambridge, pages 27–31. Consulter le PDF source et ses illustrations · Provenance. Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) — adaptation française et exemples modifiés
Synchroniser les horloges et mesurer une durée
La dérive est une différence de vitesse ; le décalage, ou skew, est la différence de lecture entre deux horloges à un instant donné. Une horloge à quartz, souvent maintenue par batterie quand la machine est éteinte, doit être corrigée. NTP et PTP diffusent des références temporelles ; les configurations et la précision dépendent du système et du réseau. Une hiérarchie NTP organise des sources de référence au stratum 0, des serveurs directement synchronisés au stratum 1 puis des serveurs de niveaux suivants. Interroger plusieurs sources et filtrer les échantillons aberrants réduit certains biais sans abolir l’incertitude.
Un échange NTP mesure quatre dates : t1 à l’émission côté client, t2 à la réception serveur, t3 à l’envoi serveur et t4 au retour client. Le délai aller-retour réseau estimé est delta=(t4−t1)−(t3−t2), qui enlève le temps de traitement serveur. Le décalage estimé du serveur par rapport au client vaut theta=((t2−t1)+(t3−t4))/2. Cette estimation suppose un trajet à peu près symétrique ; une file d’attente dans un seul sens peut la biaiser. Sans autre information et avec des délais non négatifs, l’erreur d’asymétrie peut atteindre delta/2, hors erreurs des horloges elles-mêmes.
La correction peut se faire en ajustant légèrement la fréquence, le slewing, ou en sautant à une autre valeur, le stepping. Les seuils simplifiés de 125 ms et 1000 s dans les notes ne sont pas universels : la documentation de l’implémentation NTP de référence 4.2.8 décrit notamment un seuil de saut par défaut de 128 ms, une persistance de 300 s et un seuil de panique de 1000 s, tous configurables avec des comportements d’initialisation particuliers. D’autres démons ont d’autres politiques. Surveiller l’état de synchronisation et l’erreur estimée reste nécessaire, même si un service NTP est actif.
Une horloge de calendrier, telle time.time en Python, fournit une date relative à une époque connue ; elle peut sauter vers l’avant ou vers l’arrière lors d’une correction. Soustraire deux lectures peut donc produire une durée trompeuse, voire négative. Une horloge monotone est conçue pour ne pas reculer sous l’effet d’un réglage de l’heure ; sa vitesse et son comportement pendant une suspension dépendent de la plateforme. time.monotonic_ns fournit des lectures entières adaptées à une différence locale, sans garantir qu’un nanoseconde affichée correspond à une résolution matérielle d’une nanoseconde.
Le point de référence monotone est arbitraire : ce sont les différences entre lectures compatibles qui ont un sens. Ne pas comparer des compteurs monotones pris sur deux machines pour dater des événements mondiaux. Utiliser UTC conscient du fuseau pour les journaux, et une durée monotone locale pour un timeout ou une mesure de performance. La source présente l’analogie Java currentTimeMillis/nanoTime et Linux CLOCK_REALTIME/CLOCK_MONOTONIC ; nos exemples emploient les fonctions Python correspondantes.
Exemple appliqué aux données
from time import monotonic_ns
t1, t2, t3, t4 = 10, 13, 14, 13
délai = (t4-t1) - (t3-t2)
décalage = ((t2-t1) + (t3-t4)) / 2
assert (délai, décalage) == (2, 2)
début = monotonic_ns()
sum(range(1000))
durée_ns = monotonic_ns() - début
assert durée_ns >= 0
Simulation Python locale à exécuter séparément. Les assertions vérifient les cas présentés ; ce code ne constitue pas une implémentation distribuée de production.
À toi de jouer
Pour t1=10, t2=13, t3=14 et t4=13, calcule delta et theta. Choisis ensuite le type d’horloge pour un timeout local, la validité d’un certificat et l’ordre de mises à jour concurrentes.
Voir la correction expliquée
delta=(13−10)−(14−13)=2 ; theta=((13−10)+(14−13))/2=2. Un timeout local utilise une durée monotone ; la validité d’un certificat demande une date de calendrier correctement synchronisée ; les dépendances de mises à jour concurrentes demandent une information causale comme une horloge vectorielle, pas seulement l’heure civile.
Références : Notes originales de Martin Kleppmann — Cambridge 2025/26 · Horloges Python 3.12 · NTP 4.2.8 — ajustement de l’horloge.
Adapté de Distributed Systems — notes de cours 2025/26, Martin Kleppmann, University of Cambridge, pages 32–35. Consulter le PDF source et ses illustrations · Provenance. Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) — adaptation française et exemples modifiés