Wait-Free Consensus
Total Page:16
File Type:pdf, Size:1020Kb
WaitFree Consensus James Aspnes July CMUCS Scho ol of Computer Science Carnegie Mellon University Pittsburgh PA Submitted in partial fulllmen t of the requirements for the degree of Do ctor of Philosophy c James Aspnes This researc h was supp orted by an IBM Graduate Fellowship and an NSF Graduate Fellowship Keywords distributed algorithms shared memory consensus random walks martingales shared coins Abstract Consensus is a decision problem in which n pro cessors each starting with a value not known to the others must collectively agree on a single value If the initial values are equal the pro cessors must agree on that common value this is the validity condition A consensus proto col is waitfree if every pro ces sor nishes in a nite numb er of its own steps regardless of the relative sp eeds of the other pro cessors a condition that precludes the use of traditional syn chronization techniques such as critical sections lo cking or leader election Waitfree consensus is fundamental to synchronization without mutual ex clusion as it can b e used to construct waitfree implementations of arbitrary concurrent data structures It is known that no deterministic algorithm for waitfree consensus is p ossible although many randomized algorithms have b een prop osed I present two algorithms for solving the waitfree consensus problem in the standard asynchronous sharedmemory model The rst is a very simple proto col based on a random walk The second is a proto col based on weighted 2 voting in which each pro cessor executes O n log n exp ected op erations This b ound is close to the trivial lower b ound of n and it substantially 2 improves on the b est previouslyknown b ound of O n log n due to Bracha and Rachman Acknowledgments I would like to b egin by thanking the memb ers of my committee My advisor Steven Rudich has always b een willing to provide encouragement Danny Sleator showed me that research is b etter done as play than as work Merrick Furst has always b een a source of interesting observations and ideas Maurice Herlihy intro duced me to waitfree consensus when I rst arrived at Carnegie Mellon his keen insights into distributed computing have b een a continuing inuence on my work I would like to thank my parents for their warm supp ort and encourage ment I would like to thank the many other students who lightened the monastic burdens of graduate student life David Applegate in particular was always ready to supply a new problem or a new toy Finally I would like to thank my b eloved wife Nan Ellman who waited longer and more patiently for me to nish than anyone i Contents Intro duction The Asynchronous SharedMemory Mo del Basic elements Time and asynchrony Randomization Relation to other models Performance measures Consensus and Shared Coins Consensus Shared coins Consensus using shared coins Consensus Using a Random Walk Random walks The robust shared coin proto col Implementing a b ounded counter with atomic registers The randomized consensus proto col Consensus Using Weighted Voting Intro duction The shared coin proto col Martingales Knowledge algebras and measurability Denition of a martingale Gambling systems ii Limit theorems Pro of of correctness Phases of the proto col Common votes Extra votes Written votes vs decided votes Choice of parameters Conclusions and Op en Problems Comparison with other proto cols Limits to waitfree consensus Op en problems iii List of Figures Consensus from a shared coin Robust shared coin proto col Pictorial representation of robust shared coin proto col The proto col as a controlled random walk Pseudo co de for counter op erations Consensus proto col Counter scan for randomized consensus proto col Shared coin proto col iv List of Tables Comparison of consensus proto cols v Chapter Intro duction Consensus CIL is a to ol for allowing a group of pro cessors to collectively cho ose one value from a set of alternatives It is dened as a decision problem in which n pro cessors each starting with a value or not known to the others must collectively agree on a single value The restriction to a single bit do es not prevent the pro cessors from cho osing b etween more than two p ossibilities since they can run just run a onebit consensus proto col multiple times The pro cessors communicate by reading from and writing to a collection of registers each pro cessor nishes the proto col by deciding on a value and halting A consensus proto col is waitfree if each pro cessor makes its decision after a nite numb er of its own steps regardless of the relative sp eeds or halting failures of the other pro cessors In addition a consensus proto col must satisfy the validity condition if every pro cessor starts with the same input value every pro cessor decides on that value This condition excludes trivial proto cols such as one where every pro cessor always decides The asynchronous sharedmemory model is an attempt to capture the eect of making the weakest p ossible assumptions ab out the timing of events in a distributed system At each moment an adversary scheduler cho oses one of the n pro cessors to run No guarantees are made ab out the schedulers choices it may start and stop pro cessors at will based on a total knowledge of the state of the system including the contents of the registers the pro gramming of the pro cessors and even the internal states of the pro cessors Since the scheduler can always simulate a halting failure by cho osing not to run a pro cessor the mo del eectively allows up to n halting failures The adversarys p ower however is not unlimited It cannot cause the pro cessors to deviate from their programming or cause op erations on the registers to fail or return incorrect values Combined with the requirement that a consensus proto col terminate af ter a nite numb er of op erations the adversarys p ower precludes the use of traditional synchronization techniques such as critical sections lo cking or leader election any pro cessor that obtains a critical resource can b e killed and as so on as any pro cessor or group of pro cessors is given control over the outcome of the proto col the scheduler can put them to sleep and leave the other pro cessors helpless to complete the proto col on their own In general any proto col dep ending on mutual exclusion where one pro cessors p os session of a resource or role dep ends on other pro cessors b eing excluded from it will not b e waitfree Waitfree consensus is fundamental to synchronization without mutual exclusion and thus lies at the heart of the more general problem of con structing highly concurrent data structures Her It can b e used to obtain waitfree implementations of arbitrary abstract data typ es with atomic op er ations Her Plo It is also complete for distributed decision tasks CM in the sense that it can b e used to solve all such decision tasks that have a waitfree solution Intuitively the pro cessors can individually simulate a sequence of op erations on an ob ject or the computation of a decision value and use consensus proto cols to cho ose among the p ossibly distinct outcomes Conversely if consensus is not p ossible it is also impossible to construct waitfree implementations for many simple abstract data typ es including queues testandset bits or compareandswap registers as there exist sim ple deterministic consensus proto cols for b ounded numb ers of pro cessors using these primitives Her Alas given the p owerful adversary of the asynchronous sharedmemory model it is not p ossible to have a deterministic waitfree consensus proto col one in which the b ehavior of the pro cessors is predictable in advance In fact in a wide variety of asynchronous models it has b een shown there is no deterministic consensus proto col that works against a scheduler that can stop even a single pro cessor CIL DDS FLP Her LAA TM Though this result is usually proved using more general techniques when only singlewriter registers are used it has a simple pro of that illustrates many of the problems that arise when trying to solve waitfree consensus Imagine that two pro cessors A and B are trying to solve the consensus problem Their situation is very much like the situation of two p eople facing each other in a narrow hallway neither p erson has any stake in whether they pass on the left or the right but if one go es left and the other right they will bump into each other and make no progress When A and B are deterministic pro cessors under the control of a malicious adversary scheduler we can show the scheduler will b e able to use its knowledge of their state and its control over the timing of events to keep A and B oscillating back and forth forever b etween the two p ossible decision values Here is what happ ens Since each pro cessor is deterministic