Approximate Analysis of Reader/Writer Queues
Theodore Johnson
Dept. of CIS
University of Florida
Gainesville, F1 326112024
September 3, 1992
Abstract
We analyze the performance of queues that serve readers and writers. Readers are served con
currently, while writers require exclusive service. We approximately analyze a firstcomefirstserve
(FCFS) reader/writer queue, and derive simple formulae for computing waiting times and capacity
under the assumption of Poisson arrivals and exponential service. We extend the analysis to handle
a onewriter queue, and a queue that includes writeintention locks. The simple analyses that we
present can be used as rulesofthumb for designing concurrent systems.
Keywords: Performance Analysis, Queuing System, Concurrent System, Reader/Writer, Lock Queue.
1 Introduction
Most analyses of database or operating system concurrency control algorithms handle only the case
of exclusive access. In practice, however, many concurrency control algorithms use both shared and
exclusive locks. Shared locks are important for increasing concurrency and reducing serialization delays.
This paper describes queues that model reader and writer access to a shared resource. Readers place
R (read) locks and writers place W (write) locks. Any number of R locks may be held simultaneously,
but only one W lock may be placed at a given time. In addition, R and W locks are incompatible and
cannot be held simultaneously. A queuing discipline that manages the lock access should be fair, so that
readers should not starve writers, and vice versa. A common fairness criterion is FCFS. That is, if lock
a arrives before lock 3, grant a before granting 3.
The FCFS lock queuing mechanism obeys the following protocol: when the job in service finishes, if
the first job in the queue is a reader, grant access to all readers up to the first writer. If the first job is
a writer, grant the lock to the writer. In addition, if the queue is empty, or only readers are in service
and a reader arrives, grant a lock to the reader (see figure 1). We call this type of lock queue a FCFS
reader/writer queue or a FCFS r/w queue, for short.
We also analyze a variation on the FCFS R/W queue. In the variation, which we call the onewriter
queue, there is at most one writer in the queue at a time, and the reader arrival rate is much larger than
the writer arrival rate. The onewriter queue has many applications (for example, in the analysis of a
communications driver [15]). We use the onewriter queue to model queues with writeintention locks,
or R/U/W queues. In a R/U/W queue, the incoming stream consists of R and U locks. R locks are
compatible both with each other and with U locks, but U locks are not compatible with each other. U
locks occasionally upgrade to W locks, which are exclusive. The R/U/W queue can model writeintention
locks, which are often used for concurrent data structures [3] and for multigranularity locking [4].
The model that we develop predicts the expected waiting time for R, W and U locks. In addition,
the model can predict the probability that a W lock is in the queue, and determine whether the resource
can serve the offered load.
Several analyses of read and write access to a shared resource have been in the context of database
performance [23, 17, 6]. For example, Tay [23] handles readonly requests by modifying the formulae for
the probability of a lock conflict and assumes that queuing for shared data is rare.
The problem of queuing for shared data has been modeled in the context of replicated databases. It
is assumed that there are k copies of a file, and two different copies of a file may be read simultaneously.
Coffman et al. [7] analyze a saturated queue in which a write request preempts all current readers. In
[8], Coffman, Gelenbe, and Plateau analyze the same queue, except that readers may begin reading a
copy of the file as soon as it has been written. Baccelli and Coffman [2] analyze a preemptive queue
that has Poisson arrivals. Nelson and Iyer [18] analyze a nonpreemptive queue in which the job arrivals
are Poisson and are processed in FCFS order. Read operations receive exponentially distributed service,
and write operations receive phase distributed service (the exponential distribution is an example of a
phase distribution.) Nelson and Iyer's analysis can be thought of as an exact analysis of an approximate
FCFS R/W queue, as readers and writers receive FCFS service, but at most k readers may be served
simultaneously. This analysis requires an iteration step that involves multiplication of k by k matrices.
Courcoubetis et al. [10, 1] analyze queuing systems of k queues in which ordinary customers require
service from only one queue, while locking customers require service from all queues simultaneously.
Thomasian and Nicola [24, 26, 25] use the vacationing server model to study the optimal control of a
reader/writer queue. Courcoubetis and Reiman [9] use a system of k queues with ordinary and locking
customers to study the optimal control of a reader/writer queue.
Reiman and Wright [20, 19] provide an exact analysis of the stability of the first queueing system
described in this paper, permit arbitrary reader and writer service times, and permit the writer arrival
process to be an arbitrary renewal process. These authors also provide lower and upper bounds on the
lock waiting times, and a heavy traffic approximation.
This paper has two main contributions. The first contribution is the simple formulae for predicting
the capacity and the waiting times of the FCFS R/W queuing system. These formulae can provide simple
rules of thumb for designing concurrent systems [12, 11]. The second contribution of this paper is the
analysis of the onewriter queue and the R/U/W queue. To the best of our knowledge, these queuing
systems have not been treated before.
2 An Approximation to the FCFS R/W Queue
The difficulty in analyzing the reader/writer queue is that the two different classes of customers receive
different types of service. The writers are the more tractable of the two classes because they receive
exclusive FCFS service. Therefore, we approximate the reader/writer queue as an FCFS queue with an
aggregate customer, which is a writer together with all readers immediately ahead of it in the queue. The
aggregate customer has an arrival rate of A,, and a service time equal to the service time for a writer
plus the service time for all of the readers immediately ahead of it. We need to calculate the service
time for the readers that entered the queue before the entering writer and after the previous writer.
There are two cases: either the entering writer finds another writer in the queue, or no writers are in
the queue. If another writer is in the queue, the entering writer must wait for all readers that entered in
between writer arrivals. Otherwise, the writer must wait for only those readers that survived (have not
yet finished service) until the writer entered.
We will use the following symbols and definitions in the analysis:
A,: reader arrival rate.
A,,: writer arrival rate.
pr,: reader service rate.
p,,: writer service rate.
p,: probability that a writer is in the queue (or writer utilization).
A,: expected time to serve an aggregate customer (a writer and all readers that arrived after the previous
writer for which the current writer must wait).
Pa: = 1/A,.
r,: expected time that a writer must wait for readers that arrived after the previous writer, if the
previous writer is still in the queue upon the arrival of the current writer.
re: expected time that a writer must wait for readers that arrived after the previous writer, if the previous
writer finished before the current writer arrived.
W,,: expected waiting time for a writer.
W,: expected waiting time for a reader.
S,(n): time to serve n readers.
A,(t): number of readers that arrive in t seconds.
T,,: interarrival time of a writer that finds another writer in the queue.
Nr: number of surviving readers.
service time: time that a customer spends receiving service.
service period: total time that a customer spends in the queue (=service time+waiting time).
The main result of this section is:
Theorem 1 The probability that a writer is in the queue, p,, satisfies:
Aw Pw ( PwAr> 1 p, (, (1+Pw)A,r
= n + + n 1 + + P (1)
Some results that we will need to perform the analysis are:
Lemma 1 Let S,(n) be the time for n concurrent readers to be served, where each reader is served
concurrently at rate P,. Then
d Pr[S,(n) < t] = n 1()ili (2)
i=1
Proof: We model this situation by a puredeath process. Let state k be the condition that there are k
readers left, and let Pk(t) be the probability that the system is in state k at time t, k = 0,..., n, t < 0. If
the system is in state k at time t, then a reader will die at rate k/,. In this model Po(t) = Pr[S,(n) < t].
The description of the system leads to the following system of differential equations:
dPn (t)
dt
dt Pn
dti = ktPk(t) + (k + 1)/,Pk+l(t) 0 < k < n
dPo(t)
_, PT (t)
dt
For our initial conditions, we have Pn(O) = 1 and Pk(O) = 0 if k < n. From this, the solution to the
differential equations is:
The solution to this recurrence is:
pP t)= (;) [E (n i
The last of the differential equations tells us that d! = p,Pi(t), or that
dt 'dt
dPr[S,(n) < t] ie t
Corollary 1
E[S,(n)] = 1/i (3)
S i=
Proof:
E[S,(n)] = fo tnn [ i, _1)( le dt
= nE (n_1(l)i1(1/i) (o00 ip,tei dt)
TE, (n _I)iI(1/i)(1/i,,)
1 ()( _1i(1/i)
St 1 1/i
where the last step is just the application of the combinatorial identity found in [21], page 4. *
With these tools, we can calculate the expected time needed to serve all readers in front of a writer,
W, if another writer is in the queue when W enters. We need to calculate the number of readers that
entered the queue before the entering writer and after the previous writer. Suppose the time between
writer arrivals is t. Let the random variable A,(t) be the number of readers that arrive in t seconds. The
readers have a Poisson arrival rate, so A,(t) has the distribution:
Pr[A,(t) = k]= (At)k 
To calculate the distribution of the number of readers that arrive between the arrival of two writers,
we find the unconditional distribution of A,. For this, we need to know the distribution of t. The
probability that the interarrival period lasts at least t seconds, given that the arriving writer finds at
least one other writer in the queue, is the probability that the interarrival period lasts at least t seconds
and the service period (waiting time plus service time) of the previous writer lasts at least t seconds. Let
T, be the random variable that represents the interarrival time of writers that find the queue utilized.
Then:
d d
Pr[T, < t] = K Pr[interarrival time < t] Pr[previous writer still in queue]
dt dt
where K is a normalizing constant.
Suppose that we already know the expected service time of an aggregate customer, 1/pa, and the
probability that a writer is in the queue, p, = 4,/pa. If we model the aggregate queue as an M/M/1
queue, then we know that the service period distribution (waiting time and service time) is [13]:
Pr[S(t) < t] = e(1)
The probability that the previous writer has not been served in t seconds is 1 S(t), so we have:
dt
SPr[T < t] = K (\ ewt) e(P )) = peot
Using this distribution for T,, we get:
Pr[A, = k] = fQo Pr[A,(t) = k] Pr[T < t]dt
fO 0 (Art)' \Art ok P atdt
k A, fo tke(Ar+Pa)tdt
k! Jo
S A^, k!
k! (A,+, ,)k+1
=Ar+P (xAa (4)
This leads to
Lemma 2 The expected time to serve all readers in front of a writer arriving in a queue that already
contains a writer is:
r, = E[S] = In 1 + p (5)
Proof: We randomize S, using A, and calculate the unconditional expectation.
E[S,] = Pa =0 ( \ 1
[S ] ( P+Ar) Ek= 1 (pat)k 1(/i)
In order to solve this sum, we apply Abel's transformation ([16] page 36),
n k n n
(AX Y, = Xn+ Yk Xk Yk
k=l ( r=1 k=l k=l
Let a = A,/(p/a + Ar), AXk = a and Y, = 1/r. Then Xk = ak/(a 1) and
k k n n
I a an+1 1/k ak/k
a 1
k=1 r=l k=l k=1
Since a < 1, as n  o, an+1 =1 1/k 0 and using the wellknown expansion ln(1 + x) =
Zak/k+ln
k=l
We substitute in the value of a, substitute A /pw for pa, and multiply by the leading constants to
get:
ru= [S,] = In , = In (1+ 
Next, we must calculate the expected waiting time for serving the readers in the case in which the
writer enters the queue and finds only readers in the queue. We cannot use the expected value already
calculated because some of the readers may have left the queue before the writer enters the queue. The
calculation of the distribution of the number of readers in the queue when the writer arrives is intractable.
Instead of the distribution, we will calculate the expected number of readers still in the queue.
Consider three points in time, A < B < C, with respect to a particular writer, W, who enters the
queue and finds no other writers in the queue. Occasion A is the point when the previous writer entered
the queue, occasion B is the point when the previous writer left the queue and occasion C is the point
when W enters the queue (see Figure 2). Because reader arrivals and departures are independent, we
will consider the expected number of surviving readers from (A,B) and from (B,C) separately.
We need to know the lengths of the intervals (A,B) and (B,C). The arrival distribution is memoryless,
so the length of (B,C) has an exponential distribution with parameter A,. We find the approximation
to the distribution of the length of (A,B) the same way we found the approximation to the distribution
of T,. The probability that (A,B) lasts at least t seconds is the probability that the previous writer's
service period lasts at least t seconds and the writer interarrival time is at least t seconds.
d
d Pr[(A, B)I < t] = KPi(1 p)e a(1PwleXt
Pda 
Consider the survivors from (B,C) first. The probability that a reader enters the queue during time
(r, r + dr) is Adr. A reader that entered the queue r seconds before C will survive with probability
e l'. Therefore, the expected number of surviving readers if (B,C) is t seconds long is
E[NBC(t)]= fo Are dr
The unconditional distribution of NBc becomes:
E[NBC] (1e ') (Ae t) dt
Ar (6)
Next, consider the survivors from (A,B). The expected number of survivors from (A,B) is the expected
number of readers that arrived in (A,B), then survived through (B,C). Suppose that the probability of
surviving (B,C) is p. Then if k readers arrived in (A,B), the expected number of survivors, NAB(k,p)
equals kp. To remove the dependence of NAB(k, p), on we need to know the distribution of the number
of arrivals in (A,B). Since the distribution of I(A, B) has the same distribution as T,, the number of
readers that arrive in (A,B) has the same distribution as A,.
NAB()= 0kpP =k
NB(p) k=O p. Pr[A, = k]
o( A_ k Ap_
F 2k=0 1 1+ A,+[,
If the interval (B,C) is t seconds long, the probability of surviving is e Pt. Using this to get the
unconditional distribution of NAB, we get:
NAB= fB A ePrI cetdt
Pw A (7)
The expected number of survivors when W arrives is
N, = NAB +NB ( + ) (8)
prp + A4
In order to calculate the expected waiting time, we assume that the number of surviving readers has
a geometric distribution with mean (1 + pw)A,/(/r, + A4). If A' is then number of surviving readers,
then:
Ptr ,.+A ((l+Pw)Ar ,
Pr[A' = k] =
r (1 + Pw)Ar + p, ++ A ((1 + pw)Ar+p lr + )
We can calculate the mean in the same manner as in Lemma 2, to get:
Lemma 3 The expected time to serve all readers in front of a writer that finds no other writers in the
queue when it arrives is:
re In 1i + + (9)
Pr p ,r + Aw
Now, we know that the expected service time for the aggregate customer is:
1 1
Aw = = p r, + (1 P )re
lPa lw
If we use the fact that pw = A, A and the values of re and ru, we get:
w = + In + + n 1 + (10)
Proving Theorem 1.
To find pw, we find the root of pw in the above equation. This can be done iteratively or with a
nonlinear equation solving package. The queue will be stable if pu < 1.
Once the correct pw has been found, we can try solving the queue as an M/M/1 queue with arrival
rate A, and service rate 1/A,. In this system, the expected waiting time is (pwA,)/(1 po). The
waiting time of an aggregate customer is the waiting time of a reader, but a writer must also wait for all
readers ahead of it to finish, so:
Corollary 2 If the aggregate queue is modeled as an M/ i!/1 queue, the expected waiting times for the
reader and writer customers are:
Ww = (pwAA)/( p) + pru + ( pL)re (12)
2.0.1 M/G/1 Model
We can also consider the server as a network of exponential stages. With probability pw, service is for
an expected 1/~p seconds, then for an expected r, seconds. With probability 1 pw, service is for an
expected 1/p, seconds, then for an expected re seconds. The Laplace transform of the service time of
this server is given by:
B*(s) =( ) (P (US1 ) +(1 P) ( 1 ))
The expected waiting time for a M/G/1 queue is given by ([13] pg.190):
Ax2
W=
2(1 p)
where x is the service time at the server.
The value of x2 can be found by differentiating the Laplace transform twice and evaluating at zero.
This gives:
Corollary 3 If the aggregate queue is modeled as an M/G/1 queue, the expected waiting times for the
reader and writer customers are:
W, = A + ( + r +2(1 P ) (I_ + 1 (13)
w/ w (13)
W, = Wr + pWru + (1 pw)re (14)
2.1 Maximum Throughput
Theorem 1 can be used to predict the maximum throughput.
Corollary 4 At the maximum throughput, Aw, Ar, pw and p, satisfy
A, = A e (eP'(1/1/w1/) 1) (15)
Proof: Set pw = 1 in Theorem 1 and solve for A, We note that this stability condition is the same as
that derived in [20, 19].
As an application, we can find the maximum throughput of the queue when the proportion of readers
to writers is constant.
Corollary 5 If A,/A, = a, then the maximum writer arrival rate is:
A, = (16)
pl, ln(a + 1) + p,
Corollary 5 implies that if a > e 1, increasing the reader service rate is better than increasing the
writer service rate. If a < e 1, the opposite is true.
Theorem 1 can also be used to find the arrival rates such that pw = .5, pw = .75, etc.
2.2 Comparison and Experiments
A R/W queue simulator was built and experiments run. Six hundred thousand samples were taken. The
results of the simulator were then compared to analytical results.
Table 1 shows a comparison between the M/M/1 model and the simulation. The analytical calculation
of p, (and therefore of r, and r,) is usually close to the results of the simulator. The match is best when
A, a A, and becomes worse when A, is much larger than A,. This can be seen in Figure 4. The M/M/1
model gives good predictions of the expected lock waiting times when A, AX. As A, increases, the
waiting times predicted by the M/M/1 model tend to become pessimistic, as can be seen in Figure 3.
Table 2 shows a comparison between the M/G/1 model and the simulation. If A, > AX, then the
M/G/1 model is a better approximation than the M/M/1 model.
When the rate of reader arrivals is close to the rate of writer arrivals, the aggregate customer has
a service distribution that can be approximated well by an exponential distribution. When the rate of
reader arrivals becomes large, the contribution of the readers to the service time becomes greater and the
service time distribution is better approximated by the hyperexponential distribution. A rule of thumb
for choosing the best model to use is the following:
Rule of thumb: If A,/AX > 5, use the M/G/1 model, otherwise use the M/M/1 model.
Figures 5 and 6 show how the maximum writer and reader arrival rate decreases with an increasing
reader and writer arrival rate, respectively. The graphs show a cutoff point in the writer arrival rate after
which the reader arrival rate may be increased almost arbitrarily as the writer arrival rate decreases.
This is largely due to the fact that re and r, depend logarithmically on Ar, so that further increases in
the aggregate customer's service time require exponential increases in the reader arrival rate.
3 The OneWriter Queue
In this section, we analyze a reader/writer queue in which at most one writer is ever in the queue. The
protocol of the onewriter queue is the same as for the FCFS R/W queue: FCFS and readers are served
concurrently. Further, we assume that writers arrive rarely, compared to readers.
Let us calculate E[W,], the expected waiting time for a W lock. We need to know the distribution
of the number of R locks in front of the W lock when the W lock enters the queue. If W locks arrive
rarely, the distribution of the number of R locks in the queue will approach a steadystate M/M/oo
distribution. If N, is the number of R locks in the queue when a W lock arrives, then, from [13]:
Pr[N, = k] = ( (17)
k!
Let W (n) be the waiting time for a W lock if n R locks are in the queue when the W lock enters.
Then, from Corollary 1,
E[W (n)] = 1/i
Combining (17) and Corollary 1, the unconditional distribution of W" is:
E[W.] 1 = 1 1/i (18)
In [5], we find the formula:
Sf i l/, e o0 (1)nlzn
n=l i=1
= e fo(1 et)tldt
= eCGl(x) (19)
The exponential integral can be algebraically obtained from Gi(x), so we can't expect to simplify
Gi(x) into a closed form. Combining (18) and (19), we get:
Theorem 2 The expected waiting time for a W lock in a onewriter queue is:
E[W] = Gi(A,/p,)/p, (20)
Let us next calculate the expected waiting time for a R lock. An R lock waits only if there is a W
lock in the queue ahead of it. If the R lock arrives when the W lock is in service, the R lock will have to
wait for the renewal time of the W lock service. Since we are assuming exponentially distributed service
times, the expected renewal time is 1/p,. The probability that the R lock will arrive when a W lock is
in service is Aw/pw.
An R lock will arrive while the W lock is waiting with probability E[W,]Aw (as there is at most one
W lock in the queue at a time). The R lock will have to wait for the service time of the W lock (1/pw)
plus the remaining time to serve the readers ahead of the W lock. This is the renewal time of the W
waiting time distribution. From [13], this is given by
r = (21)
2mi
where mi is the first moment of the waiting time distribution and m2 is the second moment. We have
already calculated the first moment (E[W,]), so all we need to do is calculate the second moment.
From Lemma 1, the distribution of the time for n readers to finish service is:
d n I
d Pr[S,(n) < t] = n 1 (1)ilep
Using the distribution of the number of readers (17), the distribution of W" is:
d Pr[W, < t] = F 1(Ar (A r/p /_ [7 1 (7 (l)yjpr)t
dt n= n!
Next, we find the second moment:
[ f t 2 {)i [z (n1)(if16irtl) }dt]
2eAt/{r O (A/)) ( 1 (7)(i/i2)
F 2=l n!
In order to simplify the sum, let us express
(7) (i1/i2
Sa r v
as a recursive relation:
g,= E 1 1)/k2
E=1(1I)k1 n + n)] /k2
= (1)k1 n1)/k2 + =1 )( )1/k
Since (, 1) = 0, the first sum is simply gn1. From [21], the second sum is just H(n) = 1 1/i.
Therefore:
g = n1 + j =1 (22)
= (iE= ) (23)
Our problem reduces to finding a simpler form of
v(x)= 1 x" 1 'i
T i=l i 2j=1 1IN
7 Zn=l n!2
The g, function has a simple difference. This suggests that we consider V(x) to be the exponential
generating function of gn, and try to find a relationship that leads to a solution for V(x).
The derivative operator will let us calculate a difference in an exponential generating function. As
suming that go = 0,
+ P(V(x ) =Q() V() =n nl Qn d
Since P() = 1, f P() dx = . Therefore,
()= eo(f ,i(sn) dg+c)
~ no= 0 (n+l i=l i n!
V(x) satisfies a firstorder linear differential equation, so we can apply the formula for the solution
of first order linear differential equations [22],
Since P(x) = 1, f P(x) dx = x. Therefore,
V(x) = ex (fexGl(x)ex dx + c)
Xu
= (s Z1 7 (1 ~([!)j dr+ c)
S( on=l n (n!) )
In order to find the value of the constant c, evaluate V(0) and find that c = 0. Therefore
() ft ( 1)nl "
V(x) = e ) e~G2(x) (24)
n=l
The function G2(x) is also a transcendental function, so we cannot hope to simplify V(x) further. By
using the formula for V(x) (24) and the formula for the renewal time (21), we get:
Lemma 4 The expected residual time of W, is
ri[W,/  ,)
lGr (l{/lLr)
Now that we have calculated ri[W,], we can calculate E[W,] by:
E[W,] = [+ E[W.]A.(1/,p + ri[W,])
which gives:
Theorem 3 The expected wait for a reader in the onewriler queue is:
E[W,] = w + ) + p) (25)
The throughput of the onewriter queue is limited by the arrival rate at which there always is a
writer in the queue. The expected length of time that a W lock is in the queue is 1/ps + E[W/ ]. Using
Theorem 2, we get:
Corollary 6 The throughput of the onewriler queue is limited by
wmx < /r+w ) (26)
,rnaz p,+p ,(A,/p,)
Proof: When the arrival rate over the service rate equals one, there will always be a W lock in the
queue. Therefore, the arrival rate must be less than or equal to the service rate *
3.1 Asymptotics
The functions Gi(x) and G2(x) are transcendental functions, so they cannot be simplified into familiar
functions. Their power series forms aren't completely satisfactory for calculations either. While both Gi
and G2 grow slowly, the maximum terms in their power series grow rapidly, so that for even relatively
small values of x (about 35), limited precision algorithms cannot calculate the functions. Fortunately,
both G1 and G2 have simple asymptotic representations.
The function Gi(x) is related to the exponential integral by
Gi(x) = ln() + 7+ Ei(x)
where El(x) is the exponential integral [14],
loo et
El (x) dt
El has the following asymptotic expansion [14]:
Ei(x) = X[1 1/ + 2!/X2 ... + (1)"n!/a + Rn(x)
where
Rn(x) = (1)+1(n + 1)!x10n(x) 0 < 0n(x) < 1
If we use the first asymptotic expansion (use Ro(x)), we can bound El(x) by
Ei(x) < ex/x
Therefore we can approximate Gi(x) by
Gi(x) l In(x) + (27)
with an error of less than ex/x.
We can use the asymptotic form of Gi(x) to get an asymptotic formula for G2(x) by integrating.
Since Gi(x) has a zero at x = 0, Gl(x)/x has a removable singularity at x = 0. If Gi(x) is expressed
as ln(x) + 7 + El(x), then as x  0, ln(x)  oo and El(x)  o. Therefore, break the interval of
integration [0, x] into two parts, [0, a) and [a, x]. On the first interval, we integrate the power series
representation of Gi(x) and get the value G2(a). On the second interval, we integrate the asymptotic
form of Gi:
Ga(x) G(a) + f (t)dt
= (G2(a) ln(a)2/2 + ln(a)) + ln(X)2/2 + ln()
ln()2/2 + 7 ln() + C2 (28)
The constant c2 m .9891 can be evaluated by using the power series of G2 to evaluate G2(a). The error
is bounded by
error(a)= Jfa E )dx
< fa e/x2dx
< eala2
4 The Reader/WriteUpgrade/Writer Queue
In this section, we use the results of section 3 to analyze the reader/writeupgrade/writer queue. The
R/U/W queue uses three types of locks: read, writeupgrade, and write locks, which we abbreviate sa R,
U and W locks, respectively. W denote the arrival rates of the R and U locks by AR and Au, respectively.
We assume that some proportion of the U locks upgrade to W locks. We denote the service rates of the
R and W locks by PR and pw, respectively. The service time of a U lock depends on the waiting time of
a W lock. We assume that the A, > AX, and that U locks are rarely upgraded to W locks. The result is
that A, > A, and that writer arrivals are rare. Because of the assumptions, the results of the previous
section apply. (The assumptions are safe when the queue is applied to concurrent Btree algorithms, for
example [3, 11]).
The R locks will be blocked only by a W lock. A U lock may be blocked by a W lock or by another
U lock. A W lock comes from a conversion request from the current U lock only, and is blocked by all
of the R locks currently in service. Thus, R locks block U locks only by blocking a W lock conversion.
This leads us to consider strategy of modeling the R/U/W queue as two queues, one for the R and W
locks, and one for the U locks.
In the R/W queue, R locks are served simultaneously. If a W lock enters the queue, the W lock must
wait for the preceding R locks to finish service before obtaining control of the queue. All R locks that
enter the queue after the W lock must wait until the W lock finishes service. In the U queue, U locks
receive FCFS service. The U lock in service might be upgraded to a W lock. The W lock blocks all U
locks. Therefore, the R/W queue and the U queue are coupled by increasing the service time for a U
lock by the expected service period (waiting time and service time) of a W lock.
We can now list the waiting times for the three types of locks.
W: the waiting time for a W lock is the time for all preceding R locks to finish.
R: the waiting time for an R lock is:
Pr[W lock is 'i, 11 _]' [(W service)+(time for surviving R's to finish)]+ Pr[W lock in i.. ]' (time
for W to finish service).
U: the waiting time for a U lock is the the waiting time for a customer in a FCFS queue. The arrival
rate is Au and the service time is:
Pr[no W conversion]*T[serve U  no W conversion]+Pr[W ..... U ;.. ]'(l[*. U I W conver
sion]+(W service period)).
Let :
Pc be the probability that a U lock converts to a W lock. Then Aw = PcAU.
T1 be the expected time to service a U lock if the lock does not upgrade to a W lock.
Tt be the expected time to service a U lock if it upgrades to a W lock.
Therefore, the input parameters for the queue are AR, Au, PR, Pw, Pc, TC and Tt.
Since A, = PcAu, Theorem 2 gives the expected wait for a W lock. Theorem 3 gives the expected
wait for a R lock.
All that needs to be done is to calculate the expected wait for a U lock. The expected service time
for a single U lock is:
1/pu = Au = (1 Pc)TC + P,(T& + E[WV] + 1/pw)
= (1 Pc)TC + Pc(T{ + Gi(A,/p,)/p,) (29)
Therefore, the utilization of the U lock queue is:
Pu = Au/pu
= Au((1 Pc)TI + P,(Tt + Gi(A,/p,)/p,))
If we model the U lock queue as a M/M/1 queue then, from [13],
Theorem 4 The expected waiting time for a U lock in the R/U/W queue is
E[Wu] = (puAu)/( p) (30)
Since W locks are generated from U locks, the throughput of the R/U/W queue is limited by the
service of the U locks.
Corollary 7 The throughput of the R/U/W queue is limited by
AUmax <1
Umax ((1Pc)TJ+Pc(Tj+Gi(A,i/p,)/p,))
4.1 Comparison and Experiments
A R/U/W queue was built and experiments run. Six hundred thousand samples were taken. Table 3
shows a comparison between analytical and simulator results. Since the onewriter queue and the R/U/W
queue are so similar, the comparison applies to the onewriter queue also. The comparison shows that
the analytical model predicts waiting times well. The accuracy of the analytical model improves as the
reader arrival rate increases.
5 Conclusions
We have developed a simple yet accurate model of FCFS reader/writer queue performance. We present
formulae to predict the shared resource capacity, waiting times for read and write locks, and the arrival
rates that produce a desired system loading. The formulae are simple enough to be used in a rule of
thumb by a system designer.
We extend the analyses to handle onewriter queues, and writeupgrade locks. We present formulae
to predict lock waiting times, and an estimate of the capacity of the shared resource. The locking queues
analyzed in this paper are used in many areas, such as concurrent data structures [11] and communications
channels [15].
References
[1] F. Baccelli, C.A. Courcoubetis, and M.I. Reiman. Construction of the stationary regime of queues
with locking. Stochastic Processes and their Applications, 2'. '"265, 1 '.
[2] F. Baccelli and E.G. Coffman Jr. A data base replication analysis using an M/M/m queue with
service interruptions. SICi 1.1TRICS Performance Evaluation Review, 11(4):102107, 19821983.
[3] R. Bayer and M. Schkolnick. Concurrency of operations on Btrees. Acta Informatica, 9:121, 1977.
[4] P.A. Bernstein, V. Hadzilacos, and N. Goodman. Concurrency Control and Recovery in Database
Systems. AddisonWesley, 1 1 7.
[5] T.J. Bromwich. An Introduction to the Theory of Infinite Series. MacMillian and Co., 1926.
[6] A. Chesnais, E. Gelenbe, and I. Mitrani. On the modeling of parallel access to shared data. Com
munications of the AC i1, 26(3):196202, 1983.
[7] E. Coffman and et al. An analysis of parallelread sequentialwrite systems. Performance Evaluation,
1:6269, 1981.
[8] E. Coffman, E. Gelenbe, and B. Plateau. Optimization of the number of copies in a distributed
database. IEEE Transactions on Software Engineering, 7(1):7884, 1981.
[9] C.A. Courcoubetis and M.I. Reiman. Optimal control of a queuing system with simultaneous service
requirements. IEEE Transactions on Automatic Control, AC32(8):717727, 1 I .
[10] C.A. Courcoubetis, M.I. Reiman, and B. Simon. Stability of a queuing system with concurrent
service and locking. SIAM J. Computing, 16(1):169178, 1 I .
[11] T. Johnson. The Performance of Concurrent Data Structure Algorithms. PhD thesis, NYU Dept.
of Computer Science, 1990.
[12] T. Johnson and D. Shasha. A framework for the performance analysis of concurrent Btree algo
rithms. In A(C 1 SIGACT/SIC I[OD/SIGART Symposium on Principles of Database Systems, pages
273287, 1990.
[13] L. Kleinrock. Queueing Systems, volume 1. John Wiley, New York, 1 I.
[14] C.G. Van Der Laan and N.M. Temme. Calculation of Special Functions: The Gamma Function, the
Exponential Integral and Errorlike Functions. Cenrtum foor Wiskunde en Informatica, 1984.
[15] Ian Heavens, Spider Systems Ltd. Experiences in fine grain parallelisation of streamsbased com
munications drivers. In OpenForum '92, Utrecht, November 1992.
[16] R. Mickens. Difference Equations. Van Nostrand Reinhold, New York, 1 I'.
[17] D. Mitre and P.J. Weinberger. Probabilistic models of database locking: Solutions, computational
algorithms and asymptotics. Journal of the AC 11, 31(4 ..878, 1984.
[18] R. Nelson and B. Iyer. Analysis of a replicated database. Performance Evaluation, 5(3):133148,
1 1i "
[19] M.I. Reiman and P.E. Wright. The stability and latency of concurrentx exclusivey. Submitted to
the Journal of the AC'I.
[20] M.I. Reiman and P.E. Wright. Performance analysis of concurrentread exclusivewrite. In Proc.
AC if Sigmetrics Conference on Measuring and Modeling of COmputer SYstems, pages 168177,
1991.
[21] J. Riordan. Combinatorial Identities. Robert E. Kreiger, Huntington, NY, 1979.
[22] G. Simmons. Differential Equations with Applications and Historical Notes. McGrawHill, 1972.
[23] Y.C. Tay, R. Suri, and N. Goodman. Locking performance in centralized databases. AC if Trans
actions on Database Systems, 10(4):415462, 1 I".
[24] A. Thomasian and V. Nicola. Analysis of a threshold policy for scheduling readers and writers.
Technical Report RC 14252, IBM Research Division, 1988.
[25] A. Thomasian and V. Nicola. Analysis of a threshold policy for scheduling readers and writers. In
AC if SICY i! TRICS Conference on Measuring and Modeling of Computer Systems, 1989.
[26] A. Thomasian and V. Nicola. Performance evaluation of a threshold policy for scheduling readers and
writers. Technical Report RC 14878, IBM Research Division, 1989. to appear in IEEE Transactions
on COmputers.
6 Tables and Figures
Pw Ww Wr
Ar Aw Pr pwt sim. ana. sim. ana. sim. ana. r, re
.4 .4 1 1 56.98 56.57 2.192 2 "'. 1.876 1.842 .448 .370
.4 .4 2 1 45.75 45.81 1.072 1.114 .968 .189 .10
.3 .3 1 1 39.32 38.94 1.149 1.125 .818 .828 329 .278
.3 .3 2 1 33.31 33.02 .635 .643 .502 .543 .143 .080
.3 .5 1 1 1 8 7 i. ,' 2.792 2 ". 2.520 2.526 .333 .286
.3 .5 2 1 55.86 55.94 1.499 1.539 1.403 1.420 .145 .06
.5 .3 1 1 45.30 44.83 1.651 1.709 1.263 1.215 .558 .443
.5 .3 2 1 34.98 34.91 .766 .788 .634 1.' .229 .129
.2 .2 1 1 24.07 23.88 ;. .569 .370 .375 .214 .188
.2 .2 2 1 21.21 21.32 .343 .348 .277 .286 .96 .052
.5 .5 1 1 77.40 77.45 5.671 5.868 5.160 5.319 .574 i..
.5 .5 2 1 59.75 59.79 1.873 1.974 1.707 1.779 .234 .139
.55 .55 1 1 89.48 89.40 12.87 14.34 12.32 13.71 .639 .514
1 .3 1 1 60.43 59.11 3.593 3.819 2.779 2.848 1.09 77
1.5 .3 1 1 73.22 72.24 6.556 7.676 5.299 6.268 1.53 1.09
2 .3 1 1 ." '.; 84.00 13.54 16.50 11.85 14.70 1.88 1.34
.1 .1 1 1 11.01 10.97 .235 .232 .135 .135 .104 .096
3 .3 2 1 53.60 52.14 2.365 2.631 1.601 1.893 913 T .I
4 .3 2 1 58.29 56.84 2.977 3.391 2.038 2.250 1.07 ,.,
4 .1 1 1 32.53 29.89 3.223 3.263 1.007 1.274 2.56 1.74
5 .1 1 1 34.47 32.39 3.616 3.790 1.148 1.551 2.84 1.9
2 .2 1 1 52.55 50.66 3.757 4.133 2.123 2.600 1.80 1.26
3 .2 1 1 63.42 60.74 5.698 6.752 4.078 4.712 2.31 1.61
5 .2 2 1 39.58 37.67 1.913 2.021 .944 1.138 1.17 .709
Table 1: FCFS R/W queue, M/M/1 approximation
Pw ww w 1
Ar Aw pr Pwt sim. ana. sim. ana. sim. ana.
.4 .4 1 1 56.98 56.57 2.192 1.876 1.876 1.462
.4 .4 2 1 45.75 45.81 1.072 1.008 '* ' '..'
.3 .3 1 1 39.32 38.94 1.149 .979 .818 .682
.3 .3 2 1 33.31 33.02 .635 .599 .502 .498
.3 .5 1 1 1 . 87 i., , ; 2.792 2.394 2.520 2.077
.3 .5 2 1 55.86 55.94 1.499 1.405 1.403 1.287
.5 .3 1 1 45.30 44.83 1.651 1.442 1.263 *',;
.5 .3 2 1 34.98 34.91 .766 .714 .634 .550
.2 .2 1 1 24.07 23.88 .518 .370 .324
.2 .2 2 1 21.21 21.32 .343 .333 .277 .271
.5 .5 1 1 77.40 77.45 5.671 4.656 5.160 4.107
.5 .5 2 1 59.75 59.79 1.873 1 .1 1.707 1.468
.55 .55 1 1 89.48 89.40 12.87 11.097 12.32 10.472
1 .3 1 1 60.43 59.11 3.593 3.098 2.779 2.136
1.5 .3 1 1 73.22 72.24 6.556 6.193 5.299 4.785
2 .3 1 1 ., .'.; 84.00 13.54 13.199 11.85 11.400
.1 .1 1 1 11.01 10.97 .235 .221 .135 .124
3 .3 2 1 53.60 52.14 2.365 2.189 1.601 1.452
4 .3 2 1 58.29 56.84 2.977 2.7',, 2.038 1.903
4 .1 1 1 32.53 29.89 3.223 2.999 1.007 1.010
5 .1 1 1 34.47 32.39 3.616 3. I'. 1.148 1.246
2 .2 1 1 52.55 50.66 3.757 3.542 2.123 2.009
3 .2 1 1 63.42 60.74 5.698 5.771 4.078 3.732
5 .2 2 1 39.58 37.67 1.913 1.754 .944 .871
Table 2: FCFS R/W queue, M/G/1 approximation
simulation analytical
A, A W W W W. W, W. W
1 .2 .053 .841 .390 .054 .797 .364
4 .2 .119 2.04 .504 .114 1.97 .454
8 .2 .159 2.68 .558 .160 2.66 .513
2 .1 .042 1.38 .190 .039 1.32 .173
8 .1 .077 2.67 .226 .080 2.66 .216
12 .1 .092 3.05 .299 .096 3.06 .230
Table 3: FCFS R/U/W queue. = pw = T = T, = 1.0, Pc= .1
R AR
R enters queue
W finishes service
serve concurrently 
serve serially
Figure 1: Model of a FCFS Reader/Writer Queue
readers enter
I 1 1
A
previous W
enters
I 1 1
previous W
leaves
readers leave
Figure 2: Surviving readers
Waiting time vs. reader arrival rate
waiting time
0.2 0.4 0.6
reader arrival rate
Writer wait (ana)
Reader wait (ana)
Writer wait (sim)
Reader wait (sim)
Figure 3: Comparison between analysis and simulation of R and W waiting times. = .3, pr = /, = 1
I 1
C
current
W enters
n
_n.
t
Writer utilization vs.
reader arrival rate
utilization
0.2 0.4
0.6
reader arrival rate
analytical
simulation
Figure 4: Comparison between analysis and simulation of writer utilization. A = .3, /r = ~, = 1
Maximum reader arrival rate
vs. writer arrival rate
max. reader arrival
0.4 0.6
writer arrival rate
Figure 5: Maximum reader arrival rate vs. writer arrival rate. Pr = P~
Maximum writer arrival rate
vs. reader arrival rate
max. writer arrival
0.8
0.6
0.4
0.2
0
0 0.5 1 1.5 2 2.5 3
reader arrival rate
Figure 6: Maximum writer arrival rate vs. reader arrival rate. pr, = ,, = 1
