tutorial 10

Download Tutorial 10

If you can't read please download the document

Upload: stacc

Post on 24-Dec-2015

4 views

Category:

Documents


1 download

DESCRIPTION

Tutorial 10

TRANSCRIPT

Tutorial 101. Name the Eight Fallacies of Distributed Computing1.2.3.4.5.6.7.8.The network is reliable.Latency is zero.Bandwidth is infinite.The network is secure.Topology doesn t change.There is one administrator.Transport cost is zero.The network is homogeneous.2. Briefly explain the following:Distributed databaseA dedicated storage that spans across multiple machines in possibly multiple locations.Distributed data storeA network that stores information on multiple nodes in the network commonly used by peer-to-peer based applications.Data gridAn architecture that allows simple requests to be translated to multiplelarge scale requests for distributed information and returned as a single result.3. Caching is a method used for speeding up access. If files are on a disk whatis the purpose of a disk cache (in the context of this chapter)?Cached data is still there during recovery and doesnt need to be fetchedagain therefore is more reliable.4. Submit any code or results that you have obtained from this weeks lab.________________Queue between 0-199 (200)Head:Queue:SSTF:SCAN:C-SCAN:158[ 137, 145, 121, 169, 162, 25, 139, 90, 128, 47 ]155193186Head:Queue:SSTF:SCAN:C-SCAN:30[ 134, 64, 55, 10, 122, 112, 173, 128, 136, 77 ]183169179Head:Queue:SSTF:SCAN:C-SCAN:90[ 56, 22, 74, 47, 25, 139, 140, 144, 159, 56 ]205283183These sequences were found by continually running randomly generated sequences until each algorithm was superior.SSTF is only superior if the head placement is ideal, the seeking is mainly unidirectional and the range of queue is a away from the edges. In any other case SSTF fails in comparison to the other two. This was the longest algorithm to compute an ideal use-case for.SCAN will only be faster than C-SCAN if the distance between the next request inthe second pass and the head is less than the distance between 0 and the next request on the loop through. That is if SCAN can reach its next element on the return before C-SCAN can reach its next element on the loop.C-SCAN will never take longer than the number of cylinders as it seeks through the disk in a circular fashion. This was the fastest algorithm to compute an ideal use-case for.________________#include #include #include #include #define NUM_REQUESTS 10#define NUM_ADDRESSES 200int _head_pos, _queue[NUM_REQUESTS];void init();int SSTF();int SCAN();int CSCAN();int cmp_asc ( const void *a, const void *b );void print_head();void print_queue();void print_all();int main( int argc, char** argv ){int sstf = 0, scan = 0, cscan = 0;init();while ( sstf >= scan || sstf >= cscan ){init();sstf = SSTF();scan = SCAN();cscan = CSCAN();}print_all();putchar( \n );while ( scan >= sstf || scan >= cscan ){init();sstf = SSTF();scan = SCAN();cscan = CSCAN();}print_all();putchar( \n );while ( cscan >= sstf || cscan >= scan ){init();sstf = SSTF();scan = SCAN();cscan = CSCAN();}print_all();putchar( \n );return EXIT_SUCCESS;}void init(){int i;srand( time(NULL) );_head_pos = rand() % NUM_ADDRESSES;for ( i = 0; i < NUM_REQUESTS; i++ ){_queue[i] = rand() % NUM_ADDRESSES;}}int SSTF(){int head_pos, queue[NUM_REQUESTS];int seek_time;int i, j;head_pos = _head_pos;memcpy( queue, _queue, sizeof(queue) );seek_time = 0;for ( i = 0; i < NUM_REQUESTS; i++ ){int min_index;int min_seek = NUM_ADDRESSES;for ( j = 0; j < NUM_REQUESTS; j++ ){/* ignore completed */if ( queue[j] != -1 ){int j_seek_time;j_seek_time = abs( head_pos - queue[j] );if ( j_seek_time < min_seek ){min_seek = j_seek_time;min_index = j;}j_seek_time = abs( queue[j] - head_pos );if ( j_seek_time < min_seek ){min_seek = j_seek_time;min_index = j;}}}/*printf( "[%i] %i [%i]\n", head_pos, queue[min_index], min_seek);*/seek_time += min_seek;head_pos = queue[min_index];queue[min_index] = -1;}return seek_time;}int SCAN(){intintintinthead_pos, queue[NUM_REQUESTS];seek_time;i;remaining;head_pos = _head_pos;memcpy( queue, _queue, sizeof(queue) );seek_time = 0;remaining = NUM_REQUESTS;qsort( queue, NUM_REQUESTS, sizeof(int), cmp_asc );for ( i = 0; i < NUM_REQUESTS; i++ ){if ( queue[i] > head_pos ){break;}}for ( ; i < NUM_REQUESTS; i++ ){/*printf( "[%i] %i [%i]\n", head_pos, queue[i], queue[i] - head_pos );*/seek_time += queue[i] - head_pos;head_pos = queue[i];queue[i] = -1;remaining--;}if ( remaining == 0 ) return seek_time;/*printf( "[%i] %i [%i]\n", head_pos, NUM_ADDRESSES - 1, (NUM_ADDRESSES- 1) - head_pos);*/seek_time += (NUM_ADDRESSES - 1) - head_pos;head_pos = NUM_ADDRESSES - 1;for ( i = i - 1; i > 0; i-- ){if ( queue[i] != -1 ){/*printf( "[%i] %i [%i]\n", head_pos, queue[i], head_pos- queue[i] );*/seek_time += head_pos - queue[i];head_pos = queue[i];queue[i] = -1;}}return seek_time;}int CSCAN(){intintintinthead_pos, queue[NUM_REQUESTS];seek_time;i;remaining;head_pos = _head_pos;memcpy( queue, _queue, sizeof(queue) );seek_time = 0;remaining = NUM_REQUESTS;qsort( queue, NUM_REQUESTS, sizeof(int), cmp_asc );for ( i = 0; i < NUM_REQUESTS; i++ ){if ( queue[i] > head_pos ){break;}}for ( ; i < NUM_REQUESTS; i++ ){/*printf( "[%i] %i [%i]\n", head_pos, queue[i], queue[i] - head_pos );*/seek_time += queue[i] - head_pos;head_pos = queue[i];queue[i] = -1;remaining--;}if ( remaining == 0 ) return seek_time;/*printf( "[%i] %i [%i]\n", head_pos, NUM_ADDRESSES - 1, (NUM_ADDRESSES- 1) - head_pos);*/seek_time += (NUM_ADDRESSES - 1) - head_pos;head_pos = NUM_ADDRESSES - 1;/*printf( "[%i] %i [%i]\n", head_pos, 0, head_pos );*//* don t include jump as head movement *//* seek_time += head_pos; */head_pos = 0;for ( i = 0; i < NUM_REQUESTS; i++ ){if ( queue[i] != -1 ){/*printf( "[%i] %i [%i]\n", head_pos, queue[i], queue[i]- head_pos );*/seek_time += queue[i] - head_pos;head_pos = queue[i];queue[i] = -1;}}return seek_time;}int cmp_asc ( const void *a, const void *b ){return ( *(int*)a - *(int*)b );}void print_head(){printf( "Head: %i\n", _head_pos );}void print_queue(){int i;printf( "Queue: [" );for ( i = 0; i < NUM_REQUESTS; i++ ){printf( " %i%s", _queue[i], (i+1 < NUM_REQUESTS) ? "," : " " );}printf( "]\n" );}void print_all(){print_head();print_queue();printf( "SSTF: %i\n", SSTF() );printf( "SCAN: %i\n", SCAN() );printf( "CSCAN: %i\n", CSCAN() );}