1%{ @file fj_rmax_erlang.m
2 % @brief Maximum response time R_K^max
for Erlang service times
4 % @author LINE Development Team
8 % @brief Maximum response time R_K^max
for Erlang service times
11 % Computes the expected value of the maximum response time
for K
12 % M/E_k/1 queues (Poisson arrivals, Erlang-k service times).
14 % For K=2 (two servers), uses the closed-form formula:
15 % R_2^max = R_1 + R_2 - sum_{m=0}^{k1-1} sum_{n=0}^{k2-1} C(m+n,m) * mu1^m * mu2^n / (mu1+mu2)^{m+n+1}
17 % For general K, uses numerical integration:
18 % R_K^max = integral_0^inf [1 - prod_{i=1}^{K} F_Erlang(t)] dt
20 % where F_Erlang(t) = 1 - exp(-mu*t) * sum_{j=0}^{k-1} (mu*t)^j / j!
24 % Rmax = fj_rmax_erlang(K, k, lambda, mu)
29 % <tr><th>Name<th>Description
30 % <tr><td>K<td>Number of parallel servers (positive integer)
31 % <tr><td>k<td>Number of Erlang stages (positive integer)
32 % <tr><td>lambda<td>Arrival rate
33 % <tr><td>mu<td>Service rate per Erlang stage (mean service = k/mu)
38 % <tr><th>Name<th>Description
39 % <tr><td>Rmax<td>Expected maximum response time R_K^max
43 % A. Thomasian,
"Analysis of Fork/Join and Related Queueing Systems",
44 % ACM Computing Surveys, Vol. 47, No. 2, Article 17, July 2014.
45 % Eq. (33) and (34) on page 17:18.
47function Rmax = fj_rmax_erlang(K, k, lambda, mu)
50 line_error(mfilename,
'K must be a positive integer. Got K=%d.', K);
54 line_error(mfilename,
'k (number of stages) must be a positive integer. Got k=%d.', k);
57% Compute mean service time and utilization
59rho = lambda * mean_service;
62 line_error(mfilename,
'System is unstable: rho = %.4f >= 1.', rho);
65% Compute response time
for M/E_k/1 queue
using Pollaczek-Khinchin formula
66% R = mean_service / (1 - rho) * [1 + rho * (1 + 1/k) / 2]
67% Simplified: R = mean_service * (1 + rho*(k+1)/(2*k*(1-rho)))
68cv2 = 1 / k; % Squared CV of Erlang-k
69R_single = mean_service * (1 + rho * (1 + cv2) / (2 * (1 - rho)));
72 % Use closed-form formula (Eq. 34)
73 % For identical servers: k1 = k2 = k, mu1 = mu2 = k/R
74 mu_resp = k / R_single; % Effective rate for response time
76 % R_2^max = 2*R - sum_{m=0}^{k-1} sum_{n=0}^{k-1} C(m+n,m) * mu^m * mu^n / (2*mu)^{m+n+1}
80 correction = correction + nchoosek(m + n, m) * (mu_resp^m) * (mu_resp^n) / ((2 * mu_resp)^(m + n + 1));
83 Rmax = 2 * R_single - correction;
85 % Use numerical integration
for general K
86 % The response time distribution
for M/E_k/1 can be approximated by Erlang
87 % with parameters matched to the response time moments
89 % For M/E_k/1, use the approximation that response time
is approximately
90 % Erlang with adjusted parameters
91 k_resp = ceil(1 / cv2_response(k, rho)); % Effective stages
for response time
92 mu_resp = k_resp / R_single;
94 % Erlang CDF
for response time
95 erlang_cdf = @(t) erlang_cdf_func(t, k_resp, mu_resp);
97 % Expected maximum: integral_0^inf [1 - F(t)^K] dt
98 integrand = @(t) 1 - erlang_cdf(t).^K;
100 % Numerical integration
101 upper_limit = R_single * 20; % Well beyond the tail
102 Rmax = integral(integrand, 0, upper_limit,
'RelTol', 1e-10,
'AbsTol', 1e-12);
107function cv2 = cv2_response(k, rho)
108% Squared CV of response time
for M/E_k/1 queue (approximation)
109% Based on: c2_R ≈ (c2_X + rho*(1+c2_X)/2) / (1 + rho*(1+c2_X)/2)
111cv2 = (cv2_X + rho) / (1 + rho); % Simplified approximation
112cv2 = max(cv2, 1/20); % Bound to avoid numerical issues
115function F = erlang_cdf_func(t, k, mu)
116% Erlang-k CDF: F(t) = 1 - exp(-mu*t) * sum_{j=0}^{k-1} (mu*t)^j / j!
124 S = S + (mu * t(i))^j / factorial(j);
126 F(i) = 1 - exp(-mu * t(i)) * S;