function main() { /**************************** * Model specific variables * ****************************/ $noNodes = 0; $noStreams = 0; $tech = APPROX; // EXACT $pop = 0; $think = 0.0; /************************ * Initialize the model * ************************/ /* Give model a name */ printf("**** %s ****:\n", $tech == EXACT ? "EXACT" : "APPROX"); printf("%s\t\t%s\t\t%s\t\t%s\t\t%s\n", "POP", "N:w1", "RESP:w1", "N:w2", "RESP:w2"); printf("-----------------------------------------------------------------------------\n"); for ($pop = 1; $pop < 10; $pop++) { PDQ_Init("Test_Exact_calc"); /* Define the workload and circuit type */ $noStreams = PDQ_CreateClosed("w1", TERM, 1.0 * $pop, $think); $noStreams = PDQ_CreateClosed("w2", TERM, 1.0 * $pop, $think); /* Define the queueing center */ $noNodes = PDQ_CreateNode("node", CEN, FCFS); /* Define service demand */ PDQ_SetDemand("node", "w1", 1.0); PDQ_SetDemand("node", "w2", 0.5); /******************* * Solve the model * *******************/ PDQ_Solve($tech); printf("%d\t\t%d\t\t%3.4f\t\t%d\t\t%3.4f\n", $pop, getjob_pop(getjob_index("w1")), PDQ_GetResponse(TERM, "w1"), getjob_pop(getjob_index("w1")), PDQ_GetResponse(TERM, "w2")); } }
function main() { global $job; /**************************** * Model specific variables * ****************************/ $noNodes = 0; $noStreams = 0; $pop = 0; $servers = 2; $s = 0; $w = HOMEPG; $work = array(0 => "stress", 1 => "homepg"); /* stress */ /* homepg */ $time = array(0 => 0.0044, 1 => 0.03); $slave = array(0 => "slave0", "slave1", "slave2", "slave3", "slave4", "slave5", "slave6", "slave7", "slave8", "slave9", "slave10", "slave11", "slave12", "slave13", "slave14", "slave15"); if (PREFORK) { printf("Pre-Fork Model under \"%s\" Load (m = %d)\n", $w == STRESS ? $work[STRESS] : $work[HOMEPG], $servers); } else { printf("Forking Model under \"%s\" Load \n", $w == STRESS ? $work[STRESS] : $work[HOMEPG]); } printf("N\tX\tR\n"); for ($pop = 1; $pop <= 10; $pop++) { PDQ_Init("HTTPd_Server"); $noStreams = PDQ_CreateClosed($work[$w], TERM, 1.0 * $pop, 0.0); $noNodes = PDQ_CreateNode("master", CEN, FCFS); if (PREFORK) { for ($s = 0; $s < $servers; $s++) { $noNodes = PDQ_CreateNode($slave[$s], CEN, FCFS); } PDQ_SetDemand("master", $work[$w], 0.0109); for ($s = 0; $s < $servers; $s++) { PDQ_SetDemand($slave[$s], $work[$w], $time[$w] / $servers); } } else { /* FORKING */ $noNodes = PDQ_CreateNode("forks", CEN, ISRV); PDQ_SetDemand("master", $work[$w], 0.0165); PDQ_SetDemand("forks", $work[$w], $time[$w]); } PDQ_Solve(EXACT); printf("%3.2f\t%3.4f\t%3.4f\n", getjob_pop(getjob_index($work[$w])), PDQ_GetThruput(TERM, $work[$w]), PDQ_GetResponse(TERM, $work[$w])); } }
function exact() { global $streams, $nodes; // extern int global $node; // extern NODE_TYPE * global $job; // extern JOB_TYPE * global $s1, $s2, $s3, $s4; // extern char [] global $qlen; $p = "exact()"; // char * $n0 = 0; // int $n1 = 0; // int $n2 = 0; // int $pop = array(); //int[MAXCLASS] = {0, 0, 0}; /* pop vector */ $N = array(); // int[MAXCLASS] = {0, 0, 0}; /* temp counters */ $sumR = array(); // double[MAXCLASS] = {0.0, 0.0, 0.0}; for ($c = 0; $c < MAXCLASS; $c++) { $pop[$c] = 0; $N[$c] = 0; $sumR[$c] = 0.0; } $c = 0; //int $k = 0; // int if ($streams > MAXCLASS) { printf("Streams = %d", $streams); $s1 = sprintf("%d workload streams exceeds maximum of 3.\n", $streams); errmsg($p, $s1); } for ($c = 0; $c < $streams; $c++) { $pop[$c] = (int) ceil((double) getjob_pop($c)); if ($pop[$c] > MAXPOP1 || $pop[$c] > MAXPOP2) { $s1 = sprintf("Pop %d > allowed:\n", $pop[$c]); $s2 = sprintf("max1: %d\nmax2: %d\n", MAXPOP1, MAXPOP2); errmsg($p, $s1 . $s2); } } /* initialize lowest queue configs on each device */ for ($k = 0; $k < $nodes; $k++) { $qlen[0][0][$k] = 0.0; } /* MVA loop starts here .... */ for ($n0 = 0; $n0 <= $pop[0]; $n0++) { for ($n1 = 0; $n1 <= $pop[1]; $n1++) { for ($n2 = 0; $n2 <= $pop[2]; $n2++) { if ($n0 + $n1 + $n2 == 0) { continue; } $N[0] = $n0; $N[1] = $n1; $N[2] = $n2; for ($c = 0; $c < MAXCLASS; $c++) { $sumR[$c] = 0.0; if ($N[$c] == 0) { continue; } $N[$c] -= 1; for ($k = 0; $k < $nodes; $k++) { $node[$k]->qsize[$c] = $qlen[$N[1]][$N[2]][$k]; $node[$k]->resit[$c] = $node[$k]->demand[$c] * (1.0 + $node[$k]->qsize[$c]); $sumR[$c] += $node[$k]->resit[$c]; } $N[$c] += 1; switch ($job[$c]->should_be_class) { case TERM: if ($sumR[$c] == 0) { errmsg($p, "sumR is zero"); } $job[$c]->term->sys->thruput = $N[$c] / ($sumR[$c] + $job[$c]->term->think); $job[$c]->term->sys->response = $N[$c] / $job[$c]->term->sys->thruput - $job[$c]->term->think; $job[$c]->term->sys->residency = $N[$c] - $job[$c]->term->sys->thruput * $job[$c]->term->think; break; case BATCH: if ($sumR[$c] == 0) { errmsg($p, "sumR is zero"); } $job[$c]->batch->sys->thruput = $N[$c] / $sumR[$c]; $job[$c]->batch->sys->response = $N[$c] / $job[$c]->batch->sys->thruput; $job[$c]->batch->sys->residency = $N[$c]; break; default: break; } } for ($k = 0; $k < $nodes; $k++) { $qlen[$n1][$n2][$k] = 0.0; for ($c = 0; $c < MAXCLASS; $c++) { if ($N[$c] == 0) { continue; } switch ($job[$c]->should_be_class) { case TERM: $qlen[$n1][$n2][$k] += $job[$c]->term->sys->thruput * $node[$k]->resit[$c]; $node[$k]->qsize[$c] = $qlen[$n1][$n2][$k]; break; case BATCH: $qlen[$n1][$n2][$k] += $job[$c]->batch->sys->thruput * $node[$k]->resit[$c]; $node[$k]->qsize[$c] = $qlen[$n1][$n2][$k]; break; default: break; } } } } /* over n2 */ } /* over n1 */ } /* over n0 */ }