lab07 report team20 final

23
2014 Spring Semester EE505 Exp2 – Week3 Queue Simulation Final Report Electrical Engineering 20143084 김김김 20143667 김김김 20143668 김김김

Upload: gyubeom-choi

Post on 23-Nov-2015

25 views

Category:

Documents


1 download

TRANSCRIPT

EE505 Exp2 Week3. Queue Simulation2014 Spring Semester EE505

Exp2 Week3Queue SimulationFinal Report

Electrical Engineering20143084 20143667 20143668

Objective It is possible to build a queuing model between arrival and departure of packets in a server or servers. An aforementioned model can be explained by M/M/1 queuing model whose arrival and service rate have exponential distribution. Therefore, we need to understand why this model is proper to describe its characteristics. And then examinethoroughly its attributes by gathering and analyzing data in MATLAB. BackgroundIn order to comprehend the meaning of M/M/1 Queuing System, we need to understand following theories above all.Kendalls NotationBefore starting the investigations of our simulation result let us introduce a notation originated by Kendall to describe a queuing system.Let us denote a system byA / B / m / K / n/ D,where A: distribution function of the inter-arrival times, B: distribution function of the service times, m: number of servers, K: capacity of the system, the maximum number of customers in the system including the one being serviced, n: population size, number of sources of customers, D: service discipline. Exponentially distributed random variables are notated by M, meaning Markovain or memoryless.Furthermore, if the population size and the capacity are infinite, the service discipline is FIFO, and then they are omitted.Hence M/M/1 denotes a system with Poisson arrivals, exponentially distributed service times and a single server. M/G/m denotes an m-server system with Poisson arrivals and generally distributed service times. M/M/r/K/n stands for a system where the customers arrive from a finite-source with n elements where they stay for an exponentially distributed time, the service times are exponentially distributed, the service is carried out according to the requests arrival by r severs, and the system capacity is K.Poisson ProcessThe M/M/1 system is made of a Poisson arrival, one exponential (Poisson) server, FIFO (or not specified) queue of unlimited capacity and unlimited customer population. Note that these assumptions are very strong, not satisfied for practical systems (the worst assumption is the exponential distribution of service duration - hardly satisfied by real servers). Nevertheless the M/M/1 model shows clearly the basic ideas and methods of Queuing Theory. Next two chapters summarize the basic properties of the Poisson process and give derivation of the M/M/1 theoretical model.Poisson ProcessThe Poisson process satisfies the following assumptions, where P[x] means "the probability of x":1) P[one arrival in the time interval , for ] = h, where l is a constant. 2) P[more than one arrivals in the interval , for ] 3) The above probabilities do not depend on t ("no memory" property = time independence = stationarity).Let = P[n arrivals in the time interval (0, t)]. Using the above assumptions 1) and 2), it is possible to express the probability , : ( n arrivals by t, no more arrival or n-1 arrivals by t, one more arrival) ( no arrival by t, no more arrival) (1)The equations (1) may be written in this way:, (2)Because of small h the terms at the left sides of (2) may be considered as derivatives:, (3)Equations (3) represent a set of differential equations. To solve them lets start by p0(t):(to prove it, compute the derivative of p0(t) and compare with (3) )Using p0(t) it is possible to compute p1(t):(prove by computing the derivative and inserting to (3) with p0(t) )Or generally (can be proved by mathematical induction):(4)Because of the assumption 3) the formula (4) holds for any interval (s, s+t), in other words the probability of n arrivals during some time interval depends only on the length of this time interval (not on the starting time of the interval).Number of arrivals during some time interval is a discrete random variable associated with the Poisson process. Having the probabilities of the random values - (4), it is possible to find the usual parameters of the random variable . Let be the mean (average) value of the random variable x:

(5) gives the interpretation of the constant , that is the average number of arrivals per time unit. Thats why the is called Arrival rate.Another random variable associated with the Poisson process is the random interval between two adjacent arrivals. Let x be the random interval. To find its distribution, lets express the Distribution function F(x):= P[interval < x] = P[at least one arrival during the interval x] = Because the interval is a continuous random variable, it is possible to compute the Probability density as a derivative of the Distribution function:

These two functions define the probability distribution: (6)The distribution (6) is called Exponential Distribution. Its parameters are:(7)

(7) gives another interpretation of the constant .Traffic ratio Another very important parameter of queuing systems is the ratio of the arrival and the service rates called Utilization factor.(8)The value of shows how "busy" is the server. It is obvious, that for the queue will grow permanently.

The System M/M/1The M/M/1 system is made of a Poisson arrival (Arrival rate ), one exponential server (Service rate ), unlimited FIFO (or not specified queue), and unlimited customer population. Because both arrival and service are Poisson processes, it is possible to find probabilities of various states of the system, that are necessary to compute the required quantitative parameters. System state is the number of customers in the system. It may be any nonnegative integer number. Let = P[n customers in the system at time t]. Like with the Poisson process, by using the assumptions 1) and 2), it is possible to express the probability in this way: (n customers at t, no came, no left) + (n customers at t, one came, one left) + (n-1 customers at t, one came, no left) + (n+1 customers at t, no came, one left ) + (no customer at t, no came) (one customer at t, no came, one left) Figure 1]The transition diagram of a birth/death process looks like this diagram.

(9)The above equations may be written in the following way, where the terms with are omitted because they are relatively very small ( ):

Because of small h the terms at the left sides of (10) may be considered as derivatives:

Equations (11) represent a set of differential equations called Kolmogorov Differential Equations. Their solution is a set of equations showing how each probability changes with time. Fortunately we actually do not need these functions. Because of the third assumption (stationarity) after some transition period the system will become stable. Of course the state will permanently change, but the probabilities of various numbers of customers in the system will be constant. So the functions become constants . Constant functions have zero derivatives, so the set (11) becomes a set of algebraic equations for the stable state:

By dividing the equations (12) by we get this set of equations that contain the only parameter - the utilization factor:

In the set (15) is expressed by. By inserting and to the equation for , we get:

Similarly and may by used to express , etc. which gives the general formula for :

The value can be computed by using the obvious requirement, that the sum of all probabilities must be equal to 1: giving: (14)In (14) the sum of geometric progression has been used. From (14) it is also obvious that the utilization factor must be less than 1, otherwise the sum of probabilities would not be 1 (not even limited). Inserting (14) to (13) gives the general formula for:

The equations (15) represent a very important result used later to obtain all the characteristics of the M/M/1 system. The relatively simple derivation of (15) was enabled by the Poisson process assumptions used when expressing the probabilities in (9). The equations (15) may be used directly to express these probabilities:P[service idle] = P[not queuing on arrival] = = 1 - = 1 - / P[service busy] = P[queuing on arrival] = 1 = = / P[n customers in the system] = = P[n or more customers in the system] = P[less than n customers in the system] = The derivation of P[n or more customers in the system]:

Now the formula (15) will be used to derive quantitative characteristics of the M/M/1 system. (15) actually represents a distribution of a discrete random variable Number of customers in the system (probabilities of all possible random values). So it is possible to compute the mean value, that is the average number of customers in the system:

In (16) the formula for geometric progression has been used. This formula gives us the information to compute average queue length for M/M/1 queuing system.

Result & analysisPart1We conducted the simulation of Queue with some fixed conditions that are described as followings. Average Service Time : second. Customer Arrival Rate : =[0.5 0.9] arrival per second (with 0.1 interval). Confidence Level = . Number of simulation Runs = verse Average Queue length except the customers in service time

This overlap graph consists of simulation value and expected theoretical value graph. We can see former value as dot having red color and latter value as line graph having blue color. In addition, the error bar graph shows the margin of error of simulation value. We can see average queue length becoming large as increase. Its natural that this graph looks like monotonically increasing. As we know, the value of is customer arrival rate. Namely, it means that the more value has, the more customers arrive. Moreover, under the condition of fixed =1, the capacity of server cannot increase. Therefore, these conditions have the average queue length drive to increase. The theoretical value written in lecture material on page 7 includes the customer in service. Therefore, an immediate comparing with average queue length is not meaningful. The theoretical average queue length can be derived from littles result.For an M/M/1 queue, . The average of service time is (For exponential distribution, For any queuing system, is the average number of customer in the system. is the average arrival rate of customers to the system. is the average amount of time spent in the system by a customer., , , is the average of service time. is the average waiting time. is the average of queue length.Therefore, we can compare the results derived from the simulation with calculated theoretical value by using . Meanwhile, we can define the margin of error as below.Margin of errorBecause already knowing and degree of freedom, we can calculated from the student T-distribution. In addition, sample standard deviation also can be derived easily from the samples.

In case 20 simulation runs, the margin of error was measured as below table.0.50.60.70.80.9

The margin of error0.04790.10210.21380.56891.905

If the margin of error needs to be less then current value conducting, we should increase the number of simulation runs. When 30 more simulation conducting than before, we can see that the margin of error is less than 1.0.0.50.60.70.80.9

The margin of error0.02730.04710.13620.29440.9739

Time verse Queue size (Stair Graph) when

Figure 2] Queue size graph when

This result simulated conditions taking and 50 departures. The graph shows the average queue length according to time increasing. Though the theoretical average queue length is fixed, we can see that the shape is fluctuating in interval. Moreover, the queue length does not diverge because utilization factor is less than 1.0 verse Average waiting time (both M/M/1 & M/D/1)Figure 3] M/M/1 Queue

Figure 4] M/D/1 Queue

In order to compare measured values with thoeretical value, we need to find out the formula about average waiting time in case M/M/1 and M/D/1 queue. These two formula can be easily derived from Littles Result and Pollaczek-Khinchin formula. For M/M/1 queue

For M/D/1 queue

The following table shows the theoretical value for each case from to with 0.1 interval.0.50.60.70.80.9

M/M/1 queue1.00001.50002.33334.00009.0000

M/D/1 queue0.50000.75001.16672.00004.5000

From above table, we can see the average waiting time value of M/D/1 queue is less than that of M/M/1. Though these cases of average waiting time value is same, the distribution of each case is entirely different. M/D/1 queue has fixed service time, while M/M/1 queue has exponential distribution with value. From the CDF of exponential distribution graph, we can comprehend why these differences occurred. In case of , the probability over 1 second is a quite considerable value. Therefore, the average waiting time of M/D/1 queue is less than that of M/M/1 queue when average service time is same.Figure 5] The CDF of exponential distribution with

Demo QuestionsExplain about Littles ResultThe number in system forms a stochastic process. Its average value over a long period of time t can be calculated by dividing the shaded area in the figure by the length of the period . On average, each customer contributes to the area by the amount The average number of customers arriving in interval is . The area is thus .It is very straightforward result. As we know, we also can calculate average wait time by using this result and pollaczek-khinchin formula.

Explain about M/M/K/K queuing systemKendalls Notation for QueuesA/B/C/D/EIt is shorthand notation where A, B, C, D, E describe the queue and can be applicable to a large number of simple queuing scenarios. A: Inter-arrival time distributionM: exponentialD: deterministicEk: Erlangian (order k)G: general

D deterministic

Ek Erlangian (order k)

G general

B: Service time distribution C: Number of servers D: Maximum number of jobs that can be there in the system (waiting and in service)Default for infinite number of waiting positions E: Queueing Discipline (FCFS, LCFS, SIRO etc.) Default is FCFSTherefore, M/M/K/K means Inter-arrival time and service time distribution are exponential and the system has K servers and finite waiting room for K customers.

Explain about Memoryless ProperyIn probability and statistics, memorylessness is a property of certain probability distributions: the exponential distributions of non-negative real numbers and the geometric distributions of non-negative integers.The memoryless property makes it easy to reason about the average behavior of exponentially distributed items in queuing systems. Suppose were observing a stream of events with exponentially distributed inter-arrival times. Because of the memoryless property, the expected time until the next event is always , no matter how long weve been waiting for a new arrival to occur.This behavior is a bit counterintuitive. We might expect that arrivals get more likely the longer we wait. For example, if the bus is supposed to come every ten minutes, and we have been waiting for nine minutes without seeing a bus, we expect that the next bus should be along very soon. If the time between bus arrivals is exponentially distributed, however, the memoryless property tells us that our waiting time no matter how long its been is of no use in predicting when the next bus will arrive. Memory-less Property of the Exponential An exponential random variableXhas the property that the future is independent of the past"i.e. the fact that it hasn't happened yet, tells us nothing about how much longer it will take before it does happen. In mathematical terms

Proof:

Memory-less Property of the Geometric

Explain about Show the relationship of waiting, system, and service time.at(2)

For M/M/1 queue, this system can deal with only one packet during service time because one server can accept one packet only. If the server have been processing (n-1)th packet when n-th packet arrived, the n-th packet should wait for the service until (n-1)th packet finish. Therefore, we can define the relation ship of waiting time, system, and service time as following forms.

Explain about Class of service, Priority with two Queue and on server and How does it work?For practical case, the weights of all packets are not same. Some kinds of packets may need to be processed with higher priority than the others above all. In order to handle these packets, the system has to the policy describing which one is more important. For example, if there are two kind of queue for video streaming packets and packets for file download, the system should have higher priority to video packets for real time communication than the other. Unless this policy ensure, the end-user using this service may often suffer from bad quality of service. Moreover, the queue size of system is not infinity so we should concern this characteristic when we design the system having queue. If the queue overflow occurs, we cannot recover the lost packets. Therefore, we make sure when impending overflow, the queue nearly full of packets should be handled above everythingelse.Figure 4] The system having two kinds of classes.

Explain about Pollaczek-Khinchin FormulaIn queuing theory, a discipline within the mathematical theory of probability, the PollaczekKhinchin formula states a relationship between the queue length and service time distribution Laplace transforms for an M/G/1 queue (where jobs arrive according to a Poisson process and have general service time distribution). The term is also used to refer to the relationships between the mean queue length and mean waiting/service time in such a model. For an M/G/1 queue, the average queue length is

where that is called utilization and should be in under condition in order to prevent from growing permanently.

For an M/M/1 queue, the standard deviation which can be easily calculated. We already know the formula of variance and mean for exponential distribution: (when the system has the average rate So, we can have these formula arranged neatly as following forms.

In similar manner again, we can also derive for an M/D/1 queue case.For an M/D/1 queue, the variance of service time is 0 because the service time is deterministic.

As mentioned earlier, we can also derive the relation ship of waiting, system, and service time using this result and littles result.

Explain about What is the meaning of the Event driven method in this experimentFor this experiment, the event driven method is preferred. Actually, there are two methods to get results. The one way, we have to pick all of arrival and service time in advance. In this case, we need to check all of intervals whether packets are wait for service or not. Moreover, we cannot help sampling for this interval because time is not countable. So, some terrible case in which we miss change of queue length can happen when there are variations in short time interval that is small then sampling time. The following graph shows the problem of sampling.Queue length is changing suddenly from 9 to 6.The deviation of queue length must occur with increments of 1.

Figure 6] this graph shows a problem of sampling method.

But, the other is an aforementioned way the event driven method. Under this way, the simulation of queue in matlab can be working like actual queue in which the packets come in one by one. In this manner, we can easily calculate the relationship of waiting, system and service time by just comparing latter packet with former packet. When current packet arrives but need to wait for service, we just add 1 to the current queue length and also need to save this time when this variation happened. Besides, we should subtract 1 from the queue length if that of length is over 0 whenever the service time of packets finish. Eventually, we can plot the queue length graph like as [Figure 2] by using these collected data.

IV. References

http://en.wikipedia.org/wiki/Little's_lawhttp://en.wikipedia.org/wiki/Memorylessnesshttp://pages.cs.wisc.edu/~dsmyers/cs547/http://en.wikipedia.org/wiki/Pollaczek%E2%80%93Khinchine_formulaSztrik, Dr. Jnos. Basic Queueing Theory . University of Debrecen, Faculty of Informatics.http://www.mathcs.emory.edu/~cheung/Courses/558/Syllabus/00/queueing/birth-death.html

V. Appendix. Source CodeThe followings are our source codes.mm1.mExplanation

function [wait_time_avg, n_average, queue_average] = mm1(lambda, mu, n_departures, display) at(1) = -1/lambda * log(1- rand() ); st(1) = -1/mu * log(1-rand() ); ft(1) = at(1) + st(1);

last_pt=1; u=2; time = 0; q_length = 0;

time_packet = [0 at(1)]; numofpacket = [0 1];

while(1) at(u) = at(u-1) -1/lambda * log(1-rand()); st(u) = -1/mu * log(1-rand()); ft(u) = max( ft(u-1) + st(u), at(u) + st(u) );

if( at(u) > ft(last_pt) ) current_pt = last_pt; while(1) if(ft(current_pt) > at(u) ) last_pt = current_pt; break; end time_packet(length(time_packet)+1) = ft(current_pt); numofpacket(length(numofpacket)+1) = max(numofpacket(length(numofpacket))-1,0);

time(length(time)+1) = ft(current_pt); q_length(length(q_length)+1) = max(q_length(length(q_length))-1,0); current_pt = current_pt +1; end end

time_packet = [time_packet at(u)]; numofpacket = [numofpacket numofpacket(length(numofpacket))+1];

if( at(u) < ft(u-1) ) time(length(time)+1) = at(u); q_length(length(q_length)+1) = q_length(length(q_length)) + 1; end

u = u+1;

if( u==n_departures + 1) for p = last_pt:n_departures time = [time ft(p)]; q_length = [q_length max(q_length(length(q_length))-1, 0)]; time_packet = [time_packet ft(p)]; numofpacket = [numofpacket , max(numofpacket(length(numofpacket))-1, 0)]; end break; end %if end

end

area_sum = 0; for i=1:length(time) if( i+1