Asymptotically Optimal Election on Weighted Rings

Asymptotically Optimal Election on Weighted Rings Lisa Higham1 University of Calgary Teresa Przytycka2 Odense University Abstract. In a network of ...
Author: Penelope Poole
0 downloads 0 Views 217KB Size
Asymptotically Optimal Election on Weighted Rings

Lisa Higham1 University of Calgary

Teresa Przytycka2 Odense University

Abstract. In a network of asynchronous processors, the cost to send a message can di er

signi cantly from one communication link to another. In such a setting, it is desirable to factor the cost of links into the cost of distributed computation. Assume that associated with each link is a positive weight representing the cost of sending one message along the link and the cost of an algorithm executed on a weighted network is the sum of the costs of all messages sent during its execution. We determine the asymptotic complexity of distributed leader election on a weighted unidirectional asynchronous ring assuming this notion of cost, by exhibiting a simple algorithm and a matching lower bound for the problem for any collection of edge weights. As a consequence, we see that algorithms designed for unweighted rings are not in general ecient for the weighted case. This research was carried out in part while visiting the University of Odense. The support of the Natural Sciences and Engineering Research Council of Canada is also acknowledged. Author's address: Computer Science Department, University of Calgary, Calgary, Alberta, T2N 1N4, Canada. email: 1

highamcpsc.ucalgary.ca

This research was carried out in part while visiting the University of Calgary. Author's address: Department of Mathematics and Computer Science, Odense University, DK-5230 Odense M, Denmark. email: 2

przytyckimada.ou.dk

2

1. Introduction Consider a network of asynchronous processors that communicate via message passing. The typical measure of the cost of a distributed algorithm on such a network is the number of messages sent. This measure assumes that the cost of sending a message along any link is equal to one. In practice, the cost of sending a message may depend upon the link that the message traverses. This motivates the study of distributed algorithms where the cost of transmitting a message over a link is factored into the communication complexity of the algorithm. Awerbuch, Baratz and Peleg [1] called this notion of communication complexity \cost sensitive analysis". A weighted network is a network of processors where each link e of the network has associated with it a positive weight w(e), which is the cost of sending a message along link e. The cost of a distributed algorithm for a given weighted network and input is the maximum, over all message delay patterns, of the sum of the costs of all message trac that occurs while executing the algorithm on that input. When designing a distributed algorithm for a weighted network we try to limit the message trac over heavy edges. In this paper, we study the weighted cost of leader election when the network topology is an asynchronous unidirectional weighted ring. The leader election problem is to design a distributed algorithm that distinguishes exactly one processor from among all the processors of the network as a unique processor called the leader. Leader election on asynchronous unweighted rings has been very well studied. Several early paper appeared before Peterson [8] and Dolev et.al.[2] independently solved the unidirectional version of the problem using O(n log n) messages. By the results of Pachl et.al.[7] these algorithms are asymptotically optimal. Some e ort has been made to reduce the constant [8, 2, 6] leading recently to the constant 1.271 [6]. Also, there has been substantial work generalizing and strengthing the lower bound for election on rings and other networks under a variety of assumptions about the model. See [5] for a list of research addressing algorithms and lower bounds related to the leader election problem. Running an algorithm designed for an unweighted network on a weighted network will, in general, not be cost ecient. Let W be the sum of the weights of all links of a weighted ring. Peterson's classical algorithm [8], when executed on the weighted ring will incur a cost of (W log n). In fact, all other known leader election algorithms have the same bound on complexity. The results of this paper show that this is not optimal. What is needed is a new technique for breaking the symmetry of the ring based on the weights of the edges. Such a technique is developed in this paper.

3

Let R be any ring with ni edges having weight in (2i?1; 2i]. We present an algorithm for the P leader election problem on unidirectional weighted rings that has cost O( n 1 ni 2i lg(ni + 1)) on R. We show that this algorithm is optimal in the following sense: Given a multiset W of weights where ni weight are in the interval (2i?1; 2i] and a leader election algorithm A, we can design a ring R with edge weights equal to the set W such that the weighted message cost of A on R is P

( n 1 ni 2i lg(ni + 1)). The matching lower bound of our cost sensitive analysis establishes that our algorithm is optimal in the \universal" sense of Garay, Kutten and Peleg [4] | that is, that the algorithm is optimal for any collection of weights. This universality ensures that the parameters that determine the complexity of election on a unidirectional weighted ring have been precisely identi ed. This is the rst lower bound that applies in this strong, universal sense, to cost sensitive analysis of any problem on any weighted network. i

i

Our algorithm for weighted rings is in some sense a generalization of the basic algorithm for the unweighted case [6]. The perspective of this algorithm facilitates an extension to the weighted case. However, the analysis in the weighted case requires completely di erent techniques. The new contribution of our lower bound is that it explicitly incorporates the weights into the result. The basic idea to achieve this bound is derived from the work of Pachl, Korach and Rotem [7]. However, we need to adjust the technique to overcome the complications introduced by weighted links. The optimal algorithm is presented in Section 2, its analysis in Section 3, and the lower bound in Section 4. 2. The leader election algorithm for weighted rings

2.1. Algorithm description. Although, in the literature, the leader election algorithms for un-

weighted rings are presented in a variety of ways, there is a high-level perspective that can be used to describe them all (see [5]). Initially each processor creates an envelope containing a label set to its own identi er, a round number (or sometimes a round parity bit), and possibly additional information and forwards the envelope to its neighbour. Upon receipt of an envelope, a processor applies a casualty test, which compares the contents of the envelope with the processor's stored information, to determine whether or not to destroy the envelope. If the receiving processor determines not to destroy the envelope, it applies a promotion test, to determine whether or not to increment the round number. It then updates the content of the envelope and its own information as required and forwards the envelope to its neighbour. Eventually only one envelope remains and a leader is elected. The various algorithms di er in four ways: the content of an envelope in addition

4

to label and round number, the local information stored by each processor, the speci cation of the casualty test, and the speci cation of the promotion test. In both the basic algorithm [6] which we refer to as the min-max algorithm, and our algorithm for weighted rings, called weighted elect, the label of an envelope is never changed. In min-max, each envelope contains only its label and a round number initialized to 1. Each processor stores the label and the round of the last envelope it sent. The casualty test is simply: the envelope and the receiving processor have the same round number and this round number is odd (respectively, even) and the label of the envelope is larger (respectively, smaller) than that stored by the processor. The promotion test is simply: the envelope and the receiving processor have the same round number. One way to visualize min-max is to imagine that execution proceeds in rounds. In an odd round any envelope that directly follows an envelope with label smaller than it's own label is destroyed while in an even round any envelope that directly follows an envelope with a larger label is destroyed. Notice that in min-max, as well as in other election algorithms for unweighted rings, in every round (or sometimes in every second round) messages trac covers every link of the ring. One central idea in weighted elect is to accelerate processing of envelopes that have travelled a large weighted distance by promoting them to a higher round as soon as they incur a sucient weighted cost. Algorithm weighted elect can be thought of as combining min-max with this idea of \early promotion by weighted distance". We will see that by using early promotion, message trac does not necessarily cover every link in each round, thus reducing the weighted distance an envelope travels before the algorithm terminates. For algorithm weighted elect, in addition to the label, each envelope contains a round and a credit. Both are initialized as a function of the weight of the link adjacent to the processor that creates the envelope. The initial credit is proportional to this weight and the initial round number is the logarithm of this weight. The label of an envelope remains unchanged as long as the envelope survives, whereas, the round and credit are adjusted during the course of the algorithm. Throughout the algorithm, each processor stores the label and the round of the last envelope that it sent. The casualty test for weighted elect is: the round number of the received envelope is less than that of the last envelope sent, or the casualty test of min-max holds. If an envelope is not destroyed then it may be promoted, resulting in an increased credit and a larger round. The promotion test for weighted elect is: the credit is less than the weight of the outgoing edge or the promotion test of min-max holds. For any surviving envelope (whether promoted or not) the processor reduces its credit by the weight of its adjacent edge before sending the envelope forward.

5

The complete protocol for weighted elect is given in Figure 1. The protocol for each processor is parameterized by its identi er (proc-id) and the weight of its outgoing edge (adj wt). Four consecutive rounds of weighted elect are grouped together to form a phase; hence round r is represented by an ordered pair (p; t) where p is the phase number, t 2 f0; 1; 2; 3g and r = 4  p + t. The pseudo code assumes the following three tests that are employed when an envelope containing label id, and round (p,t) and credit cnt arrives at a processor that has recorded a label fwd id and a round (fwd p,fwd t) and has an outgoing edge with weight adj wt.

Casualty-test:

(p < fwd p) or ((p ,t) = (fwd p ,fwd t) and t 2 f1; 3g and id > fwd id) or ((p ,t) = (fwd p,fwd t) and t 2 f0; 2g and id < fwd id)

Promotion-test:

((p ,t) = (fwd p ,fwd t) and t 2 f1; 3g and id < fwd id) or ((p ,t) = (fwd p ,fwd t) and t 2 f0; 2g and id > fwd id) or (p > fwd p and cnt < adj wt) . Leader-test: id = fwd id.

2.2. Correctness of weighted elect. Correctness of weighted elect follows immediately af-

ter establishing:

safety: the algorithm never deletes all message envelopes, progress: if there is more than one envelope then after a nite number of messages the number of envelopes is reduced, and correct termination: the algorithm elects a leader exactly when one envelope remains.

Because the ring is unidirectional and the algorithm is deterministic and message-driven with messages processed in rst-in- rst-out order, the messages received by each processor and the order in which each processor processes its messages is entirely determined by the initial con guration of identi ers and edge weights. Thus the scheduler is powerless to in uence the outcome of the computation. We emphasize that for message-driven algorithms on unidirectional rings, correctness and complexity under any xed scheduler implies correctness and complexity under all schedulers. Thus without loss of generality we assume a scheduler that proceeds by the round number of the envelopes. That is, an envelope with a given round number is not delivered until there does not exist an envelope of smaller round number. (This round-driven scheduler exists because weighted elect

6

Processor(proc-id, adj wt): id ?proc-id ; p ?dlg adj wte ; t ?0 ; cnt ?2p ; fwd id ? ?1 ; fwd p ? ?1 ; fwd t ? 0 ; +1

repeat if not Casualty-test then if Promotion-test then t ?(t+1) mod 4 ; if t= 0 then p ?p+1 ; cnt ?2p+t+1 ; fwd id ?id ; fwd p ?p ; fwd t ?t ; send(id, p, t, cnt ? adj wt) ; receive(id, p, t, cnt) ; until Leader-test . Figure 1. Algorithm weighted elect

ensures that the round number of an envelope never decreases and the casualty test guarantees that the sequence of envelopes travelling any edge have non-decreasing round number.) Suppose, contrary to safety, that some execution of weighted elect removes all envelopes under the round-driven scheduler and let (p; t) be the maximum round achieved. Suppose t is odd, and let S be the set of identi ers in envelopes that achieve round (p; t). According to Casualtytest, an envelope in round (p; t) with identi er i can only be destroyed by meeting a processor that either (1) last forwarded an envelope with round larger than (p; t), or (2) last forwarded an envelope with round equal to (p; t) and identi er less than i. Since (p; t) is the maximum round, case (1) is impossible. Furthermore, in case (2), the envelope in S with minimum identi er cannot be destroyed. so the envelope will be eventually promoted and its round increases contradicting that (p; t) was the maximum round. A symmetric argument applies if t is even. Suppose contrary to progress, that after some point, k  2 envelopes remain alive under the round-driven scheduler. Then eventually, say in round (p; t), each of these envelopes will receive a credit at least as large as the weight of the ring. At this point each envelope has a large enough credit to allow it to travel to the processor that promoted the envelope that precedes it. Since, all

7

undestroyed envelopes have the same round number, if t is odd (respectively, even) the envelope with maximum label (respectively, minimum label) must be destroyed. contradicting that no more envelopes are destroyed. The algorithm cannot prematurely elect a leader because a processor will receive an envelope with id equal to its fwd id if and only if there are no other envelopes, thus passing the Leader-test and con rming correct termination. 3. Message complexity of weighted elect We rst introduce some de nitions and notation. The pth phase consists of all the message trac of envelopes with round (p; t) for t 2 f0; 1; 2; 3g. Since algorithm weighted elect never changes the label of an envelope for the duration of its existence, we use envelope a as an abbreviation for the envelope with label a. For an envelope a in phase p, let hostp (a) denote the processor that promoted the envelope to phase p (that is, from round (p ? 1; 3) to round (p; 0)), or the processor that created the envelope if it is initialized with phase p. The weighted distance from processor x to processor y, denoted (x, y), is the sum of the weights of all links between processor x and processor y , travelling in the direction of the ring. As discussed in Section 2, the scheduler cannot in uence the communication complexity in a message passing unidirectional ring. Therefore, for simplicity, assume as before the round-driven scheduler, which delivers all envelopes in order of increasing round number. Under this scheduler, all undestroyed envelopes either participate in the round, say (p; t), or just exist in round (p; t) because they have been created with round number (q; 0) where q > p but have not yet been delivered across any link. Envelope b is the immediate predecessor in phase p of envelope a if, when all participating envelopes are in round (p; 0) and all existing envelopes are in phase p or greater, the rst envelope encountered after envelope a travelling in the direction of the ring, is envelope b. Let envelope b be the immediate predecessor of envelope a in phase p and suppose b is in phase q  p. Then the horizon of envelope a in phase p is (hostp (a), hostq (b)). Let ni be the number of links with weight in (2i?1; 2i] in an asynchronous ring with distinct identi ers. Let dp denote the number of envelopes that participate in phase p. An envelope that participates in phase p is sparse in phase p if its horizon is greater than 2p, otherwise it is dense. Let sp denote the number of envelopes that are sparse in phase p. Let J denote the number of phases until there are at most 3 remaining envelopes when weighted elect is run on the ring. Notice that after J phases, there can be at most 3 more passes of message trac on the ring, so it

8

suces to bound the weighted message complexity for the rst J phases. The next three lemmas allow us to bound the number of sparse envelopes and the total number of envelopes participating in each phase as a function of the weights on the ring.

Lemma 3.1. The number sp of sparse envelopes that participate in phase p satis es sp  Ppi ni2i?p. =0

Proof: The result follows immediately from the de nition of sp. We expect each pair of successive rounds in a phase to reduce the number of dense envelopes by at least one half. This is because in the rst round any envelope meeting a processor in the same round with fwd id smaller than its own id is eliminated, and in the next round any envelope meeting a processor in the same round with fwd id larger than its own is eliminated. This is made precise in the next lemma.

Lemma 3.2. For p < J the number dp of envelopes that participate in phase p satis es the recur-

rence:

d =n ; 0

0

dp  dp ?4 sp + np + sp p  0 +1

+1

Proof: The proof relies on the following observation: Fact 3.3. Let x be an envelope that exits in phase p +1. Assume that at the beginning of phase p, x is immediately followed by k dense envelopes. Then the minfk; 3g dense envelopes that immediately follow x do not survive to phase p + 1. The fact holds because consecutive dense envelopes have enough credit to reach the host of the next envelope with the same round number. By applying the min-max comparison for four consecutive rounds it is easily checked that if x survives for four rounds, the minfk; 3g dense envelopes that follow x must be eliminated.

Consider a maximal chain of dense envelopes in round (p; 0). Suppose there is a non-dense envelope s (a sparse envelope or an envelope with higher phase) that immediately precedes the leading dense envelope of this chain. If y is a dense envelope in this chain that survives to phase p + 1 and is followed by at least 3 dense envelopes then, by fact 3.3, we can attribute 3 eliminated envelopes to y . Suppose y is followed by fewer than 3 dense envelopes. If s exists in phase p + 1 then we attribute to y the 3 eliminated envelopes that, by fact 3.3, follow s at the beginning of phase p. If s does not survive to phase p + 1 then in our count of surviving envelopes we can count y as eliminated instead of s.

9

If there is no such s then all exiting envelopes are dense and participating, and the result again follows immediately from fact 3.3 as long as dp  4. Otherwise dp  3 and hence p  J . In all cases at most (dp ? sp )=4 + sp phase p envelopes survive to phase p + 1. In addition, there are np+1 new envelopes that begin in phase p + 1.

Lemma 3.4. The number dp of envelopes that participate in phase p for p  J satis es dp