CS 5523 Operating Systems
Laboratory 3 - Spring 2001
Comparing Threaded Servers

Objectives:

Overview:

In this laboratory you will write two versions of a threaded server (thread-per-connection and worker-pool) and compare their performance. In both cases the communication will be based on TCP.

Requirements:

Server version I:

Server version I listens for a TCP connection request on a well-known port. After accepting the request, the server creates a thread to handle the request and resumes listening for another request. The thread function takes the communication file descriptor as a parameter. The thread detaches itself, performs the request, closes the communication file descriptor and exits (by calling pthread_exit). Server version I takes the well-known port as a command line argument. Under what circumstances should Server version I exit?

Server version II:

Server version II takes the well-known port and the size of the worker-pool as command line arguments. Server version II creates the number of threads specified by the worker-pool size and a circular buffer of the same size. Server version II is based on a producer/consumer model with the main thread being the producer and the worker threads being consumers. The worker threads wait for an item (the communication file descriptor value) to become available and use it to process the request. The worker threads then close the communication file descriptor and wait for another item to become available.

Client driver:

You should also write a client driver program that takes the following command line arguments: the hostname of the server, the port name of the server, the number of processes to fork, the number of connections per process, and the number of messages per connection. The client driver will fork the specified number of processes, each of which will do the following the number of times specified by connections per process:

Note, the connection request may fail and have to be retried when the server is busy, so you will need to put this in its own loop. The number of connections means the number of successful connections. The process should get the time before it tries to make a connection and after it makes the connection. It should also read the time after it has received the response. It should write the time differences between these three points to standard error, along with its PID so that the interleaved messages from the different processes can be distinguished. Before each client process exits it should print the the total number of connection retries it experienced and other relevant statistics

The message:

Each message from the client should consist of structure containing four long integers in network byte order:

Each time the client process sends a message, it increments the client message number. The client does not reset the message counter when it makes a new connection.

The response consists of:

Each time a server thread processes a message, it increments its thread message number. It does not ever reset the message number to zero.

Gathering statistics:

You should gather statistics about average and median connection times and response times for the two different servers. For the worker pool you should compare results for 1, 5, 10 and 50 threads in the pool. You should vary the number of client processes and also test with the client driver running simultaneously on multiple machines. You should organize your results in tables and graphically and draw conclusions about the measurements in your report.


Last Revision: February 28, 2002 at 7:30 am