Lecture 34: Thread Pools & Futures; Intro to Consensus
COSC 273: Parallel and Distributed Computing
Spring 2023
Annoucements
- Leaderboard Submissions Tonight
- Take-home Quiz Wednesday-Friday on Sorting Networks
Executor Services
From Java API an ExecutorService
is
[a]n Executor that provides methods to manage termination and methods that can produce a Future for tracking progress of one or more asynchronous tasks.
What Can ExecutorService
s Do?
-
submit
tasks
- a task is
Callable<T>
or Runnable
instance
- a
Future<T>
is returned
-
invoke
a Collection
of tasks
- a
List
of Future<T>
s is returned
Callable<T>
is an interface
- implement
call()
method
-
call()
returns a T
What is a Future
?
Represents the result of a submitted task:
- waits until task is complete before giving return value
- stores return value when task is complete
Example.
ExecuterService pool = Executors.newFixedThreadPool(...);
Future<String> result = pool.submit(someTask);
System.out.println("result: " + result.get());
Activity
- Download
lec34-futures.zip
and run the program
- Understand what happens and why
- Modify the program so that:
- completed tasks print in order submitted
- printing can before all tasks complete
Motivation I: Mission Critical Components
Suppose you’re designing an airplane
- Need computers to control everything
- sensors for speed, thrust, flap positions, pitch, roll, yaw
- must adjust constantly to fly
- But computers occasionally (regularly) crash/need restart
How to design around this issue?
Fault-Tolerance through Duplication?
Have multiple duplicate, independent systems
- systems run in parallel
- highly unlikely both crash simultaneously
- restarts are infrequent
- restarting one system won’t affect other system
The end of our worries?
Trouble Ahead
Suppose all systems working normally, but
- system 1 says increase thrust
- system 2 says decrease thrust
- system 3 not responding (restart?)
What do we do?
Motivation II: Electronic Currency
Context. Decentralized electronic currency
- money represented as digital tokens
- unlike physical coins, digital tokens are easily duplicated
Question. If money can be duplicated, how can it hold value? How can one “spend” their money?
-
holding (storing) a token is not ownership
- ownership is determined by history of transactions
- transactions stored as a (distributed) ledger
Problem: Double-Spending
Issue. Customer spends same digital token twice
- Customer submits transaction giving coin $A$ to vendor $V$
- Customer submits another transaction giving coin $A$ to vendor $W$
Question. How does the network decide which (if any) transaction is valid?
The Problem of Consensus
Have multiple processes with different views/inputs
- For us, binary inputs
-
0
= decrease thrust; accept transaction 0
-
1
= increase thrust; accept transaction 1
Goal:
- all processes agree on same output
Conditions for Consensus
-
Agreement: all processes output the same value
-
Validity: if all systems have the same input, they all output that value
-
Termination: all (non-faulty) processes decide on an output and terminate after a finite number of steps
Exercise
Devise an algorithm for consensus assuming:
- Extremely fair scheduler: all processes take a step before anyone takes a next step
- execution in synchronous rounds
- No faulty processes
- Access to shared array of size $n$
Consensus with Faults
Suppose some process(es) may crash at any time during an execution…
- Other processes can’t tell that a process crashes
- e.g., cannot distinguish slow process from crashed
Not Consensus 1
How can we achieve…
Agreement: all processes output the same value
-
Validity: if all systems have the same input, they all output that value
-
Termination: all (non-faulty) processes decide on an output and terminate after a finite number of steps
Not Consensus 2
How can we achieve…
-
Agreement: all processes output the same value
Validity: if all systems have the same input, they all output that value
-
Termination: all (non-faulty) processes decide on an output and terminate after a finite number of steps
Not Consensus 3
How can we achieve…
-
Agreement: all processes output the same value
-
Validity: if all systems have the same input, they all output that value
Termination: all (non-faulty) processes decide on an output and terminate after a finite number of steps
So
Without too much trouble, we can achieve…
- …consensus with synchronous rounds, no faults
- …“consensus” without agreement
- …“consensus” without validity
- …“consensus” without termination
What about consensus with faults?
Our Plan
Prove version of FLP result:
- There is no wait-free protocol for consensus with read/write registers for any $n > 1$
- wait-free is stronger assumption than termination
Next Time.
- Specify computational model
- Make preliminary observations
- Outline argument