Lamport timestamp

The Lamport timestamp algorithm is a simple logical clock algorithm used to determine the order of events in a distributed computer system. As different nodes or processes will typically not be perfectly synchronized, this algorithm is used to provide a partial ordering of events with minimal overhead, and conceptually provide a starting point for the more advanced vector clock method. The algorithm is named after its creator, Leslie Lamport.

Distributed algorithms such as resource synchronization often depend on some method of ordering events to function. For example, consider a system with two processes and a disk. The processes send messages to each other, and also send messages to the disk requesting access. The disk grants access in the order the messages were received. For example process sends a message to the disk requesting write access, and then sends a read instruction message to process . Process receives the message, and as a result sends its own read request message to the disk. If there is a timing delay causing the disk to receive both messages at the same time, it can determine which message happened-before the other: happens-before if one can get from to by a sequence of moves of two types: moving forward while remaining in the same process, and following a message from its sending to its reception. A logical clock algorithm provides a mechanism to determine facts about the order of such events. Note that if two events happen in different processes that do not exchange messages directly or indirectly via third-party processes, then we say that the two processes are concurrent, that is, nothing can be said about the ordering of the two events.[1]

Lamport invented a simple mechanism by which the happened-before ordering can be captured numerically. A Lamport logical clock is a numerical software counter value maintained in each process.

Conceptually, this logical clock can be thought of as a clock that only has meaning in relation to messages moving between processes. When a process receives a message, it re-synchronizes its logical clock with that sender. The above-mentioned vector clock is a generalization of the idea into the context of an arbitrary number of parallel, independent processes.

Algorithm

The algorithm follows some simple rules:

  1. A process increments its counter before each local event (e.g., message sending event);
  2. When a process sends a message, it includes its counter value with the message after executing step 1;
  3. On receiving a message, the counter of the recipient is updated, if necessary, to the greater of its current counter and the timestamp in the received message. The counter is then incremented by 1 before the message is considered received.[2]

In pseudocode, the algorithm for sending is:

# event is known
time = time + 1;
# event happens
send(message, time);

The algorithm for receiving a message is:

(message, timestamp) = receive();
time = max(timestamp, time) + 1;

Considerations

For every two different events and occurring in the same process, and being the timestamp for a certain event , it is necessary that never equals .

Therefore it is necessary that:

  • The logical clock be set so that there is a minimum of one clock "tick" (increment of the counter) between events and ;
  • In a multi-process or multi-threaded environment, it might be necessary to attach the process ID (PID) or any other unique ID to the timestamp so that it is possible to differentiate between events and which may occur simultaneously in different processes.

Causal ordering

For any two events, and , if there’s any way that could have influenced , then the Lamport timestamp of will be less than the Lamport timestamp of . It’s also possible to have two events where we can’t say which came first; when that happens, it means that they couldn’t have affected each other. If and can’t have any effect on each other, then it doesn’t matter which one came first.

Implications

A Lamport clock may be used to create a partial ordering of events between processes. Given a logical clock following these rules, the following relation is true: if then , where means happened-before.

This relation only goes one way, and is called the clock consistency condition: if one event comes before another, then that event's logical clock comes before the other's. The strong clock consistency condition, which is two way (if then ), can be obtained by other techniques such as vector clocks. Using only a simple Lamport clock, only a partial causal ordering can be inferred from the clock.

However, via the contrapositive, it's true that implies . So, for example, if then cannot have happened-before .

Another way of putting this is that means that may have happened-before , or be incomparable with in the happened-before ordering, but did not happen after .

Nevertheless, Lamport timestamps can be used to create a total ordering of events in a distributed system by using some arbitrary mechanism to break ties (e.g., the ID of the process). The caveat is that this ordering is artificial and cannot be depended on to imply a causal relationship.

Lamport's logical clock in distributed systems

In a distributed system, it is not possible in practice to synchronize time across entities (typically thought of as processes) within the system; hence, the entities can use the concept of a logical clock based on the events through which they communicate.

If two entities do not exchange any messages, then they probably do not need to share a common clock; events occurring on those entities are termed as concurrent events.

Among the processes on the same local machine we can order the events based on the local clock of the system.

When two entities communicate by message passing, then the send event is said to happen-before the receive event, and the logical order can be established among the events.

A distributed system is said to have partial order if we can have a partial order relationship among the events in the system. If 'totality', i.e., causal relationship among all events in the system, can be established, then the system is said to have total order.

A single entity cannot have two events occur simultaneously. If the system has total order we can determine the order among all events in the system. If the system has partial order between processes, which is the type of order Lamport's logical clock provides, then we can only tell the ordering between entities that interact. Lamport addressed ordering two events with the same timestamp (or counter): "To break ties, we use any arbitrary total ordering of the processes."[2] Thus two timestamps or counters may be the same within a distributed system, but in applying the logical clocks algorithm events that occur will always maintain at least a strict partial ordering.

Lamport clocks lead to a situation where all events in a distributed system are totally ordered. That is, if , then we can say actually happened before .

Note that with Lamport’s clocks, nothing can be said about the actual time of and . If the logical clock says , that does not mean in reality that actually happened before in terms of real time.

Lamport clocks show non-causality, but do not capture all causality. Knowing and shows did not cause or but we cannot say which initiated .

This kind of information can be important when trying to replay events in a distributed system (such as when trying to recover after a crash). If one node goes down, and we know the causal relationships between messages, then we can replay those messages and respect the causal relationship to get that node back up to the state it needs to be in.[3]

Alternatives to potential causality

The happened-before relation captures potential causality, not true causality. In 2011-12, Munindar Singh proposed a declarative, multiagent approach based on true causality called information protocols. An information protocol specifies the constraints on communications between the agents that constitute a distributed system.[4] However, instead of specifying message ordering (e.g., via a state machine, a common way of representing protocols in computing), an information protocol specifies the information dependencies between the communications that agents (the protocol's endpoints) may send. An agent may send a communication in a local state (its communication history) only if the communication and the state together satisfy the relevant information dependencies. For example, an information protocol for an e-commerce application may specify that to send a Quote with parameters ID (a uniquifier), item, and price, Seller must already know the ID and item from its state but can generate whatever price it wants. A remarkable thing about information protocols is that although emissions are constrained, receptions are not. Specifically, agents may receive communications in any order whatsoever -- receptions simply bring information and there is no point delaying them. This means that information protocols can be enacted over unordered communication services such as UDP.

The bigger idea is that of application semantics, the idea of designing distributed systems based on the content of the messages, an idea implicated in the end-to-end principle. Current approaches largely ignore semantics and focus on providing application-agnostic ("syntactic") message delivery and ordering guarantees in communication services, which is where ideas like potential causality help. But if we had a suitable way of doing application semantics, then we wouldn't need such communication services. An unordered, unreliable communication service would suffice. The real value of information protocols approach is that it provides the foundations for an application semantics approach.

See also

References

Read other articles:

Disambiguazione – Se stai cercando altri significati, vedi Quadri di un'esposizione (disambigua). Quadri di un'esposizioneLa copertina della prima edizioneCompositoreModest Petrovič Musorgskij Tipo di composizioneSuite Epoca di composizione2-22 giugno 1874 Pubblicazione1886, a cura di Nikolaj Rimskij-Korsakov AutografoBiblioteca nazionale russa, San Pietroburgo DedicaVladimir Vasil'evič Stasov Durata media33 minuti Organicopianoforte Manuale Modest Musorgskij Aiuto Modest Petrovič Musor…

Spanish- and Catalan-language newspaper, printed in Barcelona For the Argentine newspaper, see La Vanguardia (Argentina). La VanguardiaLa Vanguardia in a post-boxTypeDaily newspaperFormatTabloidOwner(s)Grupo GodóPublisherJavier Godó (Earl of Godó)EditorJordi JuanFounded1 February 1881Political alignmentLiberalism, Catalanism, monarchism[citation needed], centrismLanguageSpanish (since 1881) and Catalan (since 2011)HeadquartersBarcelona, SpainCirculation196,824 (2011)Sister newspapersM…

Artikel ini tidak memiliki referensi atau sumber tepercaya sehingga isinya tidak bisa dipastikan. Tolong bantu perbaiki artikel ini dengan menambahkan referensi yang layak. Tulisan tanpa sumber dapat dipertanyakan dan dihapus sewaktu-waktu.Cari sumber: Daftar pusat perbelanjaan di Indonesia – berita · surat kabar · buku · cendekiawan · JSTOR Berikut adalah daftar pusat perbelanjaan di Indonesia, tidak termasuk supermarket/hipermarket yang berdiri sendiri.…

Державний комітет телебачення і радіомовлення України (Держкомтелерадіо) Приміщення комітетуЗагальна інформаціяКраїна  УкраїнаДата створення 2003Керівне відомство Кабінет Міністрів УкраїниРічний бюджет 1 964 898 500 ₴[1]Голова Олег НаливайкоПідвідомчі орг…

Cet article est une ébauche concernant une commune d’Indre-et-Loire. Vous pouvez partager vos connaissances en l’améliorant (comment ?). Le bandeau {{ébauche}} peut être enlevé et l’article évalué comme étant au stade « Bon début » quand il comporte assez de renseignements encyclopédiques concernant la commune. Si vous avez un doute, l’atelier de lecture du projet Communes de France est à votre disposition pour vous aider. Consultez également la page d’aide…

此條目可能包含不适用或被曲解的引用资料,部分内容的准确性无法被证實。 (2023年1月5日)请协助校核其中的错误以改善这篇条目。详情请参见条目的讨论页。 各国相关 主題列表 索引 国内生产总值 石油储量 国防预算 武装部队(军事) 官方语言 人口統計 人口密度 生育率 出生率 死亡率 自杀率 谋杀率 失业率 储蓄率 识字率 出口额 进口额 煤产量 发电量 监禁率 死刑 国债 外…

2003 single by No AngelsSomedaySingle by No Angelsfrom the album Pure Released13 July 2003RecordedDepartment Studios (Frankfurt)Length3:16Label Cheyenne Polydor Songwriter(s) Niklas Hillbom Thomas Jansson Producer(s)Thorsten BrötzmannNo Angels singles chronology No Angel (It's All in Your Mind) (2003) Someday (2003) Feelgood Lies (2003) Someday is a song performed by all-female German group No Angels. Written and composed by Swedish musicians Thomas Jansson and Niklas Hillbom, it was produced b…

1999 South Asian GamesTournament detailsHost country NepalDates24 September – 4 OctoberTeams6 (from 1 confederation)Venue(s)1 (in 1 host city)Final positionsChampions Bangladesh (1st title)Runners-up   NepalThird place IndiaTournament statisticsMatches played13Goals scored45 (3.46 per match)Top scorer(s) I. M. Vijayan (7 goals)Best player(s) I. M. Vijayan← 1995 2004 → All statistics correct as of 4 October 1999.International football com…

English footballer For the Darlington winger, see Chris Neal (footballer, born 1947). For other people with similar names, see Chris Neal (disambiguation). Chris Neal Neal with Port Vale in 2013Personal informationFull name Christopher Michael Neal[1]Date of birth (1985-10-23) 23 October 1985 (age 38)[2]Place of birth St Albans, England[2]Height 6 ft 2 in (1.88 m)[3]Position(s) GoalkeeperTeam informationCurrent team AFC FyldeNumber 1Senior care…

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (مارس 2020) المجلس الاقتصادي والاجتماعي والثقافي الأفريقي (ECOSOCC) هو هيئة استشارية للاتحاد الأفريقي تهدف إلى إعطاء منظمات المجتمع المدني في أفريقيا صوتًا داخل مؤسسات الاتح…

Okinawa Convention Center Okinawa Convention Center adalah sebuah pusat konvensi yang terletak di Ginowan, Prefektur Okinawa, Jepang.[1] Fungsi Okinawa Convention Center utamanya difungsikan untuk kegiatan MICE. Di dalamnya terdapat tiga ruang konferensi, teater dan ruang pameran. Jenis pameran yang diadakan di Okinawa Convention Center ialah pameran dagang. Kapasitas pengunjung yang mampu ditampung di Okinawa Convention Center sebanyak delapan ribu orang.[2] Pelayanan Pelayanan …

Частина серії проФілософіяLeft to right: Plato, Kant, Nietzsche, Buddha, Confucius, AverroesПлатонКантНіцшеБуддаКонфуційАверроес Філософи Епістемологи Естетики Етики Логіки Метафізики Соціально-політичні філософи Традиції Аналітична Арістотелівська Африканська Близькосхідна іранська Буддійсь…

Akbar Hashemi Rafsanjani اکبر هاشمی رفسنجانی Presiden Republik Islam Iran ke-4Masa jabatan3 Agustus 1989 – 2 Agustus 1997Wakil PresidenHassan HabibiPemimpinAli KhameneiPendahuluAli KhameneiPenggantiMohammad Khatami Informasi pribadiLahir(1934-02-15)15 Februari 1934Nough, IranMeninggal8 Januari 2017(2017-01-08) (umur 82)Tajrish, IranPartai politikAsosiasi Ulama MilitanSunting kotak info • L • B Akbar Rafsanjani di sampul majalah TIME edisi Timur Teng…

Fictional character Soap opera character Maggie AstoniHome and Away characterPortrayed byKestie MorassiDuration2017–2020First appearance21 June 2017 (2017-06-21)Last appearance14 July 2020 (2020-07-14)ClassificationFormer; regularIntroduced byLucy AddarioIn-universe informationOccupationPrincipal of Summer Bay HighFatherRichard WalfordMotherDiana WalfordSistersKate WalfordHusbandBen AstoniDaughtersZiggy AstoniCoco AstoniGranddaughtersIzzy Thomp…

War in Iraq redirects here. For other wars, see Iraq War (disambiguation), Iraqi Civil War (disambiguation), and List of conflicts in Iraq. This is a list of wars involving the Republic of Iraq and its predecessor states. Conflict Combatant 1 Combatant 2 Results Iraqi losses Head of State Prime Minister Military Civilians Mesopotamian Campaign(1914–1918 WWI) Ottoman Empire Ottoman Iraq German Empire United Kingdom Kuwait Australia  India New Zealand Defeat Ottoman Iraq comes under British…

Archivo:Venezia Santa Lucia train station.jpgFachada de la entrada de la estación de Santa Lucía La estación de Venecia Santa Lucía (Stazione di Venezia Santa Lucia en italiano) es la principal estación ferroviaria de la ciudad de Venecia. Se encuentra en el km 267 de la línea ferroviaria Milán-Venecia. Ubicación Vista aérea de la estación Su encuentra en el extremo occidental del Gran Canal, en el barrio de Cannaregio. La acera ubicada frente a la estación está comunicada con el Pia…

1904 science fiction novel by H. G. Wells The Food of the Gods and How It Came to Earth First edition (UK)AuthorH. G. WellsLanguageEnglishGenreScience fiction, Romance novelPublished1904 (Macmillan)Publication placeUnited KingdomMedia typePrint (Hardcover and Paperback)Pages317TextThe Food of the Gods and How It Came to Earth at Wikisource The Food of the Gods and How It Came to Earth is a science fiction novel by H. G. Wells that was first published in 1904. Wells called it a fantasia on t…

Stimulant of the cathinone class N-EthylhexedroneLegal statusLegal status BR: Class F2 (Prohibited psychotropics)[1] CA: Schedule I DE: Anlage II (Authorized trade only, not prescriptible) UK: Class B US: Schedule I UN: Psychotropic Schedule II Illegal in Japan and a controlled substance in Sweden Pharmacokinetic dataMetabolismNeurometabolicIdentifiers IUPAC name 2-(Ethylamino)-1-phenylhexan-1-one CAS Number802857-66-5 YHCl  : 18410-62-3&…

Switched network of teleprinters This article is about the teleprinter network. For other uses, see Telex (disambiguation). This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Telex – ne…

Léo Bonatini Datos personalesNombre completo Leonardo Bonatini Lohner MaiaNacimiento Belo Horizonte, Brasil28 de marzo de 1994 (30 años)Nacionalidad(es) BrasileñaItalianaAltura 1,85 m (6′ 1″)Carrera deportivaDeporte FútbolClub profesionalDebut deportivo 2013(Goiás E. C.)Club Atlético de San LuisLiga Liga MXPosición DelanteroDorsal(es) 9Trayectoria Cruzeiro E. C. (2013-15) → Goiás E. C. (2013-14) → G. D. Estoril Praia (2015) G. D. Estoril Praia (2015-16) Al-Hilal Saudi F…