Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Chapter 1

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 12

Distributed Computing, Liu Instructor’s Manual w/ Solutions

Chapter 1

Chapter 1
Distributed Computing, An Introduction

Presentation Suggestions

 I usually start presenting this chapter on the very first day of class, immediately after I
have discussed the syllabus and the schedule for the course/class.
 I normally spend the first week of the course covering this chapter.
 To captivate the students’ interest, try to be as light-hearted as possible. Keep in
mind that even though today’s students take for granted the Internet, there is a
significant number of them that do not understand what happens behind the scenes
when they say surf the web. A great way to start the course is to explain just that:
what happens when one opens a browser and enters a URL.
 In retrospect, I would have added more coverage on threading. As it stands, the book
covers the bare minimum of threading. In subsequent editions of the book I will
definitely expand on the coverage. For my own classes, I supplement the topic with a
handout which you can find at this URL:
http://www.csc.calpoly.edu/~mliu/csc369/websites/mutualExclusion.html
I recommend that you do likewise, as proper use of threaded programming is crucial
in project assignments.
 The terms introduced in the “Network Basics” section are important, as they will be
used repeatedly in subsequent chapters.
 A couple of the exercises require basic probability, which may be intimidating to
some students. They are not typical exercises, but many of my students find them
interesting.

How This Chapter Fits


This is a key chapter. I have had students who told me that it should be required reading
for all computer science students. I have tried to make it as interesting as possible by
using graphics and excerpts of interesting articles.
The chapter introduces relevant topics from three important fields in computer science
that the book builds on: operating systems, networks, and software engineering. Since
this book does not assume advanced knowledge in any of these fields, this orientation
material is provided to ensure that all the students in a class are on the same page before
the subject of distributed computing unfolds in subsequent chapters.

Solutions to Chapter Exercises (Answers are in red)


1b.
In this exercise we will use a simplified mathematical model to analyze failures in a
distributed system. Explain your answers.
Suppose each computer in has a probability of p of failing at any time.
1bia

©2004 Addison Wesley


1
Distributed Computing, Liu Instructor’s Manual w/ Solutions
Chapter 1
If n computers are interconnected and the availability of each computer is needed to
maintain a service provided using distributed computing involving these computers, what
is the probability that the service will not be available at any time, assuming that no other
components in the distributed system will fail?
Answer:
All n computers need to be functioning in order for the service to be
available. The probability that each system is functioning is 1 – p.
The probability that all n systems are functioning is ( 1 – p)n , the probability
that the service is available.
The probability that the service is not available is the complement, or
1 – ( 1 – p)n
1bib
Answer:
The probability when n = 1 is 1 – ( 1 – p)1 = 1 – (1 – p) = p.

1bic
Use p=0.2 and n=3 to compute the probability. How does it compare with the failure
probability if the same computing is performed using monolithic computing, that is, on
one computer only?
Answer:
On a single computer, the probability of failing is p = 0.2.
Using the formula developed in (i), the failure probability is (1 - .83) = 0.488
on 3 computers,.
Because all three computers need to be up for the service to be available, the
failure probability is greater than when only one computer is needed.

1 b ii.
Now suppose the service provided using distributed computing requires only 1 of the 3
computers, with the other 2 computer being backups (that is, each of the three computers,
on its own, is capable of providing the service). Now what is the probability that the
service will not be available at any time, assuming that no other components in the
distributed system will fail? How does it compare with the failure probability if the same
computing is performed using monolithic computing, that is, on one computer only?
Answer:
The failure probability is pn in general, or (0.2)3 = 0.008 in this case.
Because only any one of the three computers needs to be up for the service to
be available, the failure probability is now less than when exactly one single
computer is needed.

2. Concurrent Programming
2a i.
According to the specification, which of the two, Runnable interface and Thread class, is
preferred if you only intend to implement the run method? Why?

Answer:

©2004 Addison Wesley


2
Distributed Computing, Liu Instructor’s Manual w/ Solutions
Chapter 1
For good programming practice, the Runnable interface should be used if
only the run method needs to be defined. A subclass of the Thread class
should only be used if the program requires the modification or enhancement
of the base class (that is, if the program needs to add variables and/or methods
that are not in the Thread class).
2a ii.
Answer:
The sleep method suspends the execution of the thread that makes the method call
for the specified number of milliseconds.
The simplest code for suspending the thread for 5 seconds is:
try {
Thread.sleep(5000);
}
catch (Exception ex) {
//exception handling is required
}

2a iii
Answer:
activeCount( ) returns the number of active threads in the current thread’s thread
group.” If 3 threads are spawned and currently activein a process, then the method
should return 4 or more (1 or more thread for main( ) and 3 for the child threads.)
2a iv
Answer:
A deprecated method is one whose support is no longer guaranteed by Java, and
hence its use should be avoided.
2a v
Answer:
There is only one method, run( )

2a vi
Answer:
You define a class that implements the Runnable interface, then create an instance
of the Thread class, passing as an argument to the constructor a reference to an
instance of the class you defined. Like this:
Thread p1 = new Thread(new SomeThread2(1));
p1.start();
2b.
Compile and run the Java class file provided in section 1 in the Appendix. What is the
outcome? Capture the output of the run and write a paragraph to explain the output,
paying special attention to the order of the lines.
Answer:

Thread1: 1 Thread1: 6 Thread3: 2


Thread1: 2 Thread1: 7 Thread2: 3
Thread1: 3 Thread2: 1 Thread3: 3
Thread1: 4 Thread3: 1 Thread2: 4
Thread1: 5 Thread2: 2 Thread3: 4

©2004 Addison Wesley


3
Distributed Computing, Liu Instructor’s Manual w/ Solutions
Chapter 1
Thread2: 5 Thread2: 8 Thread3: 9
Thread3: 5 Thread2: 9 Thread3: 10
Thread2: 6 Thread2: 10 Thread1: 8
Thread3: 6 Thread3: 7 Thread1: 9
Thread2: 7 Thread3: 8 Thread1: 10

Since the threads share the system’s resources, including a single CPU, they are
dispatched by the operating system in turns, and are therefore executed in an
interleaved manner; the order of the interleaving is unpredictable.

2c.
Compile and run the Java class file provided in section 2 in the Appendix. What is the
outcome? Capture the output of the run and write a paragraph to explain the output,
paying special attention to the order of the lines. Also, how does it compare with the
output from (a)?
Answer:
Thread1: 1 Thread3: 2 Thread3: 8
Thread1: 2 Thread2: 3 Thread3: 9
Thread1: 3 Thread3: 3 Thread3: 10
Thread1: 4 Thread2: 4 Thread2: 7
Thread1: 5 Thread3: 4 Thread2: 8
Thread1: 6 Thread2: 5 Thread2: 9
Thread1: 7 Thread3: 5 Thread2: 10
Thread2: 1 Thread2: 6 Thread1: 8
Thread3: 1 Thread3: 6 Thread1: 9
Thread2: 2 Thread3: 7 Thread1: 10

The threads are still executed in an interleaved manner, in an unpredictable order.

2d.
Consider the following Java classes:
import SomeThread3;
public class RunThreads3
{
public static void main (String[] args)
{
int originalThreadCount = Thread.activeCount( );
for (int i=0; i<10; i++) {
Thread p = new Thread(new SomeThread3());
p.start();
System.out.println("thread count=" +Thread.activeCount( ));
}

while (Thread.activeCount() > originalThreadCount ){


// loop until all child threads have exited.
}
System.out.println("finally, Count = " + SomeThread3.count);
}
}//end class RunThreads3

class SomeThread3 implements Runnable {


static int count=0;

SomeThread3() {
super();
}

public void run() {

©2004 Addison Wesley


4
Distributed Computing, Liu Instructor’s Manual w/ Solutions
Chapter 1
update();
}

static public synchronized void update( ){


int myCount = count;

int second = (int)(Math.random( ) * 500);


try {
Thread.sleep(second);
}
catch (InterruptedException e) {
}

myCount++;
count = myCount;
System.out.println("count="+count+
"; thread count=" + Thread.activeCount( ));
}
} //end class SomeThread3

2d i.
What do you expect the outcome to be when RunThread3 is executed? Compile and run
it.
Answer:
A synchronized method can only be run by one process/thread at a time, hence the
ten child threads spawned by RunThreads3 will run the method consecutively,
one at a time. The static variable count is therefore incremented successively,
with its value changing from 0 to 10.
Here’s the outcome of a run on a system that runs Java 1.4. Note that the initial
active thread count is 3.
thread count=3 count=2; thread count=11
thread count=4 count=3; thread count=10
thread count=5 count=4; thread count=9
thread count=6 count=5; thread count=8
thread count=7 count=6; thread count=7
thread count=8 count=7; thread count=6
thread count=9 count=8; thread count=5
thread count=10 count=9; thread count=4
thread count=11 count=10; thread count=3
thread count=12 finally, Count = 10
count=1; thread count=12

2d ii.
Comment out the word “synchronized” in the heading of the method update. Compile
and run RunThread3 again. What is the outcome? Explain.

Answer:

Now the method is no longer thread safe. Now the ten threads can execute
the method concurrently, each incrementing the value of the version of the
static count that it retrieved from. Due to the interleaved execution of the
threads, some of the incrementing can be expected to overlap each others,
resulting in a final count of an integer value in the range of 1 to 10.

©2004 Addison Wesley


5
Distributed Computing, Liu Instructor’s Manual w/ Solutions
Chapter 1
Here is a sample run outcome:

©2004 Addison Wesley


6
thread count=3
thread count=4
thread count=5
thread count=6
thread count=7
thread count=8
thread count=9
thread count=10
thread count=11
thread count=12
count=1; thread count=12
count=1; thread count=11
count=2; thread count=10
count=1; thread count=9
count=1; thread count=8
count=1; thread count=7
count=2; thread count=6
count=1; thread count=5
count=1; thread count=4
count=1; thread count=3
finally, Count = 1

Note that at two points the static count was 2 – two of the threads started with a value of
1.

3.Connection-Oriented vs. Connectionless Communication


In this exercise we will use a simplified mathematical model to analyze the tradeoff
between connection-oriented communication and connectionless communication.
Explain your answer.
On a certain network both forms of communication are provided:
 Using connection-oriented communication, it takes 50 second to establish a
connection, after which a packet of up to 10 characters can be sent in 1.0
seconds over the connection, in either direction.
 Using connectionless communication, a packet of up to 10 characters can be
sent in 1.2 second. (The sending of each packet takes slightly longer than in
the connection-oriented case, since each packet must find its way to the
receiver.)
Suppose A and B exchanges messages on this network. A initiates the
communication and sends to B a message of 100 characters, which are partitioned
into 10 packets. In reply, B sends a message of 50 characters, which are partitioned
into 5 packets.
Assuming that there is no delay other than the time it takes for establishing a
connection (in the connection-oriented case) and for packet transmission:
a. How long does the session between A and B last, using connection-oriented
communication? Explain.
Answer:
The session time is the ConnectionTime + time for A’s data transfer + time
for B’s data transfer = 50 + 1.0*10 + 1.0*5 = 65 sec
b. How long does the session between A and B last, using connectionless
communication? Explain.
Answer:
The session time is time for A’s data transfer + time for B’s data transfer =
1.2*10 + 1.2*5 = 18 sec

c. How much data (in number of characters) must be exchanged between A and B in
order for the connection-oriented communication to yield a shorter session than
the connectionless communication? Explain.
Answer:
Suppose the breakeven point occurs when N packets are exchanged between
A and B, then:
50 + N * 1.0 < N * 1.2
Solving for N yields N > 250, and hence the smallest number of packets for
the connection-oriented communication to yield a shorter time is N =251
packets.
In terms of number of characters, let a and b be the number of characters
sent by A and B respective. Then
ceiling of (a/10) + ceiling of (b/10) = 251
For the equation to hold, any of the following combination will work:

a = (1,9), b = (2491,2499)
that is, A sends 1 to 9 characters in 1 packet; B sends 2491 to 2499
characters in 250 packets
a = (11,19), b = (2481,2489)
a = (21,29), b = (2471,2579)
and so forth.

Choosing the smallest number of characters on each side, one comes up with
2492 characters as the smallest for 251 packets to be exchanges. Hence 2492
characters or more must be exchanged between A and B in order for the
connection-oriented communication to yield a shorter session than the
connectionless communication.

1. Naming
4a.
What is the size of the address space (that is, the total number of addresses allowable)
in each of the five classes of the IPv4 addresses? Show your computation.
Answer:
The size of address space = the total number of addresses allowed in IPv4
is 232 = 4,294967296.
Within each class:
class Number of variable bits Number of addresses allowable
A 31 2,147,483,648
B 30 1,073,741,824
C 29 536,870,912
D 28 268,435,456
E 28 268,435,456

4b.
Find out the IP network address assigned to your organization. What class (A
thorugh E) is it?

Answer:
At Cal Poly, the net ID is 129.65: it is a class B address.
Note: If your organization is connected to the Internet via an Internet
Service Provider (ISP), the ISP is assigned one or more IP addresses
(typically class C addresses) , which is used for data transmission to and
from he ISP’s routers. However, the ISP assigns an internal IP address
to individual subscribers using a dynamic scheme. The internal IP
address is not related to the external address of the ISP itself. For
example, the Grid, an ISP, has an external IP address of 206.80.160, a
class C address. If you are a subscriber, your internal ID may be
something like 12.24.56.156.
4c.
Find out the domain name of the web server host of your organization. What is
its IP address?
Answer:
www.csc.calpoly.edu is the alias of tiedye-srv.csc.calpoly.edu
(129.65.241.7 ), which is the host web server of CSC;
www.calpoly.edu, is the alias of polywww.cpunix.calpoly.edu
(129.65.2.119), the web server host of Cal Poly.
4d.
A network program, nslookup, can be used to obtain DNS name-lookup
service.You can invoke this program at least three ways:
 On a UNIX system, enter nslookup at the system prompt.
 On a Windows system, enter nslookup at the prompt in a command
prompt window.
 Browse to the site http://cc-www.uia.ac.be/ds/nslookup.html,
http://www.csu.net/cgi-bin/nslookup,
http://www.jeffenstein.org/nslookup.html
Use the service to complete the following table:
IP address Domain name
127.0.0.1 localhost
129.240.64.2 ifi.uio.no
132.68,160.4 ie.technion.ac.il

204.198.135.62 Non-existent
224.0.1.24 Microsoft-ds.mcast.net
137.189.91.190 cse.cuhk.edu.hk
129.65.2.119 polywww.cpunix.calpoly.edu
18.181.0.31 DANDELION-
PATCH.MIT.EDU
4e.
Complete the following table:

IP address Domain name Class Net ID (in Host


of dotted decimal ID )in
address notation) dotted
(A-E) decimal
notation)
18.181.0.31 DANDELION- A 18 181.0.31
PATCH.MIT.EDU
129.65.2.119 polywww.cpunix.calpoly.edu B 129.65 2.119
204.198.135.62 Non-existent C 204.198.135 62
224.0.1.24 Microsoft-ds.mcast.net D N/A* N/A

*A Class D address identifies a multicast group, and the notion of a network


ID and host ID does not apply.

4f.
Using [19] to help, find out the domain name country code for the following
nations:

Armenia am, Brazil br, Canada ca, Cuba cu, Germany de, Spain es,
France fr, Guatemala gt, India in, Mexico mx, Qatar qa, Singapore sg,
Sweden se, El Salvador sv, Turkey tr.

Identify the nation for each of the following country codes:

Td Chad, tv Tuvalu, zw Zimbabwe, nz New Zealand. Ph Philippines, pk


Pakistan, eg Egypt, bt Bhutan, ao Angola.

4g.
Consider this URI: http://www.someSite.org:8081/foo/index.htm

i. What is the protocol specified?

Answer: http

ii. What is the host name of the service?

Answer: www.someSite.org

iii. What is the port number of the process that provides the service?

Answer: 8081

iv. Where is the document located?


Answer: Foo/index.htm

4h.
i. Which port number is assigned to each of these services: (i)ftp 20 and 21
TCP and UDP, (ii)telnet 23 TCP and UDP, (iii) SMTP 25 TCP and UDP, and
(iv) World Wide Web HTTP 80 TCP and UDP? Are these services available
using TCP or UDP or both?
ii. What services are assigned to ports 13 and 17 respectively? 13 is for daytime,
and 17 is for qotd (quote of the day)
iii. On your UNIX system or from the command-prompt window of your
Windows system, one way that you can access a network service is by issuing a
command such as the following to access a network service that uses TCP:
telnet <space><domain name or IP addres of a system that you know>
<space><port number assigned to the service>
For example, the command telnet foo.com 13 will access the service provided by
the process running on port 13 on the Internet host telnet.foo.
Try using this method to access the services offered on ports 13 and 17
respectively on a machine you know. Describe the outcomes.
Answer:
Sample output --
9:20pm falcon ~>telnet polylog1 13
Trying 129.65.60.104...
Connected to polylog1.cpunix.calpoly.edu.
Escape character is '^]'.
Fri Oct 12 21:21:21 2001
Connection closed by foreign host.

A timestamp is sent from the daytime server running on port 13 on the host
polylog1.

The quote service (port 17) is commonly disabled on Internet host these
days.

4j.
A naming scheme is said to allow location transparency[26] if the scheme allows
objects to be addressed without explicit knowledge of their physical location. For
example, the U.S. phone number system is location transparent, as a caller does
not need to know the whereabouts of the callee when dialing up. The U.S. postal
address system, on the other hand, does not allow location transparency, since you
must address the recipient with his/her physical address (excluding postal office
boxes, that is).

Consider each of the following naming schemes. For each, determine if it is


location transparent? Justify your answer.

i. The domain name system (DNS) Yes and no – a domain name is


dynamically mapped to a Internet address assigned to a specific
computer, so the scheme is inherently location transparent.
However, the use of country-code spoils the transparency. So,
domestically (in the U.S.) you can argue that a DNS name is
location transparent, but not if you consider the international
scheme.
ii. Uniform Resource Location (URL) No – the domain name is part of
a URL, which, as explained above, is not strictly location
transparent. Furthermore, the general form of URL allows the
specification of a port number, which again diminishes the
location transparency.
iii. Uniform Resource Name (URN). Yes, it is supposed to be location
transparent, although the specification of the scheme has not been
completed.
iv. Extensible Name Service (XNS) It is supposed to be location
transparent. However, it does use DNS to resolve Internet
addresses, and in that regard it is not location transparent.

You might also like