1function [XN,UN,QN,RN,TN,CN,tranSysState,tranSync,sn]=solver_ssa_analyzer_serial(sn, init_state, options, isHashed)
2% [XN,UN,QN,RN,TN,CN]=SOLVER_SSA_ANALYZER_SERIAL(SN, OPTIONS)
4M = sn.nstations; %number of stations
5K = sn.nclasses; %number of classes
7% istSpaceShift = zeros(1,M);
10% istSpaceShift(i) = 0;
12% istSpaceShift(i) = istSpaceShift(i-1) + size(sn.space{i-1},2);
17NK = sn.njobs
'; % initial population per class
33if isfield(options,'config
') && isfield(options.config,'eventcache
')
34 eventCache = EventCache.create(options.config.eventcache, sn);
36 eventCache = EventCache.create(false, sn);
39% Snapshot the USER capacities before the solver_ssa preamble rewrites
40% sn.cap/classcap in place (it folds the state-space cutoff into them,
41% making every open class look capacity-constrained).
43userClasscap = sn.classcap;
44[probSysState,StateSpaceAggr,arvRates,depRates,tranSysState,tranSync] = solver_ssa(sn, init_state, options, eventCache);
46wset = 1:size(StateSpaceAggr,1);
48 refsf = sn.stationToStateful(sn.refstat(k));
49 XN(k) = probSysState*depRates(wset,refsf,k);
53 isf = sn.stationToStateful(ist);
55 TN(ist,k) = probSysState*depRates(wset,isf,k);
56 QN(ist,k) = probSysState*StateSpaceAggr(wset,(ist-1)*K+k);
58 % For a USER-capacity-constrained OPEN class arrivals can be dropped, so
59 % the arrival-based estimator counts the OFFERED load (including dropped
60 % jobs) and overestimates utilization; use the departure-based (carried
61 % load) estimator for such a class. Closed classes are never dropped
62 % (their classcap is finite by population, not by a buffer), and the
63 % pre-preamble snapshot excludes the cutoff-derived truncation caps.
64 canDropClass = isinf(sn.njobs(:)') & (isfinite(userCap(ist)) | isfinite(userClasscap(ist,:)));
66 case SchedStrategy.INF
68 UN(ist,k) = QN(ist,k);
70 case {SchedStrategy.PS, SchedStrategy.DPS, SchedStrategy.GPS, ...
71 SchedStrategy.PSPRIO, SchedStrategy.DPSPRIO, SchedStrategy.GPSPRIO, SchedStrategy.LPS}
72 if isempty(sn.lldscaling) && isempty(sn.cdscaling)
74 if ~isempty(PH{ist}{k})
76 UN(ist,k) = TN(ist,k)/sn.rates(ist,k)/S(ist);
78 UN(ist,k) = probSysState*arvRates(wset,isf,k)/sn.rates(ist,k)/S(ist);
82 else % lld/cd/ljd cases
83 ind = sn.stationToNode(ist);
84 % Busy-server FRACTION: carried load over
the effective
85 % capacity. Load-dependent stations divide by
the lldscaling
86 % peak;
class-dependent stations divide by
the declared
87 % per-
class peak rate (sn.cdscalingpeak), so Util = T*S/peak.
88 isCd = ~isempty(sn.cdscaling) && ist <= numel(sn.cdscaling) && ~isempty(sn.cdscaling{ist});
90 if ~isempty(sn.lldscaling) && ist <= size(sn.lldscaling,1)
91 ceff = max(ceff, max(sn.lldscaling(ist,:)));
94 if ~isempty(PH{ist}{k})
96 cdiv = sn.cdscalingpeak(ist,k);
101 UN(ist,k) = TN(ist,k)*map_mean(PH{ist}{k})/cdiv;
109 % [ni,nir] = State.toMarginal(sn, ind, StateSpace(st,(istSpaceShift(i)+1):(istSpaceShift(i)+size(sn.space{i},2))));
112 % UN(i,k) = UN(i,k) + probSysState(st)*nir(k)*sn.schedparam(i,k)/(nir*sn.schedparam(i,:)
');
118 if isempty(sn.lldscaling) && isempty(sn.cdscaling)
120 if ~isempty(PH{ist}{k})
122 UN(ist,k) = TN(ist,k)*map_mean(PH{ist}{k})/S(ist);
124 UN(ist,k) = probSysState*arvRates(wset,isf,k)*map_mean(PH{ist}{k})/S(ist);
128 else % lld/cd/ljd cases
129 ind = sn.stationToNode(ist);
130 % Busy-server FRACTION: carried load over the effective
131 % capacity. Load-dependent stations divide by the lldscaling
132 % peak; class-dependent stations divide by the declared
133 % per-class peak rate (sn.cdscalingpeak), so Util = T*S/peak.
134 isCd = ~isempty(sn.cdscaling) && ist <= numel(sn.cdscaling) && ~isempty(sn.cdscaling{ist});
136 if ~isempty(sn.lldscaling) && ist <= size(sn.lldscaling,1)
137 ceff = max(ceff, max(sn.lldscaling(ist,:)));
140 if ~isempty(PH{ist}{k})
142 cdiv = sn.cdscalingpeak(ist,k);
147 UN(ist,k) = TN(ist,k)*map_mean(PH{ist}{k})/cdiv;
155 % [ni,~,sir] = State.toMarginal(sn, ind, StateSpace(st,(istSpaceShift(i)+1):(istSpaceShift(i)+size(sn.space{i},2))));
158 % UN(i,k) = UN(i,k) + probSysState(st)*sir(k)/S(i);
169 RN(ist,k) = QN(ist,k)./TN(ist,k);
174 CN(k) = NK(k)./XN(k);
178% now update the routing probabilities in nodes with state-dependent routing
179TNcache = zeros(sn.nstateful, K);
180XNcache = zeros(sn.nstateful, K);
182 for isf=1:sn.nstateful
183 if sn.nodetype(isf) == NodeType.Cache
184 TNcache(isf,k) = probSysState*depRates(:,isf,k);
185 XNcache(isf,k) = probSysState*arvRates(:,isf,k);
190% updates cache actual hit and miss data + retrieval-system expected latency.
191% For retrieval-aware caches, the per-class hit/miss accounting reads
192% TNcache for the configured hitClass / missClass (departures of those
193% classes downstream of the cache). The retrieval-complete arrival fires
194% the actual miss event in afterEventCache, so the miss-class departure
195% rate captured by TNcache is the true miss rate.
196retrievalLatencyWarned = false;
198 for isf=1:sn.nstateful
199 if sn.nodetype(isf) == NodeType.Cache
200 ind = sn.statefulToNode(isf);
201 np = sn.nodeparam{ind};
202 if length(np.hitclass)>=k
206 sn.nodeparam{ind}.actualhitprob(k) = TNcache(isf,h)/sum(TNcache(isf,[h,m]));
207 sn.nodeparam{ind}.actualmissprob(k) = TNcache(isf,m)/sum(TNcache(isf,[h,m]));
209 sn.nodeparam{ind}.actualhitprob(k) = NaN;
210 sn.nodeparam{ind}.actualmissprob(k) = NaN;
213 % The Eq. 8 retrieval-system expected latency is not currently
214 % implemented; report NaN whenever a retrieval system is
215 % configured for this class.
216 expectedLatency = NaN;
217 if isfield(np, 'retrievalSystemQueueIndices
') ...
218 && isKey(np.retrievalSystemQueueIndices, int32(k-1)) ...
219 && ~isempty(np.retrievalSystemQueueIndices(int32(k-1)))
220 if ~retrievalLatencyWarned
221 line_warning(mfilename, 'Retrieval-system expected latency
is not currently implemented; reporting NaN.
');
222 retrievalLatencyWarned = true;
225 sn.nodeparam{ind}.actualresidt(k) = expectedLatency;