Stochastic OR

3.1 Queueing Process in Continuous Time

In Section 2.1 we modeled time as progressing in discrete chunks. However, we can also model queueing systems in continuous time, so that jobs can arrive at any moment in time and have arbitrary service times. In this section, we develop a set of recursions to construct the waiting times of jobs served in their order of arrival.1 That is, according to the FIFO scheduling rule.

Let us imagine that a machine2 A single server. starts working on a one-hour job at 9 am, and there is no job in the queue. When the next job arrives before \(10\) am, this second job has to wait in the queue until the first job finishes at 10 am. If, however, this second job arrives after 10 am, it finds the server free, so its service can start immediately upon arrival.

More generally, suppose that we are given an ordered sequence of arrival times3 Moments at which the system state is inspected or changes are often called epochs. \(\{A_{k}\}\) and a set of iid service times \(\{S_{k}\}\), so that job \(k\) arrives at time \(A_{k}\) and needs an amount \(S_{k}\) of service. The departure times \(\{D_{k}\}\) follow from the recursion4 Note that we assume that job \(k\) `reveals' its required service at the moment it arrives.

\begin{align*} \As_{k}&= \max\{A_k, D_{k-1}\}, & D_{k} &= \As_{k} +S_k, & D_{0} &=0, \tag{3.1.1} \end{align*}

where \(\As_{k}\) is the time the service of job \(k\) starts5 That is, when this job moves from the queue to the server. , and \(D_{0}=0\) is meant to start the recursions. Why is this true? The service of job \(k\) cannot start before it arrives at \(A_k\) or before job \(k-1\) leaves the server at \(D_{k-1}\). Thus, the first moment the service of job \(k\) can start is \(\max\{A_k, D_{k-1}\}\). When started, it takes \(S_{k}\) to get served.

Once \(A_{k}\) and \(D_{k}\) are known, we compute the sojourn time, i.e., the total time in the system, and the waiting time, i.e., the time in queue6 But not at the server. , as

\begin{align*} \J_k &= D_{k} - A_k, & \W_k &= \As_k - A_k = \J_{k} - S_{k}. \end{align*}

While it is often simple to measure arrival times in practical situations, it is harder to generate \(\{A_{k}\}\) directly with a simulator. For this we let a random number generator generate iid rvs \(\{X_{k}\}\) that represent the inter-arrival times between jobs. The arrival times can then be computed recursively from Eq. (1.2.2) as \(A_k = A_{k-1} + X_k\), \(A_{0} = 0\). And conversely, from Eq. (1.3.1), if \(\{A_{k}\}\) is known, \(X_{k} = A_{k}-A_{k-1}\). Interestingly, if \(\{X_{k}\}\) and \(\{S_{k}\}\) are given, we need not first compute \(\{A_{k}\}\) and \(\{D_{k}\}\) using Eq. (3.1.1) to find the sojourn times and waiting times. In fact, suppose that job \(k-1\) has to wait a time \(\W_{k-1}\) in queue and spends \(S_{k-1}\) in service, then its sojourn time \(\J_{k-1} =\W_{k-1}+ S_{k-1}\). If \(X_k\) time units elapse between the arrivals of job \(k-1\) and \(k\), then job \(k\) must wait in queue7 As we start counting jobs for \(k=1, 2, \ldots\), \(\W_{0}\) has no physical meaning.

\begin{align*} \W_{k} &= [\W_{k-1} + S_{k-1}- X_k]^+, & \W_{0} &=0, & \J_{k} &= \W_{k} + S_{k}. \tag{3.1.2} \end{align*}

However, if only \(\J_k\) is needed, use \(\J_{k} = [\J_{k-1} - X_k]^+ + S_k\), \(\J_{0} =0\).

Later we will need the system state at arbitrary times, not only at arrivals. The number of arrivals \(A(t)\) during \([0, t]\) can be computed from \(\{A_{k}\}\) as8 Read the RHS as the maximum of all \(k\) such that \(A_{k} \leq t\).

\begin{equation*} A(t):= \sum_{k=1}^{\infty}\1{A_k\leq t} = \max\{k: A_k \leq t\}. \tag{3.1.3} \end{equation*}

The function \(t\to A(t)\) is right-continuous.9 Define \(f(x-) = \lim_{y\uparrow x} f(y)\) and \(f(x+) := \lim_{y\downarrow x} f(y)\). A function \(f\) is right-continuous if \(f(x) = f(x+)\) for all \(x\), and left-continuous if \(f(x) = f(x-)\) for all \(x\).

Conversely, we can retrieve the arrival times \(\{A_{k}\}\) from the process \(\{A(t)\}\). For example, if \(A(s) = k-1\) and \(A(t) = k\), then the arrival time \(A_k\) of the \(k\)th job must lie somewhere in \((s,t]\). Specifically,

\begin{equation*} A_k = \min\{t: A(t) \geq k\}, \quad A(0) = 0. \end{equation*}

And if \(\{A_{k}\}\) is known, then \(X_k = A_k - A_{k-1}\). Thus, the arrival times, the inter-arrival times, and the number of arrivals as a function of time can be derived from one another.

Similarly, for the number of jobs that started service, \(\As(t)\), and the departures \(D(t)\) we have

\begin{align*} \As(t) &= \max\{k : \As_k \leq t\}, & \As_{k} &=\min\{t: \As(t) \geq k\}, \\ D(t) &= \max\{k : D_k \leq t\}, & D_{k} &=\min\{t: D(t) \geq k\}. \end{align*}

The work in the system \(W(t)\) is the time needed to clear the remaining service of all jobs present at time \(t\). To construct \(\{W(t)\}\) graphically, we draw lines that start at points \((A_k, \J_k)\) and go down with slope -1 until the lines hit the \(x\)-axis.10 The slope is \(-1\) because a single server processes one hour of work per hour. If the system is empty, the work in the system remains at zero until an arrival occurs. To express \(W(t)\) as a function of time, note that \(A(t)\) is the last arrival at \(t\), thus, \(D_{A(t)}\) is the time this job leaves. Therefore,

\begin{equation*} W(t)= [D_{A(t)} - t]^+. \tag{3.1.4} \end{equation*}

The work in the system is equal to the so-called virtual waiting time. For example, if \(W(t) = 5\) hours11 It takes 5 hours to complete all jobs in the system at time \(t\). , then a job arriving at \(t\) would have a waiting time of \(5\) hours. Fig. 1 shows how the above concepts relate to each other.

waitingtimegg1.png
Figure 1: The work in the system \(W(t)\) as a function of time. Right after job~\(k\) arrives at \(A_{k}\), the work in the system satisfies \(W(A_{k}) = \J_{k}\), where the sojourn time \(\J_{k}\) is the sum of the waiting time \(\W_{k}\) and service time \(S_{k}\). The server processes work at a rate of one hour per hour so \(W\) decreases as the solid lines with slope~\(-1\). Once the system is empty, there is nothing to process, and \(W\) remains at \(0\) as long as the server is idle.

Once we have the arrival and departure processes, it is easy to compute the number of jobs in the system at time \(t\), as illustrated in Fig. 2,

\begin{equation*} \L(t) = A(t) - D(t) + \L(0), \tag{3.1.5} \end{equation*}

where \(\L(0)\) is the number of jobs in the system at time \(t=0\); typically \(\L(0)=0\). Recalling that a job can be either waiting or in service, we distinguish \(\L(t)\) (in the system), \(\QQ(t)\) (in queue), and \(\Ls(t)\) (in service):

\begin{align*} \L(t) &= \QQ(t) + \Ls(t), & \Ls(t) &= \As(t) - D(t) = \L(t) - \QQ(t). \end{align*}

Note that statistics obtained from a sample path \(t \to \QQ(t)\) can be quite different from the samples \(k\to \QQ(A_k-)\) as observed by arriving jobs, and likewise for \(L(t)\) and \(L(A_{k}-)\).12 We need to be careful about the left and right limits at jump epochs.

The following indicator function

\begin{equation*} I_k(s) := \1{A_{k}\leq s < D_{k}}, \tag{3.1.6} \end{equation*}

represents the presence of job \(k\) at time \(s\).13 \(I_{k}(s)=1\) if job \(k\) is present in the system at time \(s\) and zero otherwise. Clearly, \(\int_{0}^{t} I_{k}(s) \d s\) corresponds to the total time job \(k\) spends in the system up to time \(t\) while summing over all jobs present at time \(s\) gives \(L(s)\). Therefore,

\begin{align*} \J_k &= \int_0^\infty I_k(s)\d s, & \L(t) &= \sum_{k=1}^\infty I_k(t). \tag{3.1.7} \end{align*}

With this we can relate sojourn times and the number of jobs in the system. When \(n\) is the index of the last departure of a simulation, we have on the one hand,14 At time \(D_n\) all \(n\) jobs have departed.

\begin{align*} \frac{1}{D_{n}} \sum_{k=1}^n \int_{0}^{D_{n}}I_{k}(s) \d s = \frac{1}{D_{n}} \sum_{k=1}^n \J_{k}, \end{align*}

while on the other hand,

\begin{align*} \frac{1}{D_{n}}\int_{0}^{D_{n}} \sum_{k=1}^n I_{k}(s) \d s = \frac{1}{D_{n}}\int_{0}^{D_{n}} \L(s) \d s = \bar L. \end{align*}

As the expressions at the LHSs are equal, the sum over all sojourn times divided by the time of the last departure equals the time-average number of jobs in the system:

\begin{align*} \bar L \approx \frac{1}{D_{n}} \sum_{k=1}^n \J_{k}. \tag{3.1.8} \end{align*}

We finish this section with constructing the recursions for the waiting times in a multi-server queue. Jobs line up in queue \(i\), \(i=1, \ldots, c\) that is served by a server working with rate \(\mu(i)\). When job \(k\) arrives, it sees a vector \(w_k = (w_{k}(1), \ldots, w_{k}(c))\) of waiting times at the queues. Suppose the job selects the line with the shortest waiting time.15 This is not necessarily the same as the shortest queue. Let \(e(i)\) denote the \(i\)th unit vector16 A vector with a 1 at place \(i\) and zeros elsewhere. , and \(\mathbf{1} = \sum_{i=1}^{c} e_{i}\). Then, in analogy with Eq. (3.1.2), the waiting time \(w_{k+1}\) updates as17 \([\cdot]^+\) applies element-wise to the vector.

\begin{align*} s_{k} &= \argmin_{i \in \{1, \ldots, c\}}\{w_{k}(i)\},& w_{k+1} &= [w_{k} + S_{k} e(s_{k})/\mu(s_{k}) - X_{k}\mathbf{1}]^+, \tag{3.1.9} \end{align*}

where \(s_k\) is the queue selected by job \(k\).

While the above recursions are charming in their simplicity, it is hard to generalize these recursions to more realistic queueing situations involving control. In later sections we discuss how to use discrete-event simulation to analyze such harder cases.

atltdt.png
Figure 2: Relation between the arrival process \(\{A(t)\}\), the departure process \(\{D(t)\}\), the number in the system \(\{\L(t)\}\) and the sojourn times \(\{\J_k\}\). Observe that the arrival and departure times of different jobs are intertwined.
TF 3.1.1

Claim: with our notation, the following mapping is correct:

\begin{align*} A_k : \N \to \R, \quad{\text{job id (integer) to arrival time (real number)}}. \end{align*}
Solution
Did you actually try? Maybe see the 'hints' above!:
Solution, for real

True. A simple variation: Claim: with our notation, the following mapping is correct:

\begin{align*} A(t) : \R\to \N, \quad{\text{time (real number) to number of jobs (integer)}}. \end{align*}
TF 3.1.2

Claim: the number of arrivals \(A(t)\) during \([0, t]\) can be defined as \(\min\{k : A_k \geq t\}\).

Solution
Did you actually try? Maybe see the 'hints' above!:
Solution, for real

False. Suppose \(A_3 = 10\) and \(A_4 = 20\). Take \(t=15\). Then \(\min\{k : A_k \geq 15\} = 4\), since \(A_3 < t=15 < A_4\). However, \(\max\{k : A_k \leq t\} = 3\). In fact, at time \(t=15\), 3 jobs arrived, not 4. Here is a simple variation: Claim: the number of arrivals \(A(t)\) during \([0, t]\) can be defined as \(\min\{k: A_k > t\}\)?

TF 3.1.3

Claim: The waiting time of the third job is correctly represented in Fig. 3.

waitingtimethirdjob.png
Figure 3: The figure for TF 3.1.3.
Solution
Did you actually try? Maybe see the 'hints' above!:
Solution, for real

False.

TF 3.1.4

Claim: \(A_{A(t)} = t\) for all \(t\) and \(A(A_{n}) =n\) for all \(n\).

Solution
Did you actually try? Maybe see the 'hints' above!:
Solution, for real

False. The first part is false, the second is true. \(A(t)\) is the number of arrivals during \([0,t]\). Suppose that \(A(t) = n\). This \(n\)th job arrived at time \(A_n\). Thus, \(A_{A(t)}\) is the arrival time of the last job that arrived before or at time \(t\). In a similar vein, \(A_n\) is the arrival time of the \(n\)th job. Thus, the number of arrivals up to time \(A_n\), i.e., \(A(A_n)\), must be \(n\).

TF 3.1.5

For the \(G/G/1\) queue, the virtual waiting time process \(\{W(t), t\geq 0\}\) satisfies

\begin{equation*} W(t) = [J(A_{A(t)}) + (A_{A(t)}-t)]^+. \end{equation*}
Solution
Did you actually try? Maybe see the 'hints' above!:
Solution, for real

False. \(\J(A_{A(t)})\) is nonsense. The correct expression is \([\J_{A(t)} - (t-A_{A(t)})]^{+} = [D_{A(t)} - t]^{+}\) because \(A_{A(t)} + \J_{A(t)} = D_{A(t)}\).

Ex 3.1.6

Show that \(\L(A_k-)>0 \iff A_k \leq D_{k-1}\).

Hint

Use that \(\L(A_k-)>0\) means that the system contains at least one job at the time of the \(k\)th arrival, and that \(A_k- < D_{k-1}\) means that job \(k\) arrives (almost surely) before job \(k-1\) departs.

Solution
Did you actually try? Maybe see the 'hints' above!:
Solution, for real

The claim is evident: for, if the system contains a job when job \(k\) arrives, it is not empty. But if it is not empty, then at least the last job that arrived before job \(k\), i.e., job \(k-1\), must still be in the system. That is, \(D_{k-1} \geq A_k\). A more formal proof proceeds along the following lines. Using that \(A(A_k-) = k-1 = D(D_{k-1})\),

\begin{equation*} \begin{split} & \L(A_k-) > 0 \iff A(A_k-) > D(A_k-) \iff A(A_{k}-) \geq D(A_k) \\ &\iff k -1 \geq D(A_k) \iff D(D_{k-1}) \geq D(A_k) \iff D_{k-1} \geq A_{k}, \end{split} \end{equation*}

where the last relation follows from the fact that \(D(t)\) is a counting process, hence monotone non-decreasing.

Ex 3.1.7

Why is \(W(A_{k}) = \J_{k}\)?

Solution
Did you actually try? Maybe see the 'hints' above!:
Solution, for real

Job \(k\) arrives at time \(t=A_{k}\). Its sojourn time is \(\J_{k}\). If no further jobs arrive, the system will be empty at time \(D_{k} = A_{k} + \J_{k}\). Therefore, the work in the system at that moment is \(\J_{k} = D_{k} - t = D_{k} - A_{k}\).

Ex 3.1.8

Modify Eq. (3.1.9) such that job \(k\) selects the queue with the shortest sojourn time.

Solution
Did you actually try? Maybe see the 'hints' above!:
Solution, for real

\(s_{k} = \argmin_{i \in \{1, \ldots, c\}}\{w_{k}(i) + S_k/\mu(i)\}\).