Exm # for Computer Simultion Spring 005 >>> SOLUTION <<< Welcome to exm # in Computer Simultion. Red ech problem crefully. There re eight required problems (ech worth.5 points) nd one extr credit problem worth 0 points. Plese write your nswers in the spce provided. You my hve clcultor nd one 8.5 x inch sheet of pper with you. On this sheet you my hve nything you wnt (definitions, formuls, flow chrts, etc.) in your hndwriting on both sides of the pge. You my not hve photocopies or printed text on your formul sheet. Plese nswer ech problem on seprte sheet of pper. Good luck!!! Problem # ) Precisely define model nd give three resons why we build nd experiment with models. A model is representtion (physicl, logicl, or functionl) tht mimics nother object under study. The gol in building model is to be ble to predict the behvior of the originl object. Building nd studying models is usully cheper nd sfer thn studying the rel object. Sometimes it is not possible to study the ctul object (when it does not exist) nd model is thus required. b) Describe cpcity plnning. Wht re the inputs to the process nd wht re the outputs? Cpcity plnning is process where the inputs re worklod evolution, system prmeters, nd desired service nd the outputs re sturtion point nd costeffective lterntives. c) Define computer simultion. Computer simultion is the discipline of designing model of n ctul or theoreticl physicl system, executing the model on computer, nd nlyzing the execution results. d) Wht re some of the key performnce mesures of interest in IT systems? Response time or dely is the key mesure of interest for most IT systems. Throughput, loss, utiliztion, relibility, nd vilbility re other mesures of interest. Problem # You re responsible for the opertion of three server computers. Every morning you check ech server if it is up or down. The probbility of ny given server being down is p = 0.0 (nd this is independent of the stte of the other servers). Solve for Pr[i servers re down] for i = 0,,, nd 3. Wht is the men number of servers tht re down in the morning? Wht is the vrince? Wht is the stndrd devition? This is binomil distribution. We solve for Pr[ i = 0] = 0 Pr[ i = ] = Pr[ i = ] = Pr[ i = 3] = 3 0 ( 0.0) ( 0.90) ( 0.0) ( 0.90) 3 ( 0.0) ( 0.90) 3 0 3 = 0.79 = 0.43 = 0.07 3 3 3 ( 0.0) ( 0.90) = 0. 00 men = n p = 3 0.0 = 0.30 vr ince = n p q = 3 0.0 0.90 = 0.7 s tn drd _ devition = n p q = 0.596
Problem #3 You re given the following trnsction trce dt (e.g., from dtbse server) where :59:58 is time zero. Time Trnsction size :59:58 00 bytes :00:00 00 :00:0 00 :00:04 00 :00:0 300 :00:3 300 ) Wht is the men interrrivl time? Wht is the men trnsction size? The interrrivl times re,, 3, 6, nd seconds. The men is thus ( + + 3 + 6 + 3) = 3 seconds. The trnsctions sizes re 00, 00, 00, 00, 300, nd 5 6 300 bytes. The men is thus ( 00 00 + 00 + 00 + 300 + 300) = 00 b) Wht is the stndrd devition of trnsction size? + bytes. S tn drd _ devition = 6 ( 00 00) + ( 00 00) + ( 00 00) + ( 00 00) + ( 300 00) + ( 300 00) ) = 8. 65 c) Plot histogrm of the trnsction size. Rtio 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0. 0. 0 0 00 00 300 400 Trnsction size (bytes) d) Write C function tht returns vlue tht is empiriclly distributed bsed on the trce dt for trnsction size. You my ssume tht you cn cll function rnd_vl() tht will return uniformly distributed rndom vrible between 0 nd. The function is: double emp_trnsction_size(void) double z; z = rnd_vl(); if (z < (.0 / 3.0)) return(00.0); if (z < (.0 / 3.0)) return (00.0); return (300.0);
Problem #4 Write C function tht will return Preto distributed rndom vrible with prmeters nd b. The CDF of Preto distribution b is F( x) =. You my ssume tht you cn cll function rnd_vl() tht will return uniformly distributed rndom x vrible between 0 nd. First we need to invert the function to solve for x s follows: b z = x b x x = = z b = z b z Then we cn write the C function s: double preto(double, double b) double z; do z = rnd_vl(); while (z == 0.0); return(b / pow(z, (.0 / ))); Problem #5 Answer the following questions bout queueing theory: ) Describe Kendll nottion A queue is described s A/S/c/k/m where A is the rrivl distribution, S is the service distribution, c is the number of servers, k is the cpcity of the system in number of customers, nd m is the number of customers in the universe. A nd S cn be M for Mrkov, D for deterministic, G for generl, nd others. b) Stte Little s Lw L = λ W for L is the men number in the system, λ is the rrivl rte, nd W is the men wit in the system c) Given λ (rrivl rte), µ (service rte), L (men number in the system), nd W (men wit in the system) show how to solve for Lq (men number in the queue), nd Wq (men wit in the queue) for single server queue. Lq = L ρ where ρ is the system utiliztion, which is rrivl rte divided by service rte ( ρ = λ µ ). ( µ ) Wq = W where µ is the service rte.
Problem #6 For n M/M/ queue, plot the men number of customers in the system (L) for utiliztion of 0.50, 0.60, 0.70, 0.80, 0.90, nd 0.95. ρ For n M/M/ we know tht L = so for the given vlues of utiliztion we compute L ρ s.0,.5,.33, 4, 9, nd 9. We cn then plot: L (men num in system) 0 8 6 4 0 8 6 4 0 0.5 0.6 0.7 0.8 0.9 Utiliztion Problem #7 Attched is mm_mini.c. This is the M/M/ simultion progrm from McDougll nd lso s discussed in clss. Modify the progrm such tht deprting customer hs probbility PR_REDO of immeditely returning to the queue. The vlue of PR_REDO could be set s constnt (e.g., with #define). Your modified mm_mini.c models single server queue with error checking where deprting customer with detected error is immeditely sent bck for re-service. The probbility of deprting customer hving detected error is PR_REDO. See yellow highlighted code on the ttched mm_mini.c progrm. Problem #8 List the bsic components nd give the flowchrt of discrete event simultion. Describe how n event list works. The bsic components re system stte, simultion clock (time), event list, event routine, sttisticl counters, librry routines, report genertor, initiliztion routine, nd min progrm. The flowchrt is Figure 4.4 from Molloy (hnded-out nd/or discussed in clss on Wednesdy 0/09/05).
Extr Credit: (0 points) Write simultion progrm in C for problem #. As with the previous problems, you my ssume tht rnd_vl() exists nd cn be clled. One possible solution is (rnd_vl() is not shown): #include <stdio.h> double rnd_vl(void); void min(void) int totl, i, s, s, s3, sum, count[4]; totl = 000000; count[0] = count[] = count[] = count[3] = 0; for (i=0; i<totl; i++) sum = s = s = s3 = 0; if (rnd_vl() < 0.0) s = ; if (rnd_vl() < 0.0) s = ; if (rnd_vl() < 0.0) s3 = ; sum = s + s + s3; count[sum]++; printf("pr[0 down] = %f \n", (double) count[0] / totl); printf("pr[ down] = %f \n", (double) count[] / totl); printf("pr[ down] = %f \n", (double) count[] / totl); printf("pr[3 down] = %f \n", (double) count[3] / totl); The output from this progrm is: Pr[0 down] = 0.79539 Pr[ down] = 0.476 Pr[ down] = 0.06753 Pr[3 down] = 0.00098 Which mtches (s expected) the theoreticl (nlysis) results from problem #. ---
//===================================================== file = mm_mini.c ===== //= A simple M/M/ queue simultion = //= Notes: = //= = //= This progrm is dpted from "Figure.4" in Simulting Computer = //= Systems, Techniques nd Tools by M. H. McDougll (987) = //=---------------------------------------------------------------------------= //= Build: gcc mm_mini -lm, bcc3 mm_mini.c, cl mm_mini.c = //=---------------------------------------------------------------------------= //= Execute: mm_mini = //=---------------------------------------------------------------------------= //= History: KJC (0/7/99) - Genesis = //----- Include files --------------------------------------------------------- #include <stdio.h> // Needed for printf() #include <mth.h> // Needed for log() //----- Constnts ------------------------------------------------------------- #define SIM_TIME.0e6 // Simultion time #define PR_REDO 0.0 // Probbility to redo deprting customer //----- Function prototypes --------------------------------------------------- double expntl(double x); // Generte exponentil RV with men x double rnd_vl(void); // Generte unif(0,) RV //===== Min progrm ========================================================== void min(void) double end_time = SIM_TIME; // Totl time to simulte double T = 3.0; // Men time between rrivls double Ts =.0; // Men service time double time = 0.0; double t = 0.0; double t = SIM_TIME; long int n = 0; // Simultion time // Time for next event # (rrivl) // Time for next event # (deprture) // Number of customers in the system // Min simultion loop while (time < end_time) if (t < t) time = t; //** Event # (rrivl) // Set time to tht of current event // Increment number of customers in system n++; if (rnd_vl() < PR_REDO) // Test if should redo or not t = time; t = time + expntl(t); if (n == ) // If first customer in system then t = time + expntl(ts); // ssign its deprture time // *** Event # (deprture) time = t; // Set time to tht of current event n--; // Decrement number of customers in system if (n > 0) // If customers in system then t = time + expntl(ts); // ssign next deprture time // If no customers in system then t = end_time; // ssign next deprture to "infinity"
//= Function to generte exponentilly distributed RVs = //= - Input: x (men vlue of distribution) = //= - Output: Returns with exponentil RV = double expntl(double x) double z; // Uniform rndom number from 0 to // Pull uniform RV (0 < z < ) do z = rnd_vl(); while ((z == 0) (z == )); // Inversion formul for exonentil RV return(-x * log(z)); //= Multiplictive LCG for generting uniform(0.0,.0) rndom numbers = //= - x_n = 7^5*x_(n-)mod(^3 - ) = //= - With x seeded to the 0000th x vlue should be 04368065 = //= - From R. Jin, "The Art of Computer Systems Performnce Anlysis," = //= John Wiley & Sons, 99. (Pge 443, Figure 6.) = double rnd_vl(void) const long = 6807; // Multiplier const long m = 47483647; // Modulus const long q = 7773; // m div const long r = 836; // m mod sttic long x = ; // Rndom int vlue (seed is set to ) long x_div_q; // x divided by q long x_mod_q; // x modulo q long x_new; // New x vlue // RNG using integer rithmetic x_div_q = x / q; x_mod_q = x % q; x_new = ( * x_mod_q) - (r * x_div_q); if (x_new > 0) x = x_new; x = x_new + m; // Return rndom vlue between 0.0 nd.0 return((double) x / m);