Вы находитесь на странице: 1из 8

Tutorial 10

1. Name the Eight Fallacies of Distributed Computing


1.
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 database
A dedicated storage that spans across multiple machines in possibly mult
iple locations.
Distributed data store
A network that stores information on multiple nodes in the network commo
nly used by peer-to-peer based applications.
Data grid
An architecture that allows simple requests to be translated to multiple
large scale requests for distributed information and returned as a single resul
t.

3. Caching is a method used for speeding up access. If files are on a disk what
is the purpose of a disk cache (in the context of this chapter)?
Cached data is still there during recovery and doesnt need to be fetched
again 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 ]
155
193
186

Head:
Queue:
SSTF:
SCAN:
C-SCAN:

30
[ 134, 64, 55, 10, 122, 112, 173, 128, 136, 77 ]
183
169
179

Head:
Queue:
SSTF:
SCAN:
C-SCAN:

90
[ 56, 22, 74, 47, 25, 139, 140, 144, 159, 56 ]
205
283
183

These sequences were found by continually running randomly generated sequences u


ntil each algorithm was superior.
SSTF is only superior if the head placement is ideal, the seeking is mainly unid
irectional and the range of queue is a away from the edges. In any other case SS
TF fails in comparison to the other two. This was the longest algorithm to compu
te an ideal use-case for.
SCAN will only be faster than C-SCAN if the distance between the next request in
the second pass and the head is less than the distance between 0 and the next r
equest on the loop through. That is if SCAN can reach its next element on the ret
urn 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 t
he disk in a circular fashion. This was the fastest algorithm to compute an idea
l use-case for.
________________
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <memory.h>

#define NUM_REQUESTS 10
#define NUM_ADDRESSES 200

int _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()
{
int
int
int
int

head_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()
{
int
int
int
int

head_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() );
}

Вам также может понравиться