//====================================================== file = md1_500.c ===== //= A CSIM simulation of an M/D/1 queueing system = //= - Tallies over 500 ms response time jobs = //============================================================================= //= Notes: 1) Values for lambda and mu are set in the main program = //=---------------------------------------------------------------------------= //= Example execution: = //= = //= ============================================================= = //= == *** CSIM M/D/1 queueing system simulation *** == = //= ============================================================= = //= = Lambda = 1.245000 cust/sec = //= = Mu = 5.000000 cust/sec = //= ============================================================= = //= = Total CPU time = 3.135000 sec = //= = Total sim time = 2579604.750945 sec = //= = Total completions = 3211059 cust = //= =------------------------------------------------------------ = //= = >>> Simulation results - = //= =------------------------------------------------------------ = //= = Utilization = 24.895736 % = //= = Mean num in system = 0.290157 cust = //= = Mean response time = 0.233098 sec = //= = Mean service time = 0.200000 sec = //= = Mean throughput = 1.244787 cust/sec = //= = Percent over 500ms = 1.476616 % = //= ============================================================= = //=---------------------------------------------------------------------------= //= Build: standard CSIM build = //=---------------------------------------------------------------------------= //= Execute: md1_500 = //=---------------------------------------------------------------------------= //= Author: Ken Christensen = //= University of South Florida = //= WWW: http://www.csee.usf.edu/~christen = //= Email: christen@csee.usf.edu = //=---------------------------------------------------------------------------= //= History: KJC (07/10/13) - Genesis = //= KJC (07/14/13) - Clean-up and modified to run for NUM_JOBS = //============================================================================= //----- Includes -------------------------------------------------------------- #include // Needed for printf() #include "csim.h" // Needed for CSIM stuff //----- Defines --------------------------------------------------------------- #define NUM_JOB 3211058 // Number of jobs to simulate //----- Globals --------------------------------------------------------------- FACILITY Server; // Declaration of CSIM Server facility EVENT DoneEvent; // Done event int OverCount; // Over 500ms counter //----- Prototypes ------------------------------------------------------------ void generate(double lambda, double mu); // Customer generator void queue1(double service_time, double org_time); // Single server queue //============================================================================= //== Main program == //============================================================================= void sim(void) { double lambda; // Mean arrival rate (cust/sec) double mu; // Mean service rate (cust/sec) // Create the simulation create("sim"); // CSIM and other initializations Server = facility("Server"); DoneEvent = event("Done event"); OverCount = 0; // Parameter initializations (per project statement) lambda = 1.245; mu = 5.0; // Initiate generate function and hold for SIM_TIME generate(lambda, mu); wait(DoneEvent); // Output results printf("============================================================= \n"); printf("== *** CSIM M/D/1 queueing system simulation *** == \n"); printf("============================================================= \n"); printf("= Lambda = %f cust/sec \n", lambda); printf("= Mu = %f cust/sec \n", mu); printf("============================================================= \n"); printf("= Total CPU time = %f sec \n", cputime()); printf("= Total sim time = %f sec \n", clock); printf("= Total completions = %d cust \n", completions(Server)); printf("=------------------------------------------------------------ \n"); printf("= >>> Simulation results - \n"); printf("=------------------------------------------------------------ \n"); printf("= Utilization = %f %% \n", 100.0 * util(Server)); printf("= Mean num in system = %f cust \n", qlen(Server)); printf("= Mean response time = %f sec \n", resp(Server)); printf("= Mean service time = %f sec \n", serv(Server)); printf("= Mean throughput = %f cust/sec \n", tput(Server)); printf("= Percent over 500ms = %f %% \n", 100.0 * OverCount / completions(Server)); printf("============================================================= \n"); } //============================================================================= //== Function to generate Poisson customers == //============================================================================= void generate(double lambda, double mu) { double interarrival_time; // Interarrival time to next send double service_time; // Service time for this customer create("generate"); // Loop forever to create jobs while(1) { // Pull an interarrival time and hold for it interarrival_time = exponential(1.0 / lambda); hold(interarrival_time); // Pull a service time and then send the customer to the queue service_time = 1.0 / mu; queue1(service_time, clock); } } //============================================================================= //== Function for single server queue == //============================================================================= void queue1(double service_time, double org_time) { create("queue1"); // Reserve, hold, and release server reserve(Server); hold(service_time); release(Server); // Tally response times over 500 ms if ((clock - org_time) > 0.500) OverCount++; // If completions is NUM_JOB then set done event if (completions(Server) >= NUM_JOB) set(DoneEvent); }