You are on page 1of 6

Name: 

 Pritam Das                       Roll Number: 17ETCS002130       

Laboratory 7, 8, 9 
Title of the Laboratory Exercise: Simulation of Two‐Server Queuing System 
1. Introduction and Purpose of Experiment 
This lab shows how to model a single‐queue multiple‐server system. In the notation, the M 
stands  for  Markovian;  M/M/s  means  that  the  system  has  a  Poisson  arrival  process,  an 
exponential service time distribution, and s (multiple) server. Queuing theory provides exact 
theoretical  results  for  some  performance  measures  of  an  M/M/s  queuing  system  and  this 
model makes it easy to compare empirical results with the corresponding theoretical results. 
  In  simulating  real  world  systems  on  computer  like  a  Multi‐channel  queue  or  Able 
Baker problem consisting  of a Two servers for serving the two queues of customers.so we 
have its following simulation along with the able baker problem with it. 
Structure 
The model includes the components listed below: 
 Time Based Entity Generator block: It models a Poisson arrival process by generating entities 
(also known as "customers" in queuing theory). 
 Exponential  Interarrival  Time  Distribution  subsystem:  It  creates  a  signal  representing  the 
interarrival times for the generated entities. The interarrival time of a Poisson arrival process 
is an exponential random variable. 
 FIFO Queue block: It stores entities that have yet to be served. 
 Multiple Server block: It models a servers whose service time has an exponential distribution. 
 
 
2. Aim and Objectives 
Aim 

 To develop concurrent programs for Simulation of Two‐Server Queuing System 
Objectives 
At the end of this lab, the student will be able to 
 Simulate different problems on multiple Server Queuing System 
 Create Java simulation class hierarchy by implementing sub‐classes of the Thread class 
to simulate simple M/M/s queue 
 
3. Experimental Procedure 
i. Analyse the problem statement 
ii. Design  an  algorithm  for  the  given  problem  statement  and  develop  a 
flowchart/pseudo‐code 
iii. Implement the algorithm in java language 
iv. Compile the java program 
v. Test the implemented program 
vi. Document the Results 
vii. Analyse and discuss the outcomes of your experiment 
 
Name:  Pritam Das                       Roll Number: 17ETCS002130       

4. Questions 
Implement a Simulation of Multiple Server Queuing System for given problem 
Structure of model should include: 
a. Time Based Entity Generator  
b. Exponential Interarrival Time Distribution subsystem. 
c. FIFO Queue  
d. Multiple Server  
5. Calculations/Computations/Algorithms 

1. procedure Simulation of Two‐Server Queuing System message by 3 different 
threads 
2. there are 2 Servers S1 and S2, priority:= S1 > S2 
3. begin main 
4.   while(number of Customer) 
5.   serviceCust entered the Server 
6.   upcomingCust will enter the Server   
7.     if S1 is free and S2 is free then 
8.       Customer will enter S1 
9.       if upcomingCust then serviceCust:=upcomingCust 
10.       startService for serviceCust 
11.       runService for serviceCust 
12.       endService for serviceCust 
13.     end if  
14.     else if S1 is free and S2 is busy then 
15.       Customer will enter S1 
16.       if upcomingCust then serviceCust:=upcomingCust 
17.       startService for serviceCust 
18.       runService for serviceCust 
19.       endService for serviceCust 
20.     end else if 
21.     else if S1 is busy and S2 is free then 
22.       Customer will enter S2 
23.       if upcomingCust then serviceCust:=upcomingCust 
24.       startService for serviceCust 
25.       runService for serviceCust 
26.       endService for serviceCust 
27.     end else if 
28.     else then 
29.       Customer will wait 
30.       goto while  
31.     end else 
32.   End while 
33. end main 
34. end procedure  
6. Presentation of Results 

import java.io.BufferedReader; 
import java.io.InputStreamReader; 
import java.util.Random; 
/** 
 * csLab3New 
 * Author : Pritam Das 
 * Registration Number :17ETCS002130 
 */ 
public class csLab3New { 
    public static void main(String[] args) { 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
Name:  Pritam Das                       Roll Number: 17ETCS002130       

        Random r = new Random(0); 
        int i, j; 
        int arrivaltime[] = { 1, 2, 3, 4 }; 
        double arrivalprob[] = { 0.25, 0.40, 0.20, 0.15 }; 
        double cumarrival[] = new double[arrivalprob.length]; 
        int arrivalrda[] = new int[arrivalprob.length]; 
        int ableservice[] = { 2, 3, 4, 5 }; 
        double ableprob[] = { 0.30, 0.28, 0.25, 0.17 }; 
        double cumable[] = new double[ableprob.length]; 
        int ablerda[] = new int[arrivalprob.length]; 
        int bakerservice[] = { 3, 4, 5, 6 }; 
        double bakerprob[] = { 0.35, 0.25, 0.20, 0.20 }; 
        double cumbaker[] = new double[bakerprob.length]; 
        int bakerrda[] = new int[arrivalprob.length]; 
        int randomarrival[] = new int[60 / ableservice[0]]; 
        int randomservice[] = new int[60 / ableservice[0]]; 
        int arrival[] = new int[60 / ableservice[0]]; 
        int service[] = new int[60 / ableservice[0]]; 
        int interarrival[] = new int[60 / ableservice[0]]; 
        int serviceable[] = new int[60 / ableservice[0]]; 
        int servicebaker[] = new int[60 / ableservice[0]]; 
        int ablestart[] = new int[60 / ableservice[0]]; 
        int bakerstart[] = new int[60 / ableservice[0]]; 
        int ableend[] = new int[60 / ableservice[0]]; 
        int bakerend[] = new int[60 / ableservice[0]]; 
        int ableprocess[] = new int[60 / ableservice[0]]; 
        int bakerprocess[] = new int[60 / ableservice[0]]; 
        int qtime[] = new int[60 / ableservice[0]]; 
        int ttime[] = new int[60 / ableservice[0]]; 
        int tempable = 0, tempbaker = 0; 
        float ableavgser = 0, bakeravgser = 0, waitingcust = 0, ttq = 0, tts = 0; 
        for (i = 0; i < arrivaltime.length; i++) { 
            if (i == 0) { 
                cumarrival[i] = arrivalprob[i]; 
                arrivalrda[i] = (int) (cumarrival[i] * 100d); 
            } else { 
                cumarrival[i] = cumarrival[i ‐ 1] + arrivalprob[i]; 
                arrivalrda[i] = (int) (cumarrival[i] * 100d); 
            } 
        } 
        for (i = 0; i < ableservice.length; i++) { 
            if (i == 0) { 
                cumable[i] = ableprob[i]; 
                ablerda[i] = (int) (cumable[i] * 100d); 
            } else { 
                cumable[i] = cumable[i ‐ 1] + ableprob[i]; 
                ablerda[i] = (int) (cumable[i] * 100d); 
            } 
        } 
        for (i = 0; i < bakerservice.length; i++) { 
            if (i == 0) { 
                cumbaker[i] = bakerprob[i]; 
                bakerrda[i] = (int) (cumbaker[i] * 100d); 
            } else { 
                cumbaker[i] = cumbaker[i ‐ 1] + bakerprob[i]; 
                bakerrda[i] = (int) (cumbaker[i] * 100d); 
            } 
        } 
        randomservice[0] = (int) (Math.random() * 100d); 
        for (i = 1; i < (60 / ableservice[0]); i++) { 
            randomarrival[i] = (int) (Math.random() * 100d); 
            randomservice[i] = (int) (Math.random() * 100d); 
        } 
        for (i = 0; i < (60 / ableservice[0]); i++) { 
            for (j = 0; j < arrivalrda.length; j++) { 
                if (randomarrival[i] == 0) { 
Name:  Pritam Das                       Roll Number: 17ETCS002130       

                    arrival[i] = arrivaltime[arrivaltime.length ‐ 1]; 
                    break; 
                } 
                if (randomarrival[i] <= arrivalrda[j]) { 
                    arrival[i] = arrivaltime[j]; 
                    break; 
                } 
            } 
            interarrival[i] = interarrival[i ‐ 1] + arrival[i]; 
        } 
        for (i = 0; i < (60 / ableservice[0]); i++) { 
            for (j = 0; j < ablerda.length; j++) { 
                if (randomservice[i] == 0) { 
                    serviceable[i] = ableservice[ableservice.length ‐ 1]; 
                    break; 
                } 
                if (randomservice[i] <= ablerda[j]) { 
                    serviceable[i] = ableservice[j]; 
                    break; 
                } 
            } 
            for (j = 0; j < bakerrda.length; j++) { 
                if (randomservice[i] == 0) { 
                    serviceable[i] = bakerservice[bakerservice.length ‐ 1]; 
                    break; 
                } 
                if (randomservice[i] <= bakerrda[j]) { 
                    serviceable[i] = bakerservice[j]; 
                    break; 
                } 
            } 
        } 
        for (i = 0; i < (60 / ableservice[0]); i++) { 
            if (tempable <= interarrival[i]) { 
                ablestart[i] = interarrival[i]; 
                ableend[i] = ablestart[i] + serviceable[i]; 
                ableprocess[i] = serviceable[i]; 
                tempable = ableend[i]; 
                ttime[i] = ableprocess[i] + qtime[i]; 
            } 
            if (tempbaker <= interarrival[i]) { 
                bakerstart[i] = interarrival[i]; 
                bakerend[i] = bakerstart[i] + servicebaker[i]; 
                bakerprocess[i] = servicebaker[i]; 
                tempbaker = bakerend[i]; 
                ttime[i] = bakerprocess[i] + qtime[i]; 
            } else if ((interarrival[i] < tempable) && (tempable <= tempbaker)) { 
                ablestart[i] = tempable; 
                ableend[i] = ablestart[i] + serviceable[i]; 
                ableprocess[i] = serviceable[i]; 
                qtime[i] = tempable ‐ interarrival[i]; 
                tempable = ableend[i]; 
                ttime[i] = ableprocess[i] + qtime[i]; 
                waitingcust++; 
            } else { 
                bakerstart[i] = tempbaker; 
                bakerend[i] = bakerstart[i] + servicebaker[i]; 
                bakerprocess[i] = servicebaker[i]; 
                qtime[i] = tempbaker ‐ interarrival[i]; 
                tempbaker = bakerend[i]; 
                ttime[i] = bakerprocess[i] + qtime[i]; 
                waitingcust++; 
            } 
        } 
        for (i = 0; (interarrival[i] <= 60) && (i < (60 / ableservice[0])); i++) { 
            ableavgser = ableavgser + ableprocess[i]; 
Name:  Pritam Das                       Roll Number: 17ETCS002130       

            bakeravgser = bakeravgser + bakerprocess[i]; 
            ttq = ttq + qtime[i]; 
            tts = tts + qtime[i]; 
        } 
        float totalcust = i; 
        System.out.println("No.\tRDA.\tIARR.\tARR.\tRDS.\tASTAT.\tAPRO" + "\tAEND.\tBSTAT.\
tBPRO.\tBEND.\tTSQ.\tTIS"); 
        for (i = 0; (interarrival[i] <= 60) && (i < (60 / ableservice[0])); i++) { 
            System.out.println((i + 1) + "\t" + randomarrival[i] + "\t" + arrival[i] + "\t"
 + interarrival[i] + "\t" 
                    + randomservice[i] + "\t" + ablestart[i] + "\t" + ableprocess[i] + "\t"
 + ableend[i] + "\t" 
                    + bakerstart[i] + "\t" + bakerprocess[i] + "\t" + bakerend[i] + "\t" + 
qtime[i] + "\t" + ttime[i]); 
        } 
        System.out.println("PERFORMANCE OF THE SYSTEM IS AS FOLLOWS:"); 
        System.out.println("AVERAGE SERVICE TIME OF ABLE:" + (ableavgser / totalcust)); 
        System.out.println("AVERAGE SERVICE TIME OF BAKER:" + (bakeravgser / totalcust)); 
        if (waitingcust > 0) 
            System.out.println("AVERAGE WAITING TIME OF CUSTOMER:" + (ttq / totalcust)); 
        System.out.println("PROBABILITY OF WAITING:" + (waitingcust / totalcust)); 
        System.out.println("AVERAGE TIME SPENT BY CUSTOMER IN THE SYSTEM:" + (tts / totalcu
st)); 
    } 

Fig: Code Implementation

 
Fig: Code Execution
Name:  Pritam Das                       Roll Number: 17ETCS002130       

7. Analysis and Discussions 
Keeping in mind the end goal to show queueing frameworks, we first should be more exact about what 
comprises a queueing framework. The three essential components basic to all queueing frameworks are: 

 Arrival Process: Any lining framework must work on something − clients, parts, pa ents, orders, 
and  so  forth.  We  nonexclusively  term  these  elements.  Before  elements  can  be  prepared  or 
subjected  to  pausing,  they  should  initially  enter  the  framework.  Contingent  upon  the  earth, 
elements can arrive easily or in a capricious manner. They can arrive each one in turn or in clusters 
(e.g., transport loads or groups). They can arrive freely or as per some sort of connection. 
 Service Process: Once substances have entered the framework they should be served. The physical 
importance  of  "service"  relies  upon  the  framework.  Clients  may  experience  the  checkout 
procedure.  Parts  may  experience  machining.  Patients  may  experience  restorative  treatment. 
Requests might be filled. Et cetera. From a demonstrating stance, the operational attributes of 
service matter more than the physical qualities. In particular, we care about whether service times 
are long or short, and whether they are normal or exceptionally factor. 
 Queue: The third required segment of a queueing framework is a queue, in which substances sit 
tight for benefit. The most straightforward case is a boundless queue which can oblige any number 
of clients. In any case, numerous frameworks (e.g., telephone trades, web servers, call focuses), 
have confines on the quantity of elements that can be in queue at some random time. Landings 
that come when the queue is full are rejected (e.g., clients get a bustling sign when attempting to 
dial into a call focus). 
The simulation proceeds in a manner similar to single server single queue, except that it is more complex 
because  of  the  two  servers.  A  simplifying  rule  is  that  Able  gets  the  customer  if  both  carhops  are  idle. 
Perhaps, Able has seniority. 
The problem is to find how well the current arrangement is working. To estimate the system measures of 
performance, a simulation of 1 hour of operation is made. A longer simulation would yield more reliable 
results, but for purposes of illustration a l‐hour period has been selected. 
8. Conclusions  
Here we have done the code for single server single queue which shows [Average service time for Able and 
Baker, Average waiting time, Average time spent by customer in system (system utilization)]. 
9. Comments  
  1. Limitations of Experiments 
a. We needed to consider both cases of the server, if there is neglection in the cases then process may 
enter into the server before a process is already completed. 
b. Since there are two servers, if there is a case that if one customer does not arrive and a server completed 
a process then the server has to sit idle until and unless the customer arrives. 
  2. Limitations of Results 
a. Since there uses of so many arrays then space consumption is too high and the space is dynamically 
allocated. 
b. As previously I said that there are situations when the system is idle this means delay losses are also 
there. 
  3. Learning happened 
We learned how services are process when two servers are involved. 
  4. Recommendations 
Could have been done using structure if we were doing it using C or C++. 

You might also like