LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
fj_mg1_respt_moments.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_API_FJ_FJ_MG1_RESPT_MOMENTS_H
6#define LINE_API_FJ_FJ_MG1_RESPT_MOMENTS_H
7
8/**
9 * @file
10 * @ingroup api_fj
11 * Mean and variance of the M/G/1 response time, as ForkTail inputs.
12 *
13 * Templated port of matlab/src/api/fj/fj_mg1_respt_moments.m. No JAR
14 * counterpart. Closes the white-box route of fj_tail_forktail for a fork
15 * branch that is an M/G/1 FCFS queue, from the first three moments of its
16 * service time:
17 *
18 * E[T] = E[S] (1 + rho/(1-rho) (1+SCV_S)/2)
19 * V[T] = E[W]^2 + lambda E[S^3]/(3(1-rho)) + E[S^2] - E[S]^2
20 *
21 * with rho = lambda E[S] and E[W] = lambda E[S^2]/(2(1-rho)), the
22 * Pollaczek-Khinchine mean waiting time. The THIRD moment enters the variance
23 * only, so a Markovian branch needs no input beyond what its service law
24 * already reports.
25 *
26 * A service law with no finite third moment (a Pareto branch of shape <= 3,
27 * say) leaves the ForkTail variance undefined; that is reported as an input
28 * error rather than propagated as an infinity, because every downstream
29 * ForkTail fit would then silently return the exponential special case.
30 *
31 * Reference: M. Nguyen, S. Alesawi, N. Li, H. Che, H. Jiang, "ForkTail: A
32 * Black-Box Fork-Join Tail Latency Prediction Model for User-Facing
33 * Datacenter Workloads", ACM HPDC 2018, equations (10) and (11).
34 *
35 * ARITHMETIC: rational in the four inputs, so the exact instantiation is
36 * available and there is no static_assert.
37 */
38
39#include <cmath>
40
41#include "line/num/number.h"
42#include "line/util/error.h"
43
44namespace line {
45namespace fj {
46
47/** Mirrors MATLAB's [ET, VT] return list. */
48template <class T>
50 T ET; ///< mean response time
51 T VT; ///< variance of the response time
52};
53
54/**
55 * @brief Mean and variance of the M/G/1 response time, as ForkTail inputs.
56 *
57 * @param lambda arrival rate at the branch
58 * @param ES first moment of the service time
59 * @param ES2 second moment of the service time
60 * @param ES3 third moment of the service time, finite
61 */
62template <class T>
63Mg1ResptMoments<T> fj_mg1_respt_moments(const T& lambda, const T& ES, const T& ES2,
64 const T& ES3) {
65 const T one = num_traits<T>::from_int(1);
66 const T two = num_traits<T>::from_int(2);
67 const T three = num_traits<T>::from_int(3);
68 const T rho = lambda * ES;
69 if (rho >= one) throw InputError("fj_mg1_respt_moments: the branch is unstable, rho >= 1");
70 if (!std::isfinite(num_traits<T>::to_double(ES3)))
71 throw InputError(
72 "fj_mg1_respt_moments: the service law has no finite third moment, so the ForkTail "
73 "response time variance is undefined");
74
75 const T scvS = (ES2 - ES * ES) / (ES * ES);
77 r.ET = ES * (one + rho / (one - rho) * (one + scvS) / two);
78 const T EW = lambda * ES2 / (two * (one - rho));
79 r.VT = EW * EW + lambda * ES3 / (three * (one - rho)) + ES2 - ES * ES;
80 return r;
81}
82
83} // namespace fj
84} // namespace line
85
86#endif // LINE_API_FJ_FJ_MG1_RESPT_MOMENTS_H
InputError(const std::string &what)
Definition error.h:39
The exception types the port throws.
Mg1ResptMoments< T > fj_mg1_respt_moments(const T &lambda, const T &ES, const T &ES2, const T &ES3)
Mean and variance of the M/G/1 response time, as ForkTail inputs.
Number-type abstraction for the templated API port.
Mirrors MATLAB's [ET, VT] return list.
T VT
variance of the response time