Chapter 1
Chapter 1
Chapter 1
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.
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:
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:
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
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( ));
}
SomeThread3() {
super();
}
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.
Note that at two points the static count was 2 – two of the threads started with a value of
1.
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:
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.
4g.
Consider this URI: http://www.someSite.org:8081/foo/index.htm
Answer: http
Answer: www.someSite.org
iii. What is the port number of the process that provides the service?
Answer: 8081
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).