Ex09 2 Sol
Ex09 2 Sol
Problem #1 2 pts for (a), 2 pts for (b), 3 pts for (c), and 3 pts for (d).
Answer the following question regarding the basics of systems and performance modeling.
a) What is a system?
b) What is performance?
c) What is a model, what is the goal of a model, and why do we build models?
“A model is a representation (physical, logical, or functional) that mimics another object under study” (Molly). The goal
of a model is to predict some behavior of an actual object of system. Models are often cheaper, easier, faster, and
safer than studying real systems.
“Computer simulation is the discipline of designing a model of an actual or theoretical physical system, executing the
model on a computer, and analyzing the execution output.” (Fishwick).
Problem #2 2 pts for (a), 2 pts for (b), 6 pts for (c) (1 pt for mean, 1 pt for variance and 2 pts for each plot).
Answer the following question regarding the basics of probability theory as they apply to performance
modeling.
A random variable is a function that maps a real number to every possible outcome in the sample space.
c) Consider an unfair six-sided die where the probability of rolling a “1” is three times the probability of
rolling any other value. All other values have the same probability of occurring. Let X be the random
variable that takes on values 1 through 6 for our unfair die. Plot the pmf and CDF of X. Determine the mean
of X.
f(x) |
|
|
0.375 + o
| |
0.250 + |
| |
0.125 + | o o o o o
| | | | | | |
+---+---+---+---+---+---+---
0 1 2 3 4 5 6 x
F(x) |
|
1.000 + +---
| |
0.875 + +---+
| |
0.750 + +---+
| |
0.625 + +---+
| |
0.500 + +---+
| |
0.375 + +---+
| |
0.250 + |
| |
0.125 + |
| |
+---+---+---+---+---+---+---
0 1 2 3 4 5 6 x
Problem #3 5 pts for (a) (roughly 1 pt per sub-answer), 5 pts for (b) (2 pts for PK, 3 pts for set-up).
a) For an M/M/1 queue we know that the mean number of customers in the system (L) is equal to the
utilization divided by one minus the utilization. Using basic laws and relationships, derive the mean wait in
the system (W), the mean number of customers in the queueing area (Lq), and the mean wait in the queuing
area (Wq) as a function of arrival rate and service rate. For full credit, your expressions need to be
simplified.
We know that L = ρ (1 − ρ ) where ρ = λ μ where λ = customer arrival rate and μ = customer service rate.
Little’s Law states that L = λW . We also know what Lq = L − ρ and Wq = W − (1 μ ) . So, we now have
W = 1 (μ − λ ) , Wq = λ ((μ − λ )μ ) , and Lq = ρ 2 (1 − ρ ) .
b) Consider a single server queue with Poisson arrivals (rate λ) and a uniformly distributed service time (with
minimum value a seconds and maximum value b seconds). Solve for the mean number of customers in the
system (L). You do not need to simplify your expression for L.
1 12 ⋅ (b − a )
This is an M/G/1 queue where the G is uniform with μ =
1
(a + b ) and σ 2 = 1 (b − a )2 and so Cs = .
2 12 (1 2 )(a + b )
2λ
We also have that ρ= Using the PK formula (for M/G/1) we have
a+b
⎛ ⎛ 1 12 ⋅ (b − a ) ⎞⎟
2
⎞
⎛ 2λ ⎞
2
⎜ ⎜ ⎟
⎜ ⎟ ⎜1 + ⎜ (1 2 )(a + b) ⎟⎠ ⎟
⎝a +b⎠ ⎜ ⎝ ⎟
ρ 2 (1 + Cs 2 ) 2λ ⎝ ⎠ (simplification is not necessary).
L=ρ+ = +
2(1 − ρ ) a+b ⎛ 2λ ⎞
2⎜ 1 − ⎟
⎝ a +b⎠
Consider the following single-server queueing system from time = 0 to time = 10 sec. Arrivals and service times
are:
• Customer #1 arrives at t = 1 second and requires 2 seconds of service time
• Customer #2 arrives at t = 2 second and requires 2 seconds of service time
• Customer #3 arrives at t = 5 seconds and requires 2 seconds of service time
• Customer #4 arrives at t = 8 seconds and requires 2 seconds of service time
Solve for system throughput (X), total busy time (B), mean service time (Ts), utilization (U), mean system time
(delay in system) (W), and mean number in the system (L). Show your work to receive full credit.
Num in sys |
|
3 +
|
2 + +---+
| | |
1 + +---+ +---------------+ +-------+
| | | | |
+---+---+---+---+---+---+---+---+---+---+---
1 2 3 4 5 6 7 8 9 10 time
Problem #5 5 pts for Monte Carlo framework, 5 pts for correct solution.
Write a Monte Carlo simulation to model a biased coin as follows. When flipped if the coin show tails it has a
50% chance of tails or heads on the next flop. However, if the coin shows heads then it has 75% chance of
showing heads again on the next flip. The Monte Carlo simulation should determine the probability of a head
showing. You may assume that you have access to a function rand_val() that returns uniform(0.0, 1.0).
int main()
{
double head_prob; // Probability of flipping a head
double heads, tails; // Counters for heads and tails
int i; // Loop counter
rand_val(1);
head_prob = 0.50;
heads = tails = 0;
for (i=0; i<NUM_ITER; i++)
{
if (rand_val(0) < head_prob)
{
heads++;
head_prob = 0.75;
}
else
{
tails++;
head_prob = 0.50;
}
}
return(0);
}
1 pt for C function library, 1 pt for process oriented, 1 pt for each of facility, storage, event,
Problem #6 mailbox, table, reporting and random number streams, and 1 pt for run length control.
Give an approximately 100 to 150 word overview or description of what is CSIM. You will be graded for
completeness (i.e., it is not sufficient to just say “CSIM is a simulation language”).
CSIM is a commercial C function library from Mesquite Software for developing process-oriented discrete event
simulation models. CSIM was originally developed in the 1980s. A CSIM process models a system component and it
can be active, holding (time moves forward), or waiting. CSIM processes run independently. CSIM supports
constructs for facilities (entities that do work), storage (entities that can be allocated and de-allocated), events
(process synchronization), mailboxes (passing messages between processes), tables (collecting and summarizing
data), reporting, and random number streams. Reporting includes standard end-of-run reports and inspector functions
for use during simulation runtime and at the end-of-run. CSIM also supports automatic run length control (or stopping)
using confidence intervals based on a batch-means method.
Problem #7 Roughly 1 pt for each correct line. Allow for any ordering of simultaneous events.
Appendix A contains a CSIM program. What is the output from this program?
5 pts for (a) (use of table 2 pts, insertion of record() 2pts and D/M/1 is 1 pt), 5pts for (b)
Problem #8 (2 for create(), 1 for loop, 2 for hold() and record()).
a) Appendix B contains a CSIM program that models a single server queue. Add a CSIM table to the program
to collect data on the number of customers in the system as seen by an arriving customer. What kind of
queue (identify using Kendall notation) does this CSIM program model?
b) Write a CSIM process that will periodically (say, every DELAY seconds – DELAY is a globally defined
constant value) collect data on how many customers are queued for a CSIM facility named Server (the
facility Server has been globally defined). The collected data should be recorded in a CSIM table named
Cust_table (Cust_table has been globally defined).
void sample()
{
create("sample");
while(1)
{
hold((double) DELAY);
record((double) qlength(Server), Cust_table);
}
}
5 pts for identify keying components (1 pts for each component), 3 pts for basic structure, 2 pts
Problem #9 for cache hit and else of three holds).
Describe how to model a disk drive unit. Sketch-out a CSIM process for a disk drive that captures a “pretty
good” level of detail for modeling reading a file from the disk drive unit. It is important to identify all the
components and/or functionality of a disk drive unit that may affect performance.
Key aspects of disk drive performance are the 1) cache hit probability, 2) head seek time, 3) disk spin time, and 4)
actual disk (also cache) access rate. The key performance metric of interest is the response time to read a file. A
CSIM process for a disk drive read model looks like:
Where Prob_hit, Read_rate1, Read_rate2, Seek_time, and Spin_time are all global variables that have been defined and
declared elsewhere previous to disk() be invoked. In this model we used probability distributions for cache hit, head
movement time, and disk spin time. An even more detailed model would have a “real” cache and would completely model
head movement based on the head seek algorithm actually used in the disk drive. The disk location would also be
modeled.
Problem #10 6 pts for formulas, 1 pt for each correctly computed value.
Below are some sample means taken from independent replications of a simulation model. What is the 95%
confidence interval (CI)? What is the accuracy of the CI? A T-score table is given in Appendix C.
10
⋅ (10 + 12 + 15 + 15 + 15 + 17 ) = 14
1
12 Y =
6
15
15
15 S=
1
6 −1
[ 2 2
]
⋅ (10 − 14 ) + (12 − 14 ) + K + (17 − 14 ) = 2.5298
2
17
tα 2 = 2.57 (for 95% confidence we use α = 0.05 and N = 6 degrees of freedom, so we use the N - 1 = 5 row)
⎛ 2.5298 ⎞
H = 2.57 ⋅ ⎜⎜ ⎟⎟ = 2.6543
⎝ 6 ⎠
Thus, the population mean (μ) is between 11.346 and 16.6543 with 95% confidence. The accuracy of
the CI is 2.6543/14 = 19%.
Extra Credit: 4 pts for two indexes, 4 pts for getting length, 2 pts for picking queue including load balancing.
Write a CSIM process that models the following load balancer. Consider a single load balancer where all
customers arrive. There are N queues. A customer can be sent to any of the N queues. For an arriving customer,
randomly select two queues out of the N. Send the customer to the queue (of the two selected) with the smallest
number of customers in the system. Ties need to be broken fairly. The prototype for the queue process (that you
need not write) is void queue[i](double org_time); Each queue has a facility Server[i] in it.
The index i ranges from 0 to N – 1.
void loadBalancer()
{
int index1, index2; // Index for queues
int len1, len2; // Number in system for selected queues
// Get the number in the system for the two selected queues
len1 = qlength(Server[index1]) + num_busy(Server[index1]);
len2 = qlength(Server[index1]) + num_busy(Server[index2]);
FACILITY Server;
void generate(void);
void queue1(double service_time);
void sim(void)
{
create("sim");
Server = facility("Server");
generate();
hold(SIM_TIME);
}
void generate()
{
create("generate");
hold(1.0);
queue1(2.0);
hold(1.0);
queue1(2.0);
hold(2.0);
queue1(1.0);
hold(5.0);
queue1(1.0);
}
FACILITY Server;
TABLE Cust_table;
void sim(void)
{
double lambda, mu;
create("sim");
Server = facility("Server");
Cust_table = table("Customer table");
lambda = 0.9;
mu = 1.0;
generate(lambda, mu);
hold(SIM_TIME);
report();
}
create("generate");
while(1)
{
interarrival_time = 1.0 / lambda;
hold(interarrival_time);
service_time = exponential(1.0 / mu);
queue1(service_time);
}
}
reserve(Server);
hold(service_time);
release(Server);
}
Appendix C – T score table
Selected values of tα 2; N −1
α 2 = 0.05 α 2 = 0.025
N–1 t t
4 2.13 2.78
5 2.02 2.57
6 1.94 2.45
7 1.90 2.37
8 1.86 2.31
9 1.83 2.26
10 1.81 2.23
11 1.80 2.20
12 1.78 2.18