CSCI.4220 Network Programming
Spring, 2005
Programming Assignment 3

We want to test the efficiency of several server designs. You should use at least these four, and you should feel free to use other designs as well.

  1. An iterative server, in which each connection is handled consecutively by a single process and thread.
  2. A server that forks off a new process for each connection (make sure that you deal with zombies)
  3. A server that creates a new thread for each connection
  4. A server that preforks a number of children.

I will provide you with a sample test client. This client will fork off a number of children (unusual behavior for a client) and each child will iteratively establish a number of connections with your server. Once a connection has been established, the client and server will exchange a predetermined amount of data (random numbers) and then shut down the connection.

You will want to time the server. You can use the following function for this

     #include <time.h>
     clock_t     clock(void);

DESCRIPTION
     The clock() function determines the amount of processor time used since
     the invocation of the calling process, measured in CLOCKS_PER_SECs of a
     second.

On FreeBSD, CLOCKS_PER_SEC is 128.

Here is the timer code

  clock_t start, end;

  start = clock();  /* should be zero */
  /* stuff to be timed */
  end = clock();
  printf("Time is %5.3f\n''(double)(end-start)/CLOCKS_PER_SEC);

You should start a clock when the first connection is received. After 50001 connections have been processed, call clock again, display the time, and terminate the server.

For each connection, iterate through a loop 20 times, which first reads 4096 bytes from the client, then fills a buffer with 1024 random numbers (the buffer size is 4096 bytes long) and send them to the client.

I will provide you with some sample code for the this. I will also provide a sample client.

With preforking, it might be tricky to determine when exactly 5000 connections have been processed. One solution is to used shared memory among the processes. This is the fastest way for two unrelated processes to communicate, but the implementation is somewhat bizarre. There is a link from the course website on one way to do this. You can solve this problem in some other way as long as it does not affect the time.

This is research, so you should feel free to experiment. Play around with the number of preforked processes, the number of client threads, and any other variables that might provide useful information. You will have to write up your conclusions. You will be graded on your imagination.

You might have to increase the length of the listening queue (my code always sets it to 5).

The project is due by midnight on Sunday March 13. You should submit your write-up and all of your programs in a tar file. (tar cf abc.tar server1.c server2.c client.c creates a tar file called abc.tar which contains the three files listed.)