LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
example_fj_mam_percentile.m
1%% Example: Fork-Join Percentile Analysis using SolverMAM
2%
3% This example demonstrates automatic Fork-Join percentile analysis
4% using SolverMAM with FJ_codes integration. When a valid Fork-Join
5% topology is detected, SolverMAM automatically uses FJ_codes to
6% compute response time percentiles.
7%
8% Reference:
9% Z. Qiu, J.F. Pérez, and P. Harrison, "Beyond the Mean in Fork-Join Queues:
10% Efficient Approximation for Response-Time Tails", IFIP Performance 2015.
11% Copyright 2015 Imperial College London
12
13clear;
14clc;
15
16%% Create a simple Fork-Join model
17% This creates the structure: Source → Fork → K Queues → Join → Sink
18
19model = Network('FJ_Percentile_Example');
20
21% Source with exponential arrivals
22source = Source(model, 'Source');
23
24% Fork node
25fork = Fork(model, 'Fork');
26
27% K parallel queues with exponential service
28K = 10; % Number of parallel queues
29mu = 1.0; % Service rate (per queue)
30queues = cell(1, K);
31
32for i = 1:K
33 queues{i} = Queue(model, sprintf('Queue%d', i), SchedStrategy.FCFS);
34end
35
36% Join node (paired with Fork)
37join = Join(model, 'Join', fork);
38
39% Sink
40sink = Sink(model, 'Sink');
41
42% Create an open class (after Sink)
43jobClass = OpenClass(model, 'Class1');
44lambda = 0.5; % Arrival rate
45source.setArrival(jobClass, Exp(lambda));
46
47for i = 1:K
48 queues{i}.setService(jobClass, Exp(mu));
49end
50
51% Link the network: Source → Fork → Queues → Join → Sink
52% Create routing matrix
53P = model.initRoutingMatrix();
54P{1}(source, fork) = 1.0;
55for i = 1:K
56 P{1}(fork, queues{i}) = 1.0;
57 P{1}(queues{i}, join) = 1.0;
58end
59P{1}(join, sink) = 1.0;
60
61model.link(P);
62
63%% Solve with SolverMAM (automatically detects FJ and uses FJ_codes)
64
65fprintf('Creating SolverMAM...\n');
66solver = SolverMAM(model);
67
68fprintf('Running analysis (FJ topology will be auto-detected)...\n');
69solver.runAnalyzer();
70
71%% Display average metrics
72
73fprintf('\n=== Average Performance Metrics ===\n');
74avgTable = solver.getAvgTable();
75disp(avgTable);
76
77%% Display percentile metrics
78
79fprintf('\n=== Response Time Percentiles ===\n');
80% Request specific percentiles: 50th, 90th, 95th, 99th
81percentiles = [50, 90, 95, 99];
82[percRT, percTable] = solver.getPerctRespT(percentiles);
83
84disp(percTable);
85
86% Display detailed percentile information
87fprintf('\nDetailed Percentile Results:\n');
88for i = 1:length(percRT)
89 fprintf(' Class: %s\n', percRT(i).class);
90 fprintf(' K (parallel queues): %d\n', percRT(i).K);
91 fprintf(' Method: %s\n', percRT(i).method);
92 for p = 1:length(percRT(i).percentiles)
93 fprintf(' %.2f percentile: %.4f\n', ...
94 percRT(i).percentiles(p), percRT(i).values(p));
95 end
96end
97
98%% Compare with theoretical values for exponential case
99% For exponential service in Fork-Join, we can compute theoretical bounds
100
101fprintf('\n=== Theoretical Comparison ===\n');
102fprintf('System parameters:\n');
103fprintf(' Arrival rate (lambda): %.2f\n', lambda);
104fprintf(' Service rate per queue (mu): %.2f\n', mu);
105fprintf(' Number of parallel queues (K): %d\n', K);
106fprintf(' Utilization per queue: %.2f\n', lambda/mu);
107if lambda < mu*K
108 fprintf(' Stability: Stable\n');
109else
110 fprintf(' Stability: Unstable\n');
111end
112
113% Mean response time approximation for exponential FJ
114mean_rt_approx = sum(1./(mu * (1:K)));
115fprintf(' Approximate mean response time: %.4f\n', mean_rt_approx);
116
117fprintf('\nNote: FJ_codes provides accurate percentile approximations\n');
118fprintf(' for the synchronization delay in Fork-Join systems.\n');