Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequential consistency in newbie terms?

Sequential consistency

The result of any execution is the same as if the operations of all the processors were executed in some sequential order, and the operations of each individual processor appear in this sequence in the order specified by its program.

I'm new to distributed system, what does execution mean in this context, and please explain this definition in a simple way?

like image 603
Henok Tesfaye Avatar asked Feb 02 '19 13:02

Henok Tesfaye


1 Answers

A program running in a sequentially consistent and distributed environment will behave as if all the instructions are interleaved in a sequential manner. This means multiple execution paths are possible and allowed, provided that the instruction order of each thread of execution is preserved.

Example:

Lets say we have a program with two threads that is run in a distributed system with 2 processors:

Thread 1: print "Hello\n" ; print "world \n"

Thread 2: print "Hi! \n"

Assumption: In this language "print" is thread safe and not buffered.

Sequential consistency rule: "Hello" will always be printed before "world" ; .

Possible execution 1:

 Processor 1    | Processor 2
                |
 Hello          |
 World          |
                | Hi!
                |

Possible execution 2

 Processor 1    | Processor 2
                |
 Hello          |
                |Hi!
 world          |

Possible execution 3

 Processor 1    | Processor 2
                |
                |Hi!
 Hello          |
 world          |

Not possible execution (printing "world" before "Hello" breaks sequential consistency)

 Processor 1    | Processor 2
                |
                |Hi!
 world          |
 Hello          |

Now, revisiting your definition:

The result of any execution is the same as if the operations of all the processors were executed in some sequential order, and the operations of each individual processor appear in this sequence in the order specified by its program.

And rewording it with the example above:

In a distributed environment that is sequential consistent, the result of any execution(see the possible 3 executions in the above example) = executing the instructions of the processor 1 & processor 2 in a some sequential order, while preserving the instruction order specified in the program("Hello" should be printed before "world").

i.e, the execution results are the same as if the instructions executed in the different processors were interleaved sequentially and executed in a single 1 core processor. Thus being sequential consistent provides predictability to the distributed system and establishes certain important guarantees when memory access is involved.

Hope this helps!

like image 165
Malloc Avatar answered Sep 17 '22 16:09

Malloc