2%% Example of a mixed queueing network with multiple chains and
class switching
3% Demonstrates
class switching within both open and closed job
classes.
4% Chain 1: Closed
class with 2
classes that can switch (interactive users)
5% Chain 2: Open
classes with 2
classes that can
switch (batch requests)
6% Chain 3: Open
class (external load)
8model = Network(
'mqn_multichain');
11node{1} = Delay(model,
'ThinkingTime');
12node{2} = Queue(model,
'WebServer', SchedStrategy.FCFS);
13node{3} = Queue(model,
'AppServer', SchedStrategy.PS);
14node{4} = Queue(model,
'DataServer', SchedStrategy.FCFS);
15node{5} = Source(model,
'Source');
16node{6} = Sink(model,
'Sink');
19% Chain 1: Closed
classes (interactive users that can
switch types)
20jobclass{1} = ClosedClass(model,
'InteractiveA', 3, node{1});
21jobclass{2} = ClosedClass(model,
'InteractiveB', 2, node{1});
22% Chain 2: Open
classes (batch jobs that can
switch types)
23jobclass{3} = OpenClass(model,
'BatchA', 0);
24jobclass{4} = OpenClass(model,
'BatchB', 0);
25% Chain 3: Open
class (external load)
26jobclass{5} = OpenClass(model,
'ExternalLoad', 0);
28%% Block 3: service times
30node{1}.setService(
jobclass{1}, Exp.fitMean(1.5));
31node{1}.setService(
jobclass{2}, Exp.fitMean(2.0));
34node{2}.setService(
jobclass{1}, Exp.fitMean(0.4));
35node{2}.setService(
jobclass{2}, Exp.fitMean(0.5));
36node{2}.setService(
jobclass{3}, Exp.fitMean(0.3));
37node{2}.setService(
jobclass{4}, Exp.fitMean(0.35));
38node{2}.setService(
jobclass{5}, Exp.fitMean(0.2));
41node{3}.setService(
jobclass{1}, Exp.fitMean(0.8));
42node{3}.setService(
jobclass{2}, Exp.fitMean(1.0));
43node{3}.setService(
jobclass{3}, Exp.fitMean(0.6));
44node{3}.setService(
jobclass{4}, Exp.fitMean(0.7));
45node{3}.setService(
jobclass{5}, Exp.fitMean(0.5));
48node{4}.setService(
jobclass{1}, Exp.fitMean(0.5));
49node{4}.setService(
jobclass{2}, Exp.fitMean(0.6));
50node{4}.setService(
jobclass{3}, Exp.fitMean(1.2));
51node{4}.setService(
jobclass{4}, Exp.fitMean(1.5));
52node{4}.setService(
jobclass{5}, Exp.fitMean(0.8));
54%% Block 4: arrival rates
55node{5}.setArrival(
jobclass{3}, Exp(0.4));
56node{5}.setArrival(
jobclass{4}, Exp(0.2));
57node{5}.setArrival(
jobclass{5}, Exp(0.3));
59%% Block 5: routing with
class switching
60M = model.getNumberOfNodes();
61K = model.getNumberOfClasses();
63P = model.initRoutingMatrix();
65% ===== Chain 1: Closed
classes with switching =====
66% InteractiveA routing:
67P{1,1}(1,2) = 1; % ThinkingTime -> WebServer
68P{1,1}(2,3) = 0.7; % WebServer -> AppServer (stay in InteractiveA)
69P{1,2}(2,3) = 0.3; % Class
switch to InteractiveB at WebServer
70P{1,1}(3,4) = 1; % AppServer -> DataServer
71P{1,1}(4,1) = 1; % DataServer -> ThinkingTime
73% InteractiveB routing:
74P{2,2}(1,2) = 1; % ThinkingTime -> WebServer
75P{2,2}(2,3) = 0.8; % WebServer -> AppServer (stay in InteractiveB)
76P{2,1}(2,3) = 0.2; % Class
switch to InteractiveA at WebServer
77P{2,2}(3,4) = 1; % AppServer -> DataServer
78P{2,2}(4,1) = 1; % DataServer -> ThinkingTime
80% ===== Chain 2: Open
classes with switching =====
82P{3,3}(5,2) = 1; % Source -> WebServer
83P{3,3}(2,3) = 0.6; % WebServer -> AppServer (stay in BatchA)
84P{3,4}(2,3) = 0.4; % Class
switch to BatchB at WebServer
85P{3,3}(3,4) = 1; % AppServer -> DataServer
86P{3,3}(4,6) = 1; % DataServer -> Sink
89P{4,4}(5,2) = 1; % Source -> WebServer
90P{4,4}(2,3) = 0.7; % WebServer -> AppServer (stay in BatchB)
91P{4,3}(2,3) = 0.3; % Class
switch to BatchA at WebServer
92P{4,4}(3,4) = 1; % AppServer -> DataServer
93P{4,4}(4,6) = 1; % DataServer -> Sink
95% ===== Chain 3: External load =====
96% ExternalLoad routing:
97P{5,5}(5,2) = 1; % Source -> WebServer
98P{5,5}(2,3) = 1; % WebServer -> AppServer
99P{5,5}(3,4) = 1; % AppServer -> DataServer
100P{5,5}(4,6) = 1; % DataServer -> Sink
104%% Block 6: solve with multiple solvers
105options = Solver.defaultOptions;
111disp(
'Mixed QN with 3 chains, 5 classes, and class switching:');
112disp(
'- Chain 1 (Closed): InteractiveA and InteractiveB (switch at WebServer)');
113disp(
'- Chain 2 (Open): BatchA and BatchB (switch at WebServer)');
114disp(
'- Chain 3 (Open): ExternalLoad');
118solver{end+1} = MVA(model, options);
119solver{end+1} = SSA(model, options);
121for s = 1:length(solver)
122 fprintf(
'SOLVER: %s\n', solver{s}.getName());
123 AvgTable{s} = solver{s}.getAvgChainTable();