Clocks and Synchronization - kombu.clocks

kombu.clocks

Logical Clocks and Synchronization.

class kombu.clocks.LamportClock(initial_value=0, Lock=<built-in function allocate_lock>)[source]

Lamport’s logical clock.

From Wikipedia:

A Lamport logical clock is a monotonically incrementing software counter maintained in each process. It follows some simple rules:

  • A process increments its counter before each event in that process;
  • When a process sends a message, it includes its counter value with the message;
  • On receiving a message, the receiver process sets its counter to be greater than the maximum of its own value and the received value before it considers the message received.

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 resynchronizes its logical clock with the sender.

Usage

When sending a message use forward() to increment the clock, when receiving a message use adjust() to sync with the time stamp of the incoming message.

adjust(other)[source]
forward()[source]
sort_heap(h)[source]

List of tuples containing at least two elements, representing an event, where the first element is the event’s scalar clock value, and the second element is the id of the process (usually "hostname:pid"): sh([(clock, processid, ...?), (...)])

The list must already be sorted, which is why we refer to it as a heap.

The tuple will not be unpacked, so more than two elements can be present.

Will return the latest event.

value = 0

The clocks current value.

class kombu.clocks.timetuple[source]

Tuple of event clock information.

Can be used as part of a heap to keep events ordered.

Parameters:
  • clock – Event clock value.
  • timestamp – Event UNIX timestamp value.
  • id – Event host id (e.g. hostname:pid).
  • obj – Optional obj to associate with this event.
clock

itemgetter(item, ...) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])

id

itemgetter(item, ...) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])

obj

itemgetter(item, ...) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])

timestamp

itemgetter(item, ...) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])