LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
lsn_max_multiplicity.m
1%{ @file lsn_max_multiplicity.m
2 % @brief Computes the maximum multiplicity of nodes in a Layered Software Network
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Computes maximum multiplicity (concurrency level) for LSN nodes
9 %
10 % @details
11 % This function computes the maximum multiplicity (throughput capacity) for
12 % each node in a Layered Software Network (LSN). Uses Kahn's algorithm for
13 % topological sorting to propagate constraints through the network.
14 %
15 % @par Syntax:
16 % @code
17 % outflow = lsn_max_multiplicity(lsn)
18 % @endcode
19 %
20 % @par Parameters:
21 % <table>
22 % <tr><th>Name<th>Description
23 % <tr><td>lsn<td>Layered Software Network structure
24 % </table>
25 %
26 % @par Returns:
27 % <table>
28 % <tr><th>Name<th>Description
29 % <tr><td>outflow<td>Maximum multiplicity (throughput capacity) for each node
30 % </table>
31%}
32function outflow = lsn_max_multiplicity(lsn)
33ag = lsn.dag > 0;
34mult = lsn.mult;
35type = lsn.type;
36isref = lsn.isref;
37n = size(ag, 1);
38
39% Manual topological sort (Kahn's algorithm)
40order = kahn(ag);
41
42% initially load ref task multiplicity
43inflow = zeros(n,1);
44for i = 1:n
45 if type(i) == LayeredNetworkElement.TASK && isref(i)
46 inflow(i) = mult(i);
47 % Also account for entries with open arrivals
48 elseif type(i) == LayeredNetworkElement.ENTRY
49 if isfield(lsn, 'arrival') && ~isempty(lsn.arrival) && ...
50 iscell(lsn.arrival) && i <= length(lsn.arrival) && ...
51 ~isempty(lsn.arrival{i})
52 % Entry has open arrival - needs at least 1 thread of its parent task
53 inflow(i) = 1;
54 end
55 end
56end
57outflow = zeros(n,1);
58
59if length(mult) < n
60 mult(end+1:n) = Inf;
61end
62
63isfunction = zeros(n,1);
64if isfield(lsn, 'isfunction') && ~isempty(lsn.isfunction)
65 isfunction(1:length(lsn.isfunction)) = lsn.isfunction(:);
66end
67
68for k = 1:n
69 i = order(k);
70 if isfunction(i) && inflow(i) > 0
71 % A function task's instances are provisioned by the platform, not
72 % spawned by its callers, so caller concurrency does not bound them.
73 % Keeping the declared multiplicity is queueing-neutral when fewer
74 % jobs than instances circulate, but it is required for the classic
75 % think-time semantics: the task think time overlaps across the
76 % mult(i) instances and is absorbed into each instance's idle period
77 % (against which the delay-off timer races), whereas collapsing to
78 % the caller bound would force every job to pay the think time in
79 % the request path and throttle the entry.
80 outflow(i) = mult(i);
81 else
82 outflow(i) = min(inflow(i), mult(i));
83 end
84 for j = [1:i-1,i+1:n]
85 if ag(i,j)
86 inflow(j) = inflow(j) + outflow(i);
87 end
88 end
89end
90%inflow(type > LayeredNetworkElement.TASK )=0;
91for i = 1:n
92 if type(i) == LayeredNetworkElement.TASK && mult(i)==Inf && ~isref(i)
93 outflow(i) = Inf;
94 end
95end
96end
Definition fjtag.m:157
Definition Station.m:245