# Generalized expression for waiting time.

In a certain system, a customer must first be served by server 1 and then by server 2. The service times at server i are Exponential with rate $μ_i$ , i = 1, 2. An arrival finding server 1 busy waits in line for that server. Upon completion of service at server 1, the customer either enters service with server 2 if server 2 is free or else queues up behind server 2 until server 2 is free. Customers depart the system after being served by server 2. Suppose that when you arrive there are i customers in queue in front of server 1 and j customers in queue in front of server 2 . What is the expected total time you spend in the system? At the instant t=0, both the servers just began serving the customers.

Note: I want to derive a general expression for the waiting time for any value of i and j. Doing it for i and j equals 1~2 is easy.

My approach for i=1, j=0:

E[time] = E[time waiting at 1] + 1/μ1 + E[time waiting at 2] + 1/μ2.

Now, E[time waiting at 1] = 1/μ1 , E[time waiting at 2] = (1/μ2) $\frac{μ1}{μ1 + μ2}$. The last equation follows by conditioning on whether or not the customer waits for server 2 (finds a customer being served by server 2.) Therefore, E[time] = 2/μ1 + (1/μ2)[1 + μ1/(μ1 + μ2)]

My approach for generalized expression:

E[time] = E[time waiting at 1] + 1/μ1 + E[time waiting at 2] + 1/μ2.

Now, E[time waiting at 1] = i/μ1 since i customers are in front of the arriving customers at server 1.

E[time waiting at 2] = $\sum_{n=1}^{i+j}(n/μ2)$(Pr{Arriving customer finds n customers at server 2 after being served at server 1}).

P.S.: I'm having difficulty in determining the probability that arriving customer finds n customers at server 2 after being served at server 1.

• Tip: Focus on the expected time it takes for all $(i+j)$ customers ahead of you to pass through server 2 ($Y$). Compare with how long you expect to wait and pass through server 1 $(X)$. – Graham Kemp May 31 '17 at 1:51
• @GrahamKemp can you please elaborate a bit. I couldn't get your point. – RSA May 31 '17 at 3:40
• Your expected time is the minimum of (A) the expected time for $i$ people clear server 1 and you pass through both servers, and (B) the expected time for $i+j$ people clear server 2 and you to pass through that. – Graham Kemp May 31 '17 at 4:05

You expect to take $X(i)$ to pass through server 1.   That is the expected time for both you and the $i$ people already there to pass through.
Now, you can expect it to take $Y(i+j)$ for server 2 to process the $(i+j)$ people ahead of you.   This will either be completed by the time you reach server 2 (when $X(i)\geqslant Y(i+j)$), or you would need to wait until it does (when $Y(i+j)>X(i)$).
Either way, you can then expect to take an additional $\mu_2^{-1}$ to pass through service 2 yourself.
So the expected time for you to pass through both servers will be $\bbox[lemonchiffon, 1ex]{\max\{X(i),Y(i+j)\}+\mu_2^{-1}}$ .
Evaluate $X(i)$ and $Y(i+j)$.