SlideShare a Scribd company logo
Doveryai, no Proveryai
Introduction to TLA+
Sandeep Joshi
11 Nov, 2017, Pune
https://expert-talks.in 1
Doveryai, no Proveryai
A Russian proverb which means “Trust,
but verify”.
Popular during the Cold War when the
US and Soviet Union were signing
nuclear disarmament accords.
2
Talk overview
1. Problem definition
2. What is TLA+, PlusCal, TLC...
3. Example 1 : Childcare facility
4. Example 2 : Dining Philosophers
5. Example 3 : Alternating Bit Protocol
6. Concluding observations
Code : https://github.com/sanjosh/tlaplus
Slides: https://www.slideshare.net/SandeepJoshi55/
3
Hard to prove correctness in a distributed system
In a distributed system, how do you prove
1. Safety : Something bad will never happen
2. Liveness : Something good will eventually happen
When you have
1. Multiple agents/actors, each with their state machine(FSM)
2. Non-determinism which leads to Arbitrary Interleaved execution
3. Failures and restarts
4
Microsoft .NET remote authentication FSMs https://msdn.microsoft.com/en-us/library/ms973909.aspx
Verify if this 2-process FSM (.NET) is correct.. ?
5
Or this 2-process FSM (for TCP) is correct ?
https://thewalnut.io/app/release/73/
6
CHESS : Systematic testing of concurrent programs http://slideplayer.com/slide/13582/
Interleaved execution causes ...
7
How to reason about time in a distributed system
Required :
1. A formal theory
2. A language to express the problem
3. A tool to verify
8
How to reason about time in a distributed system
Required :
1. A formal theory : Temporal Logic
2. A language to express the problem : TLA+ and others.
3. A tool to verify : TLC and other model checkers
9
Temporal logic simplified
In programs, we write formulae using Boolean operators (AND, OR, NOT).
“Assert (a > 0 AND b < 0)”
Temporal logic provides you with temporal operators which hold over one or
more paths of execution (called “Path quantifiers”).
1. I will like chocolate from now on.
2. After weather becomes cold, at some point, I will start eating chocolate.
https://en.wikipedia.org/wiki/Computation_tree_logic#Examples
10
What is TLA+
● Language created by Leslie Lamport to express temporal logic.
● PlusCal is a simpler variant of TLA+ (This talk uses PlusCal).
● TLC is the “model checker” - the compiler which verifies if your PlusCal
program is correct.
● It has a GUI called Toolbox. In this talk, only command line tool is used.
11
How to get started with TLA+
● Read general background on model checkers
● Download the TLA toolbox (GUI + java jar file)
● Read the PlusCal manual and Lamport’s tutorial “Specifying systems”
● Read sample PlusCal programs written by others
● Start with a small problem and try writing your own program
● Run it...
$ java pcal.trans myspec.tla
$ java tlc2.TLC myspec.tla
12
Childcare facility problem
Children and adults continuously enter and exit a childcare facility.
Ensure that there is always one adult present for every three children.
[ from The Little Book of Semaphores by Allen Downey ]
13
Childcare constraints
Adult can enter anytime, but exit ONLY if
1. NEW number of adults is at least three times number of children
Children can exit anytime, but enter ONLY if
1. Number of adults is at least three times NEW number of children
14
Childcare - create child & parent process
Define a PlusCal “process” for each actor in your system
-- algorithm childcare {
Process (a in 1.. ADULTS) {... }
Process (c in 1..CHILDREN) {... }
}
15
Childcare - “labels” denote Atomic actions
Use one PlusCal label for each atomic action of Child.
Child performs two actions : enter and exit the childcare facility.
Process {
c_enter: number_children = number_children + 1
c_exit : number_children = number_children - 1
}
16
What are PlusCal Labels
All statements within a label are atomically executed by TLC.
TLC internally interleaves the execution of many processes in order
to verify correctness
LabelA : Y = X + 1
Label1 : X = Y + 1
17
Label2 : X = Y - 1
Child 1 Adult 2
Childcare - use “await” to wait for a condition
Every Child will wait until there are sufficient number of adults present inside
c_enter : Await (number_adults * 3 >= number_children + 1)
number_children = number_children + 1
c_exit : number_children = number_children - 1
Assert (number_adults * 3 >= number_children)
18
Childcare - specify adult process
Follow same steps to define adult process - using process, label, await
19
Process {
a_enter: number_adults = number_adults + 1
a_exit : Await ( number_adults * 3 >= number_children)
number_adults = number_adults - 1
Assert (number_adults * 3 >= number_children)
}
TLC (model checker) Failure output
At this point, assert fires
since adult exited due to
incorrect “await”
condition
20
Childcare - correct the condition
Change the await condition to check new value instead of old
21
Process {
a_enter: number_adults = number_adults + 1
a_exit : Await ((number_adults - 1)* 3 >= number_children)
number_adults = number_adults - 1
}
Childcare - complete spec
22
TLC (model checker) output on success
23
Dining Philosophers Problem
Each philosopher keeps doing the following
1. Think
2. Take right fork
3. Take left fork
4. Eat
5. Put down both forks
24
Dining Philosophers with PlusCal
Define five philosopher instances; Step through three labels (atomic actions)
25
Process (ph in 1..5) {
Wait_first_fork : await (forks[right] = FALSE);
forks[right] = TRUE;
}
Dining Philosophers with PlusCal
Define five philosopher instances; Step through three labels (atomic actions)
26
Process (ph in 1..5) {
Wait_first_fork : await (forks[right] = FALSE);
forks[right] = TRUE;
Wait_second_fork: await (forks[left] = FALSE);
forks[left] = TRUE;
}
Dining Philosophers with PlusCal
Define five philosopher instances; Step through three labels (atomic actions)
27
Process (ph in 1..5) {
Wait_first_fork : await (forks[right] = FALSE);
forks[right] = TRUE;
Wait_second_fork: await (forks[left] = FALSE);
forks[left] = TRUE;
Done_eating : forks[left] = forks[right] = FALSE;
}
Dining Philosophers - complete spec
28
Dining Philosophers - deadlock !
29
Dining Philosophers - deadlock !
All five philosophers are waiting
for second fork !
30
Dining Philosophers - Introduce asymmetry
To resolve deadlock, third philosopher will pick left fork first.
31
Process (ph in 1..5) {
Init : if (self = 3) { swap(right, left); };
Wait_first_fork : await (forks[right] = FALSE); forks[right] = TRUE;
Wait_second_fork: await (forks[left] = FALSE); forks[left] = TRUE;
Done_eating : forks[left] = forks[right] = FALSE;
}
Dining Philosophers - complete spec
32
Dining Philosophers - no deadlock !
33
Alternate bit protocol over lossy channel
34
Sender Receiver
Message channel
Ack channel
Both channels
are lossy
https://en.wikipedia.org/wiki/Alternating_bit_protocol
Discussed in Lamports’ book “Specifying Systems”.
Alternate bit protocol - define channel
Use “Sequences” module to define the communication channels
Declare the channels as a Sequence
Variables msgChan = <<>>, ackChan = <<>>
Append to channel
Append(msgChan, m)
Extract using
“Head(msgChan)” or “Tail(msgChan)”
35
Alternate bit protocol - sender and receiver process
Process (Sender = “S”) {
Send message
OR
Receive Ack
}
36
Define one Process each for Sender and Receiver
Process (Receiver = “S”) {
Receive message
OR
Send Ack
}
Alternate bit protocol - sender and receiver process
Process (Sender = “S”) {
Either {
Append(<<input>>, msgChan)
} or {
Recv(ack, ackChan)
}
}
37
Define one Process each for Sender and Receiver
Process (Receiver = “S”) {
Either {
Append(rbit, ackChan)
} or {
Recv(msg, msgChan)
}
}
PlusCal - Either Or
“Either Or” is an important feature of PlusCal language (TLA+)
It allows you to simulate non-determinism
TLC (model checker) will test both options at runtime.
38
Either { Do this }
Or { Do that }
Alternate Bit protocol - simulate lossy channel
To simulate lossy channel, add another process which randomly deletes
messages.
39
Process (LoseMsg = “L”) {
randomly delete messages from either channel
}
Alternate Bit protocol - simulate lossy channel
To simulate lossy channel, add another process which randomly deletes
messages.
40
Process (LoseMsg = “L”) {
While TRUE{
Either with (1 in 1..Len(msgChan)) {
msgChan = Remove(i, msgChan)
} or with (1 in 1..Len(ackChan)) {
ackChan = Remove(i, ackChan);
}
PlusCal constructs introduced
1. Algorithm : A problem that you want to model.
2. Process : An actor/thread of execution within the algorithm.
3. Labels : All statements inside a label are atomically executed.
4. Await : only execute after condition becomes true
5. Either-Or : non-deterministic execution of alternatives
6. With : Non-deterministically choose one element out of a Set.
41
Notable users of TLA+
1. Intel CPU cache coherence protocol [Brannon Batson]
2. Microsoft CosmosDB
3. Amazon : S3, DynamoDB, EBS, Distributed Lock manager [Chris
Newcombe]
Newcombe(Amazon) has released two of their TLA+ specs
(See my github for a copy)
None of the others are publicly available
42
Conclusion
1. TLC can find bugs.
2. Complex programs can take hours to run (TLC also has “simulation” mode
which does random verification)
Learning curve
1. Formulation : Lack of sample programs, but google group is helpful.
2. Debugging : Check the backtrace; add prints !
3. Mastery over TLA+ requires some Mathematics knowledge (i.e. Set theory).
4. [Newcombe, Experience of Software Engineers using TLA+]
http://tla2012.loria.fr/contributed/newcombe-slides.pdf
43
Questions
Code : https://github.com/sanjosh/tlaplus (README has
references)
Slides: https://www.slideshare.net/SandeepJoshi55/
44
TLA+ operators
1. <> P : atleast one execution path has P true
2. [] P : P is eventually true
3. Q ~> P : If Q becomes true, P will be true
4. <>[] P : at some point P becomes true and stays true
45
Other model checkers besides TLA+
46
https://en.wikipedia.org/wiki/List_of_model_checking_tools

More Related Content

What's hot

An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
Adam Stephensen
 
Exploratory Testing Explained and Experienced
Exploratory Testing Explained and ExperiencedExploratory Testing Explained and Experienced
Exploratory Testing Explained and Experienced
Maaret Pyhäjärvi
 
Cruise Control: Effortless management of Kafka clusters
Cruise Control: Effortless management of Kafka clustersCruise Control: Effortless management of Kafka clusters
Cruise Control: Effortless management of Kafka clusters
Prateek Maheshwari
 
Software Testing: History, Trends, Perspectives - a Brief Overview
Software Testing: History, Trends, Perspectives - a Brief OverviewSoftware Testing: History, Trends, Perspectives - a Brief Overview
Software Testing: History, Trends, Perspectives - a Brief Overview
Softheme
 
Verification and validation process in software testing
Verification and validation process in software testingVerification and validation process in software testing
Verification and validation process in software testing
pooja deshmukh
 
Windows Internals: fuzzing, hijacking and weaponizing kernel objects
Windows Internals: fuzzing, hijacking and weaponizing kernel objectsWindows Internals: fuzzing, hijacking and weaponizing kernel objects
Windows Internals: fuzzing, hijacking and weaponizing kernel objects
Nullbyte Security Conference
 
Black Box Testing
Black Box TestingBlack Box Testing
Black Box Testing
Nivetha Padmanaban
 
Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...
Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...
Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...
Flink Forward
 
Effective Software Test Case Design Approach
Effective Software Test Case Design ApproachEffective Software Test Case Design Approach
Effective Software Test Case Design Approach
Charles D. Carson, MSSWE, CSM, ASQ-CSQE
 
Test case development
Test case developmentTest case development
Test case development
Hrushikesh Wakhle
 
Combinatorial software test design beyond pairwise testing
Combinatorial software test design beyond pairwise testingCombinatorial software test design beyond pairwise testing
Combinatorial software test design beyond pairwise testing
Justin Hunter
 
Using Modular Topologies in Kafka Streams to scale ksqlDB’s persistent querie...
Using Modular Topologies in Kafka Streams to scale ksqlDB’s persistent querie...Using Modular Topologies in Kafka Streams to scale ksqlDB’s persistent querie...
Using Modular Topologies in Kafka Streams to scale ksqlDB’s persistent querie...
HostedbyConfluent
 
Présentation Agile Testing
Présentation Agile TestingPrésentation Agile Testing
Présentation Agile Testing
jubehr
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
Mohamed Taman
 
Ship Faster, Reduce Risk, and Build Scale with Feature Flags
Ship Faster, Reduce Risk, and Build Scale with Feature FlagsShip Faster, Reduce Risk, and Build Scale with Feature Flags
Ship Faster, Reduce Risk, and Build Scale with Feature Flags
Atlassian
 
ReportPortal use cases presentation
 ReportPortal use cases presentation ReportPortal use cases presentation
ReportPortal use cases presentation
Dmitriy Gumeniuk
 
Dynamic dataflow on cgra
Dynamic dataflow on cgraDynamic dataflow on cgra
Dynamic dataflow on cgra
Ming-Hsiang Huang
 
Testing concepts [3] - Software Testing Techniques (CIS640)
Testing concepts [3] - Software Testing Techniques (CIS640)Testing concepts [3] - Software Testing Techniques (CIS640)
Testing concepts [3] - Software Testing Techniques (CIS640)
Venkatesh Prasad Ranganath
 

What's hot (20)

An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
 
Exploratory Testing Explained and Experienced
Exploratory Testing Explained and ExperiencedExploratory Testing Explained and Experienced
Exploratory Testing Explained and Experienced
 
Cruise Control: Effortless management of Kafka clusters
Cruise Control: Effortless management of Kafka clustersCruise Control: Effortless management of Kafka clusters
Cruise Control: Effortless management of Kafka clusters
 
Software Testing: History, Trends, Perspectives - a Brief Overview
Software Testing: History, Trends, Perspectives - a Brief OverviewSoftware Testing: History, Trends, Perspectives - a Brief Overview
Software Testing: History, Trends, Perspectives - a Brief Overview
 
Verification and validation process in software testing
Verification and validation process in software testingVerification and validation process in software testing
Verification and validation process in software testing
 
Windows Internals: fuzzing, hijacking and weaponizing kernel objects
Windows Internals: fuzzing, hijacking and weaponizing kernel objectsWindows Internals: fuzzing, hijacking and weaponizing kernel objects
Windows Internals: fuzzing, hijacking and weaponizing kernel objects
 
Black Box Testing
Black Box TestingBlack Box Testing
Black Box Testing
 
Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...
Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...
Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...
 
Effective Software Test Case Design Approach
Effective Software Test Case Design ApproachEffective Software Test Case Design Approach
Effective Software Test Case Design Approach
 
Test case development
Test case developmentTest case development
Test case development
 
3.software testing
3.software testing3.software testing
3.software testing
 
Combinatorial software test design beyond pairwise testing
Combinatorial software test design beyond pairwise testingCombinatorial software test design beyond pairwise testing
Combinatorial software test design beyond pairwise testing
 
Data validation option
Data validation optionData validation option
Data validation option
 
Using Modular Topologies in Kafka Streams to scale ksqlDB’s persistent querie...
Using Modular Topologies in Kafka Streams to scale ksqlDB’s persistent querie...Using Modular Topologies in Kafka Streams to scale ksqlDB’s persistent querie...
Using Modular Topologies in Kafka Streams to scale ksqlDB’s persistent querie...
 
Présentation Agile Testing
Présentation Agile TestingPrésentation Agile Testing
Présentation Agile Testing
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
 
Ship Faster, Reduce Risk, and Build Scale with Feature Flags
Ship Faster, Reduce Risk, and Build Scale with Feature FlagsShip Faster, Reduce Risk, and Build Scale with Feature Flags
Ship Faster, Reduce Risk, and Build Scale with Feature Flags
 
ReportPortal use cases presentation
 ReportPortal use cases presentation ReportPortal use cases presentation
ReportPortal use cases presentation
 
Dynamic dataflow on cgra
Dynamic dataflow on cgraDynamic dataflow on cgra
Dynamic dataflow on cgra
 
Testing concepts [3] - Software Testing Techniques (CIS640)
Testing concepts [3] - Software Testing Techniques (CIS640)Testing concepts [3] - Software Testing Techniques (CIS640)
Testing concepts [3] - Software Testing Techniques (CIS640)
 

Similar to Doveryai, no proveryai - Introduction to tla+

Interprocess Communication
Interprocess CommunicationInterprocess Communication
Interprocess Communication
Dilum Bandara
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.ppt
jayverma27
 
Os unit 3
Os unit 3Os unit 3
Os unit 3
Krupali Mistry
 
UNIT III Process Synchronization.docx
UNIT III Process Synchronization.docxUNIT III Process Synchronization.docx
UNIT III Process Synchronization.docx
karthikaparthasarath
 
OS Process synchronization Unit3 synchronization
OS Process synchronization Unit3  synchronizationOS Process synchronization Unit3  synchronization
OS Process synchronization Unit3 synchronization
subhamchy2005
 
Loops and iteration.docx
Loops and iteration.docxLoops and iteration.docx
Loops and iteration.docx
NkurikiyimanaGodefre
 
Python - Control Structures
Python - Control StructuresPython - Control Structures
Python - Control Structures
LasithNiro
 
Concurrent programming with RTOS
Concurrent programming with RTOSConcurrent programming with RTOS
Concurrent programming with RTOS
Sirin Software
 
Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3a
Ruth Marvin
 
02 - Prepcode
02 - Prepcode02 - Prepcode
02 - Prepcode
thewhiteafrican
 
Exception+Logging=Diagnostics 2011
Exception+Logging=Diagnostics 2011Exception+Logging=Diagnostics 2011
Exception+Logging=Diagnostics 2011
Paulo Gaspar
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
Ahmad Idrees
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationWayne Jones Jnr
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
DevaKumari Vijay
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templatesfarhan amjad
 
the halting_problem
the halting_problemthe halting_problem
the halting_problem
Rajendran
 
White boxvsblackbox
White boxvsblackboxWhite boxvsblackbox
White boxvsblackboxsanerjjd
 
lab-8 (1).pptx
lab-8 (1).pptxlab-8 (1).pptx
lab-8 (1).pptx
ShimoFcis
 

Similar to Doveryai, no proveryai - Introduction to tla+ (20)

Interprocess Communication
Interprocess CommunicationInterprocess Communication
Interprocess Communication
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.ppt
 
Os unit 3
Os unit 3Os unit 3
Os unit 3
 
UNIT III Process Synchronization.docx
UNIT III Process Synchronization.docxUNIT III Process Synchronization.docx
UNIT III Process Synchronization.docx
 
OS Process synchronization Unit3 synchronization
OS Process synchronization Unit3  synchronizationOS Process synchronization Unit3  synchronization
OS Process synchronization Unit3 synchronization
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Loops and iteration.docx
Loops and iteration.docxLoops and iteration.docx
Loops and iteration.docx
 
Python - Control Structures
Python - Control StructuresPython - Control Structures
Python - Control Structures
 
Concurrent programming with RTOS
Concurrent programming with RTOSConcurrent programming with RTOS
Concurrent programming with RTOS
 
Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3a
 
M C6java6
M C6java6M C6java6
M C6java6
 
02 - Prepcode
02 - Prepcode02 - Prepcode
02 - Prepcode
 
Exception+Logging=Diagnostics 2011
Exception+Logging=Diagnostics 2011Exception+Logging=Diagnostics 2011
Exception+Logging=Diagnostics 2011
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templates
 
the halting_problem
the halting_problemthe halting_problem
the halting_problem
 
White boxvsblackbox
White boxvsblackboxWhite boxvsblackbox
White boxvsblackbox
 
lab-8 (1).pptx
lab-8 (1).pptxlab-8 (1).pptx
lab-8 (1).pptx
 

More from Sandeep Joshi

Block ciphers
Block ciphersBlock ciphers
Block ciphers
Sandeep Joshi
 
Synthetic data generation
Synthetic data generationSynthetic data generation
Synthetic data generation
Sandeep Joshi
 
How to build a feedback loop in software
How to build a feedback loop in softwareHow to build a feedback loop in software
How to build a feedback loop in software
Sandeep Joshi
 
Programming workshop
Programming workshopProgramming workshop
Programming workshop
Sandeep Joshi
 
Hash function landscape
Hash function landscapeHash function landscape
Hash function landscape
Sandeep Joshi
 
Android malware presentation
Android malware presentationAndroid malware presentation
Android malware presentation
Sandeep Joshi
 
Apache spark undocumented extensions
Apache spark undocumented extensionsApache spark undocumented extensions
Apache spark undocumented extensions
Sandeep Joshi
 
Lockless
LocklessLockless
Lockless
Sandeep Joshi
 
Rate limiters in big data systems
Rate limiters in big data systemsRate limiters in big data systems
Rate limiters in big data systems
Sandeep Joshi
 
Virtualization overheads
Virtualization overheadsVirtualization overheads
Virtualization overheads
Sandeep Joshi
 
Data streaming algorithms
Data streaming algorithmsData streaming algorithms
Data streaming algorithms
Sandeep Joshi
 

More from Sandeep Joshi (11)

Block ciphers
Block ciphersBlock ciphers
Block ciphers
 
Synthetic data generation
Synthetic data generationSynthetic data generation
Synthetic data generation
 
How to build a feedback loop in software
How to build a feedback loop in softwareHow to build a feedback loop in software
How to build a feedback loop in software
 
Programming workshop
Programming workshopProgramming workshop
Programming workshop
 
Hash function landscape
Hash function landscapeHash function landscape
Hash function landscape
 
Android malware presentation
Android malware presentationAndroid malware presentation
Android malware presentation
 
Apache spark undocumented extensions
Apache spark undocumented extensionsApache spark undocumented extensions
Apache spark undocumented extensions
 
Lockless
LocklessLockless
Lockless
 
Rate limiters in big data systems
Rate limiters in big data systemsRate limiters in big data systems
Rate limiters in big data systems
 
Virtualization overheads
Virtualization overheadsVirtualization overheads
Virtualization overheads
 
Data streaming algorithms
Data streaming algorithmsData streaming algorithms
Data streaming algorithms
 

Recently uploaded

top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 

Recently uploaded (20)

top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 

Doveryai, no proveryai - Introduction to tla+

  • 1. Doveryai, no Proveryai Introduction to TLA+ Sandeep Joshi 11 Nov, 2017, Pune https://expert-talks.in 1
  • 2. Doveryai, no Proveryai A Russian proverb which means “Trust, but verify”. Popular during the Cold War when the US and Soviet Union were signing nuclear disarmament accords. 2
  • 3. Talk overview 1. Problem definition 2. What is TLA+, PlusCal, TLC... 3. Example 1 : Childcare facility 4. Example 2 : Dining Philosophers 5. Example 3 : Alternating Bit Protocol 6. Concluding observations Code : https://github.com/sanjosh/tlaplus Slides: https://www.slideshare.net/SandeepJoshi55/ 3
  • 4. Hard to prove correctness in a distributed system In a distributed system, how do you prove 1. Safety : Something bad will never happen 2. Liveness : Something good will eventually happen When you have 1. Multiple agents/actors, each with their state machine(FSM) 2. Non-determinism which leads to Arbitrary Interleaved execution 3. Failures and restarts 4
  • 5. Microsoft .NET remote authentication FSMs https://msdn.microsoft.com/en-us/library/ms973909.aspx Verify if this 2-process FSM (.NET) is correct.. ? 5
  • 6. Or this 2-process FSM (for TCP) is correct ? https://thewalnut.io/app/release/73/ 6
  • 7. CHESS : Systematic testing of concurrent programs http://slideplayer.com/slide/13582/ Interleaved execution causes ... 7
  • 8. How to reason about time in a distributed system Required : 1. A formal theory 2. A language to express the problem 3. A tool to verify 8
  • 9. How to reason about time in a distributed system Required : 1. A formal theory : Temporal Logic 2. A language to express the problem : TLA+ and others. 3. A tool to verify : TLC and other model checkers 9
  • 10. Temporal logic simplified In programs, we write formulae using Boolean operators (AND, OR, NOT). “Assert (a > 0 AND b < 0)” Temporal logic provides you with temporal operators which hold over one or more paths of execution (called “Path quantifiers”). 1. I will like chocolate from now on. 2. After weather becomes cold, at some point, I will start eating chocolate. https://en.wikipedia.org/wiki/Computation_tree_logic#Examples 10
  • 11. What is TLA+ ● Language created by Leslie Lamport to express temporal logic. ● PlusCal is a simpler variant of TLA+ (This talk uses PlusCal). ● TLC is the “model checker” - the compiler which verifies if your PlusCal program is correct. ● It has a GUI called Toolbox. In this talk, only command line tool is used. 11
  • 12. How to get started with TLA+ ● Read general background on model checkers ● Download the TLA toolbox (GUI + java jar file) ● Read the PlusCal manual and Lamport’s tutorial “Specifying systems” ● Read sample PlusCal programs written by others ● Start with a small problem and try writing your own program ● Run it... $ java pcal.trans myspec.tla $ java tlc2.TLC myspec.tla 12
  • 13. Childcare facility problem Children and adults continuously enter and exit a childcare facility. Ensure that there is always one adult present for every three children. [ from The Little Book of Semaphores by Allen Downey ] 13
  • 14. Childcare constraints Adult can enter anytime, but exit ONLY if 1. NEW number of adults is at least three times number of children Children can exit anytime, but enter ONLY if 1. Number of adults is at least three times NEW number of children 14
  • 15. Childcare - create child & parent process Define a PlusCal “process” for each actor in your system -- algorithm childcare { Process (a in 1.. ADULTS) {... } Process (c in 1..CHILDREN) {... } } 15
  • 16. Childcare - “labels” denote Atomic actions Use one PlusCal label for each atomic action of Child. Child performs two actions : enter and exit the childcare facility. Process { c_enter: number_children = number_children + 1 c_exit : number_children = number_children - 1 } 16
  • 17. What are PlusCal Labels All statements within a label are atomically executed by TLC. TLC internally interleaves the execution of many processes in order to verify correctness LabelA : Y = X + 1 Label1 : X = Y + 1 17 Label2 : X = Y - 1 Child 1 Adult 2
  • 18. Childcare - use “await” to wait for a condition Every Child will wait until there are sufficient number of adults present inside c_enter : Await (number_adults * 3 >= number_children + 1) number_children = number_children + 1 c_exit : number_children = number_children - 1 Assert (number_adults * 3 >= number_children) 18
  • 19. Childcare - specify adult process Follow same steps to define adult process - using process, label, await 19 Process { a_enter: number_adults = number_adults + 1 a_exit : Await ( number_adults * 3 >= number_children) number_adults = number_adults - 1 Assert (number_adults * 3 >= number_children) }
  • 20. TLC (model checker) Failure output At this point, assert fires since adult exited due to incorrect “await” condition 20
  • 21. Childcare - correct the condition Change the await condition to check new value instead of old 21 Process { a_enter: number_adults = number_adults + 1 a_exit : Await ((number_adults - 1)* 3 >= number_children) number_adults = number_adults - 1 }
  • 23. TLC (model checker) output on success 23
  • 24. Dining Philosophers Problem Each philosopher keeps doing the following 1. Think 2. Take right fork 3. Take left fork 4. Eat 5. Put down both forks 24
  • 25. Dining Philosophers with PlusCal Define five philosopher instances; Step through three labels (atomic actions) 25 Process (ph in 1..5) { Wait_first_fork : await (forks[right] = FALSE); forks[right] = TRUE; }
  • 26. Dining Philosophers with PlusCal Define five philosopher instances; Step through three labels (atomic actions) 26 Process (ph in 1..5) { Wait_first_fork : await (forks[right] = FALSE); forks[right] = TRUE; Wait_second_fork: await (forks[left] = FALSE); forks[left] = TRUE; }
  • 27. Dining Philosophers with PlusCal Define five philosopher instances; Step through three labels (atomic actions) 27 Process (ph in 1..5) { Wait_first_fork : await (forks[right] = FALSE); forks[right] = TRUE; Wait_second_fork: await (forks[left] = FALSE); forks[left] = TRUE; Done_eating : forks[left] = forks[right] = FALSE; }
  • 28. Dining Philosophers - complete spec 28
  • 29. Dining Philosophers - deadlock ! 29
  • 30. Dining Philosophers - deadlock ! All five philosophers are waiting for second fork ! 30
  • 31. Dining Philosophers - Introduce asymmetry To resolve deadlock, third philosopher will pick left fork first. 31 Process (ph in 1..5) { Init : if (self = 3) { swap(right, left); }; Wait_first_fork : await (forks[right] = FALSE); forks[right] = TRUE; Wait_second_fork: await (forks[left] = FALSE); forks[left] = TRUE; Done_eating : forks[left] = forks[right] = FALSE; }
  • 32. Dining Philosophers - complete spec 32
  • 33. Dining Philosophers - no deadlock ! 33
  • 34. Alternate bit protocol over lossy channel 34 Sender Receiver Message channel Ack channel Both channels are lossy https://en.wikipedia.org/wiki/Alternating_bit_protocol Discussed in Lamports’ book “Specifying Systems”.
  • 35. Alternate bit protocol - define channel Use “Sequences” module to define the communication channels Declare the channels as a Sequence Variables msgChan = <<>>, ackChan = <<>> Append to channel Append(msgChan, m) Extract using “Head(msgChan)” or “Tail(msgChan)” 35
  • 36. Alternate bit protocol - sender and receiver process Process (Sender = “S”) { Send message OR Receive Ack } 36 Define one Process each for Sender and Receiver Process (Receiver = “S”) { Receive message OR Send Ack }
  • 37. Alternate bit protocol - sender and receiver process Process (Sender = “S”) { Either { Append(<<input>>, msgChan) } or { Recv(ack, ackChan) } } 37 Define one Process each for Sender and Receiver Process (Receiver = “S”) { Either { Append(rbit, ackChan) } or { Recv(msg, msgChan) } }
  • 38. PlusCal - Either Or “Either Or” is an important feature of PlusCal language (TLA+) It allows you to simulate non-determinism TLC (model checker) will test both options at runtime. 38 Either { Do this } Or { Do that }
  • 39. Alternate Bit protocol - simulate lossy channel To simulate lossy channel, add another process which randomly deletes messages. 39 Process (LoseMsg = “L”) { randomly delete messages from either channel }
  • 40. Alternate Bit protocol - simulate lossy channel To simulate lossy channel, add another process which randomly deletes messages. 40 Process (LoseMsg = “L”) { While TRUE{ Either with (1 in 1..Len(msgChan)) { msgChan = Remove(i, msgChan) } or with (1 in 1..Len(ackChan)) { ackChan = Remove(i, ackChan); }
  • 41. PlusCal constructs introduced 1. Algorithm : A problem that you want to model. 2. Process : An actor/thread of execution within the algorithm. 3. Labels : All statements inside a label are atomically executed. 4. Await : only execute after condition becomes true 5. Either-Or : non-deterministic execution of alternatives 6. With : Non-deterministically choose one element out of a Set. 41
  • 42. Notable users of TLA+ 1. Intel CPU cache coherence protocol [Brannon Batson] 2. Microsoft CosmosDB 3. Amazon : S3, DynamoDB, EBS, Distributed Lock manager [Chris Newcombe] Newcombe(Amazon) has released two of their TLA+ specs (See my github for a copy) None of the others are publicly available 42
  • 43. Conclusion 1. TLC can find bugs. 2. Complex programs can take hours to run (TLC also has “simulation” mode which does random verification) Learning curve 1. Formulation : Lack of sample programs, but google group is helpful. 2. Debugging : Check the backtrace; add prints ! 3. Mastery over TLA+ requires some Mathematics knowledge (i.e. Set theory). 4. [Newcombe, Experience of Software Engineers using TLA+] http://tla2012.loria.fr/contributed/newcombe-slides.pdf 43
  • 44. Questions Code : https://github.com/sanjosh/tlaplus (README has references) Slides: https://www.slideshare.net/SandeepJoshi55/ 44
  • 45. TLA+ operators 1. <> P : atleast one execution path has P true 2. [] P : P is eventually true 3. Q ~> P : If Q becomes true, P will be true 4. <>[] P : at some point P becomes true and stays true 45
  • 46. Other model checkers besides TLA+ 46 https://en.wikipedia.org/wiki/List_of_model_checking_tools