1: \section{Waiting time and average waiting time of algorithm $\bm{\cal A}$}
2: Algorithm $\cal A$ is designed with the notion of {\em token}. Recall that a
3: node can enter its critical section only if it has the token. However, unlike
4: the concept of a token circulating continuously in the system, it is sent
5: from one node to another if and only if a request is made for it.
6: The token thus circulates strictly according
7: to the order in which the requests have been made. The queue is updated by
8: each node after executing its own critical section. The queue of requesting
9: processes is maintained at the node containing
10: the token and is transferred along with the token whenever the token is
11: transferred. The requesting nodes receive the token strictly according to the
12: order in the queue.
13:
14: In order to simplify the analysis, the following is assumed.
15: \begin{itemize}
16: \item When a node is not in the critical section or is not already in the waiting
17: queue, it generates a request for the token at Poisson rate $\lambda$,
18: {\em i.e.} {\sl the arrival process is a Poisson process}.
19: \item Each node spends a constant time ($\sigma$ time units) in the critical
20: section, {\em i.e.} {\sl the rate of service is} $\mu = 1/\sigma$. Suppose we
21: would not assume a constant time spent by each process in the critical
22: section. $\sigma$ could then be regarded as the maximum time spent in the
23: critical section, since any node executes its critical section within a
24: finite time.
25: \item
26: The time for any message to travel from one node to any other node in the
27: complete network is {\sl constant} and is equal to $\delta$ (communication
28: delay). Since the message delay is finite, we assume here that every message
29: originated at any node is delivered to its destination in a {\sl bounded}
30: amount of time: in words, the network is assumed to be {\sl synchronous}
31: \end{itemize}
32: At any instant of time, a node has to be in one of the following two states:
33: \begin{enumerate}
34: \item {\sl Critical state.}
35:
36: The node is waiting in the queue for the token or is
37: executing its critical section. In this state, it cannot generate any request
38: for the token, and thus the rate of generation of request for entering the
39: critical section by this node is zero.
40: \item
41: {\sl Noncritical state.}
42:
43: The node is not waiting for the token and is not
44: executing the critical section. In this state, this node generates a request
45: for the token at Poisson rate $\lambda$.
46: \end{enumerate}
47:
48: \subsection{Waiting time of algorithm $\bm{\cal A}$}
49: Let ${\cal S}_{k}$ denote the system state when exactly $k$ nodes are in the
50: waiting queue, including the one in the critical section, and let $P_{k}$
51: denote the probability that the system is in state ${\cal S}_{k}$, $0 \leq k
52: \leq n$.
53: In this state, only the remaining $n - k$ nodes can generate a request. Thus,
54: the net rate of request generation in such a situation is $(n - k) \lambda$.
55: Now the service rate is constant at $\mu$ as long as $k$ is positive,
56: {\em i.e.} as
57: long as at least one node is there to execute its critical section and the
58: service rate is $0$ when $k = 0$. The probability that during the time period
59: $(t,t+h)$ more than one change of state occur at any node is $o(h)$.
60: By using a simple birth-and-death process (see Feller, \cite{fe}), the
61: following theorem is obtained.
62:
63: \begin{theorem}
64: When there are $k$ $(k > 0)$ nodes in the queue, the waiting time of a node
65: for the token is $w_{k} \:= \: (k - 1)(\sigma + \delta) \;+\; \sigma/2,$
66: where $\sigma$ denotes the time to execute the critical section and
67: $\delta$ the communication delay. \\
68: The worst-case waiting time is $w_{worst} \:\leq \: (n - 1)(\sigma + \delta) %
69: \;+\; \sigma/2 \;=\: O(n)$. \\
70: The exact expected waiting time of the algorithm is
71: $$\overline{w} \:=\: (\sigma + \delta) (\overline{n} - n P_{n}) \;-\;
72: (\delta + \sigma/2)(1 - P_{0} - P_{n}) \;+\; 2\delta P_{0},$$
73: where $\overline{n}$ denotes the average number of nodes in the queue and the
74: critical section.
75: \end{theorem}
76: \begin{proof}
77: Following equations hold,
78: \begin{eqnarray}
79: P_{0}(t + h) & = & P_{0}(t) (1 - n{\lambda}h) \;+\; P_{1}(t) %
80: \Big(1 \:-\: (n - 1){\lambda}h\Big) {\mu}h \;+\; o(h) \nonumber \\
81: \frac{1}{h} \Big(P_{0}(t + h) - P_{0}(t)\Big) & = & - \,n{\lambda} P_{0}(t) %
82: \;+\; {\mu} P_{1}(t) \;-\; (n - 1){\lambda}{\mu}h P_{1}(t).
83: \end{eqnarray}
84:
85: Under steady state equilibrium, $P_{0}'(t) = 0$ and hence,
86: \begin{equation}
87: \mu P_{1}(t) \; - \; n{\lambda} P_{0}(t) \: = \: 0, \; \; \mbox{and} \;
88: P_{1}(t) \; = \; n (\lambda/\mu) P_{0}(t).
89: \end{equation}
90:
91: Similarly, for any $k$ such that $1 \leq k \leq n$, one can write
92: \begin{eqnarray*}
93: P_{k}(t + h) & = & P_{k}(t) \Big(1 \:-\: (n - k){\lambda}h\Big) (1 - {\mu}h) \\
94: & & +\ P_{k-1}(t) \Big((n - k + 1){\lambda}h\Big) (1 - {\mu}h) \\
95: & & +\ P_{k+1}(t) \Big(1 \:-\: (n - k - 1){\lambda}h\Big) ({\mu}h) \;+\; o(h),
96: \end{eqnarray*}
97: and
98: $$\frac{1}{h} \left(P_{k}(t + h) \:-\: P_{k}(t) \right) \; = \; %
99: - (n - k){\lambda} P_{k}(t) \;+\; (n - k + 1){\lambda} P_{k-1}(t) %
100: \;+\; {\mu} P_{k+1}(t) \;-\;{\mu} P_{k}(t).$$
101: \par
102: Classically, set $\rho = \lambda/\mu$. Proceeding similarly, since under
103: steady state equilibrium $P_{k}'(t) = 0$,
104: \begin{equation}
105: P_{k+1}(t) \:=\; \left(1 + (n - k){\rho}\right) P_{k}(t) \:-\: (n - k + 1){\rho},
106: \end{equation}
107: and, for any $k$ ($1 \leq k \leq n$),
108: \begin{equation} \label{eq:pkdet}
109: P_{k}(t) \:=\; \frac{n!}{(n - k)!}\: \rho^{k} P_{0}(t) \;=\;
110: n^{\underline{k}} \rho^{k} P_{0}(t).
111: \end{equation}
112:
113: For notational brevity, let $P_{k}$ denote $P_{k}(t)$. By Eq.~\ref{eq:pkdet},
114: we can now compute the average number of nodes in the queue and the critical
115: section under the form
116: $$\overline{n} \: = \: \sum_{k=0}^{n} k P_{k} \: = \: P_{0} \sum_{k=0}^{n} k
117: n^{\underline{k}} \rho^{k},$$
118: since the system will always be in one of the $(n + 1)$ states
119: ${\cal S}_{0}, \ldots ,{\cal S}_{n}$, $\sum_{k} P_{k} = 1$.
120:
121: Now using expressions of $P_{k}$ in terms of $P_{0}$ yields
122: $$\sum_{k=0}^{n} P_{k} \;=\; P_{0} \sum_{k=0}^{n} n^{\underline{k}} \rho^{k} \:=\: 1.$$
123: Thus,
124: \begin{equation}
125: P_{0} \:=\; \left(\sum_{k=0}^{n} n^{\underline{k}} \rho^{k} \right)^{-1}\ \quad %
126: \mbox{and}\ \quad P_{i} \:=\; \frac{n^{\underline{i}} \rho^{i}}{\left(\sum_{k=0}^{n} %
127: n^{\underline{k}}\rho^{k}\right)}.
128: \end{equation}
129:
130: Let there be $k$ nodes in the system when a node $i$ generates a request.
131: Then $(k - 1)$ nodes execute their critical section, and one node executes
132: the remaining part of its critical section before $i$ gets the token. Thus,
133: when there are $k$ $(k > 0)$ nodes in the queue, the waiting time of a node
134: for the token is
135: \begin{center}
136: $w_{k} \:=\: (k - 1)$\ ({\sl time\ to\ execute\ the\ critical\ section}\
137: {\sl communication\ delay}\ $+$\ \\
138: $+$\ {\sl average\ remaining\ execution\ time}), or
139: \end{center}
140: \begin{equation}
141: w_{k} \:=\: (k - 1 ) (\sigma + \delta) \; + \; \sigma/2
142: \end{equation}
143: (where $\sigma$ denotes the time to execute the critical section and $\delta$
144: the communication delay).
145:
146: When there are zero node in the queue, the waiting time is $w_{0} = 2\delta =$\
147: {\sl total communication delay of one request and one token message}.
148: Hence the expected waiting time is
149: \begin{eqnarray*}
150: \E(w) & = & \overline{w} \:=\; \sum_{k=0}^{n-1} w_{k} P_{k} \;=\; %
151: 2\delta P_{0} \;+\; \sum_{k=1}^{n-1} \left\{(k - 1)(\sigma + \delta) %
152: \;+\; \frac{\sigma}{2}\right\} P_{k}, \\
153: & = & (\sigma + \delta) \sum_{k=1}^{n-1} k P_{k} \;-\; (\sigma + \delta) %
154: \sum_{k=1}^{n-1} P_{k} \;+\; \sigma/2 \sum_{k=1}^{n-1} P_{k} \;+\; 2\delta P_{0},
155: \end{eqnarray*}
156: and
157: \begin{equation}
158: \overline{w} \:=\; (\sigma + \delta) (\overline{n} - n P_{n}) \;-\; %
159: (\delta + \sigma/2) (1 - P_{0} - P_{n}) \;+\; 2\delta P_{0}.
160: \end{equation}
161: \par
162: By Eq. (9), we know the exact value of the expected waiting time of a node
163: for the token in algorithm $\cal A$. Moreover, by Eq. (8), the worst-case
164: waiting time is $w_{worst} \:\leq \; (n-1)(\sigma + \delta) \;+\; \sigma/2 \;=\; O(n).$
165: \end{proof}
166:
167: \subsection{Average waiting time of algorithm $\bm{\cal A}$}
168: The above computation of $\overline{w}$ yields the asymptotic form of an
169: upper bound on the average waiting time $\overline{w}$ of $\cal A$.
170: \begin{theorem}
171: If $\rho < 1$, the average waiting time of a node for the token in $\cal A$
172: is asymptotically (when $n \rightarrow +\infty$),
173: $$\overline{w} \:\leq \: (\sigma + \delta) \left(n (1 - 2e^{-1/\rho}) \right) \;-\; %
174: (\delta + \sigma/2) (1 - e^{-1/\rho}) \;+\; O\left((\sigma/2 + 3\delta) e^{-1/\rho} %
175: \: \frac{\rho^{-n}}{n!}\right).$$
176: \end{theorem}
177: \begin{proof}
178: Assume $\rho = \lambda/\mu < 1$, when $n$ is large we can bound
179: $\overline{w}$ from above in Eq.~(9) as follows,
180:
181: First, $1 \:-\: P_{0} \:-\: P_{n} \;=\; 1 \:-\: P_{0} \:-\: n!\rho^{n} P_{0}$,
182: where $P_{0} =\; \left(\sum_{i=0}^{n} n^{\underline{i}} \rho^{i} \right)^{-1}$.
183: \par
184: \noindent
185: Since $\rho < 1$,
186: $$P_{0} \:\leq \: \left(n! \rho^{n} e^{1/\rho} \right)^{-1},$$
187: and, for large $n$,
188: \begin{equation}
189: 1 \:-\: P_{0} \:-\: P_{n} \;\leq \; 1 \:-\: \frac{1 + n! \rho^{n}}{n! \rho^{n} e^{1/\rho}} %
190: \:\leq \: 1 \;-\; \frac{1}{n! \rho^{n} e^{1/\rho}} \:-\: e^{\textstyle -1/\rho}.
191: \end{equation}
192:
193: Next,
194: $$P_{n} = \; n! \rho^{n} P_{0} \;\geq\; \frac{\textstyle n! \rho^{n}}
195: {\textstyle n! \rho^{n} e^{1/\rho}} \;=\; e^{\textstyle - 1/\rho},$$
196: and
197: $$\overline{n} \;-\; n P_{n} \;=\; P_{0} \sum_{i=1}^{n} i
198: n^{\underline{i}} \rho^{i} \;-\; n P_{n}.$$
199: Now,
200: \begin{eqnarray*}
201: P_{0} \sum_{i=1}^{n} i n^{\underline{i}} \rho^{i} & = & \frac{\sum_{j=1}^{n}
202: (n - j) \rho^{-j}/j!}{\sum_{j=0}^{n} \rho^{-j}/j!} \\
203: & = & n \;-\; \frac{n}{\sum_{j=0}^{n} \rho^{-j}/j!} \;-\; \frac{\sum_{j=1}^{n} j
204: \rho^{-j}/j!}{\sum_{j=0}^{n} \rho^{-j}/j!} \\
205: & \leq & n \;-\; \frac{n}{e^{1/\rho}} \;-\; \frac{1}{n! \rho e^{1/\rho}}\,.
206: \end{eqnarray*}
207: Therefore,
208: \begin{equation}
209: \overline{n} \;-\; n P_{n} \; \leq \; n \; - \; n e^{-1/\rho} \;-\; %
210: \rho^{-1} e^{-1/\rho}/n! \;-\; n e^{-1/\rho} \; \leq \; n (1 \:-\: 2 e^{- 1/\rho}) %
211: \;- \;\rho^{-1} e^{-1/\rho}/n!
212: \end{equation}
213:
214: Thus, by Eqs~(9), (10) and (11), we have
215: \begin{eqnarray*}
216: \overline{w} & \leq & (\sigma + \delta) \left(n \left(1 \:-\: 2e^{-1/\rho} \right) %
217: \;-\; \frac{1}{n! \rho e^{1/\rho}}\right) \\
218: & & \mbox{} \;-\; (\delta + \sigma/2) \left(1 \;-\; \frac{1}{n! \rho^{n} e^{1/\rho}} \;-\; %
219: e^{- 1/\rho} \right) \;+\; 2\delta \left( \sum_{i=0}^{n} n^{\underline{i}} \rho^{i} \right)^{-1},
220: \end{eqnarray*}
221: which yields the desired upper bound for $\rho < 1$. When $n$ is large,
222: $$\overline{w} \;\leq\; (\sigma + \delta) \left(n(1 - 2e^{-1/\rho}) \right)
223: \;-\; (\delta + \sigma/2) (1 - e^{-1/\rho}) \;+\;
224: O\left( (\sigma/2 + 3\delta)\: e^{-1/\rho} \frac{\rho^{-n}}{n!}\right).$$
225: \end{proof}
226: \begin{corollary}
227: If $\rho < 1$, and irrespective of the values of $\sigma$ and $\delta$,
228: the worst-case waiting time of a node for the token in $\cal A$ is $O(n)$
229: when $n$ is large.
230: \end{corollary}
231: