CS433/533 Programming Assignment 1:
Socket API
This assignment gives you a chance to familiar with the
basic Java socket programming interface, Java Thread, Java Asynchronous
IO, and Java sleep or (java Timer).
Due: 11:59 PM, Feb. 18,
Monday. Please see below for submission
instruction.
Part 1. Performance Comparisons and Improvement of
HTTP Servers
Please modify the programs below to implement HTTP
server in three ways: sequential, multi-thread, and asynchronous i/o.
The programs below are samples.
For each approach, the command-line syntax should allow
specification of at least port and www_root. You may want to add other
switches to help with debugging and configuration.
% java <seqHTTPServer | mtHTTPServer | asyncHTTPServer> -port
<port> -www_root <www_root>
We will use http_load
(http://www.acme.com/software/http_load/) to test the performance of
the servers. All related files are under
/home/httpd/html/zoo/classes/cs433/assignments/prog1/
For this part of the assignment, you need to be able to
do the following:
- Use /home/httpd/html/zoo/ as the www root
- Modify the three web servers so that a user can restrieve files
under the www root. Although your web server may not be able to
retrieve all files under the www root due to permission issues, it
should be able to restrieve
documents under /home/httpd/html/zoo/classes/cs433/assignments/prog1/www
For example, if I am running my a web server on
cicada at port 9876, and I want to restrieve
/home/httpd/html/zoo/classes/cs433/assignments/prog1/www/html-small/doc1.html
I can type into my browser:
http://cicada.cs.yale.edu:9876/classes/cs433/assignments/prog1/www/html-small/doc1.html
If I type an URL that does not map into an invalid file name, please
return Error and code 404.
- Test the performance of the servers using http_load. You may find
this
document helpful. We have installed http_load under
/home/httpd/html/zoo/classes/cs433/assignments/prog1/http_load/
An example url file is called urls.txt
For the test, you will need to vary the parallel from 1 to 250 (or more
until your server saturates)
with a reasonable increment schedule (e.g., 1, 2, 3, 4, 5, 10, 15, 20,
25, 30, 35, 40, 45, 50, 60, 70, ...). A reasonable test time is 60 to
120 seconds.
Please conduct two test cases:
- All small html files. For this case, please use the 1000 files
under
/home/httpd/html/zoo/classes/cs433/assignments/prog1/www/html-small/
- A mix of small, big and jpg files: For this case, please use
the first 500 files from html-small, the 100 files from html-big, and
the 100 jpg files from jpg.
- Please report the measured performance for performance metrics:
throughput and (mean) delay. The sample figure
below may
give you a sense of the
testing results for throughput. Please add one optimization feature and
validate the
optimization. Thus, your results should contain at least four curves:
one curve for each given server, and one for your optimization.
You may want to conduct a test using the department server
(http://zoo.cs.yale.edu) and compare the performance. Please discuss
the
lessons learned.

Part 2. A Concurrent Java TCP Relay Client with Timeout
-
The function of this Java program is to relay
between a user and a TCP server. It needs to provide the following
functionalities:
-
any message from the keyboard is sent to the
TCP server;
-
any message from the server is displayed to the
user;
-
if the user is idle for <idle time>
seconds, the program should close the socket and exit;
-
the Java program cannot block on either the
keyboard input or the Socket input.
-
You should implement both a thread version and an
asynchronous i/o version.
-
Command line: your program should allow a
user to specify server hostname, server port name, and the idle time
before the program exits. It also can specify the implementation mode:
asynchronous i/o or thread. the default should be thread.
% java tcpRelay -h <hostname> -p <port number> -i <idle
time in seconds> [-async | -thread]
- Submission
- Please include a short description of your design along
with your source code.
- References
- Book
- Java Network Programming, 3rd, 2005, by Elliotte Harold
is a good reference book on Java network programming. In particular,
you should read chapter 5 on Thread and chapter 12 on asynchronous i/o.
- Yale library has electronic version of this book (you
need Yale IP address to gain access). If this link does
not work, please search the book title using Orbis, and follow the link.
- The examples codes can be found here.
- Tutorials
- All About Sockets (Sun tutorial)
- Socket Programming in Java: a Tutorial
- Thread and timer
- More details on Java IO (Java NIO)
- General java information:
- Development environments:
- zoo has Java installed:
- eclipse provides a nice java IDE.
- Java book
- Suggestions
- The objective of this assignment is to let you familiarize
with the basic library. Please keep the program simple and there is no
need to handle all exceptions too nicely. For example, if there is an
exception when you close a socket but a thread is blocked on reading
from the socket, just catch the exception.
- Testing: make sure that your program can work with both an
SMTP server and an HTTP server. For example:
% java tcpRelay -h
mr1.its.yale.edu -p 25 -i 1
HELO <your address>
MAIL FROM: <your address>
RCPT TO: <destination address>
DATA
.
Subject: This is subject
From: <from address>
To: <to address>
Body
.
% java tcpRelay -h www.yale.edu -p
80 -i 1
GET / HTTP/1.0
...
Submission
- Please submit using class server. Please generate a
single jar file containing all of your files. The name of the jar file
should be prog1.<netid>.jar. If you want to update, please rename
it prog1A.<netid>.jar, etc.
Last Update:
February
10, 2008 02:04:08 PM -0500