19.7 Server Driver for Testing

Team-FLY

Modify Program 18.3 ( client ) on page 624 to create a test program for the tunnelserver program and call it servertester . The test program should take four command-line arguments: the tunnel server host name , the tunnel server port number, the number of children to fork and the number of requests each child should make. The parent process forks the specified number of children and then waits for them to exit. Wait for the children by calling wait(NULL ) a number of times equal to the number of children created. (See, for example, Example 3.15 on page 73.) Each child executes the testhttp function described below and examines its return value. The testhttp function has the following prototype.

 int testhttp(char *host, int port, int numTimes); 

The testhttp function executes the following in a loop for numTimes times.

  1. Make a connection to host on port (e.g., u_connect ).

  2. Write the REQUEST string to the connection. REQUEST is a string constant containing the three lines of a GET request similar to that of Example 19.4 on page 660. Use a REQUEST string appropriate for the host you plan to connect to.

  3. Read from the connection until the remote end closes the connection or until an error occurs. Keep track of the total number of bytes read from this connection.

  4. Close the connection.

  5. Add the number of bytes to the overall total.

If successful, testhttp returns the total number of bytes read from the network. If unsuccessful , testhttp returns 1 and sets errno .

Begin by writing a simple version of servertester that calls testhttp with numTimes equal to 1 and saves and prints the number of bytes corresponding to one request.

After you have debugged the single request case, modify servertester to fork children after the first call to testhttp . Each child calls testhttp and displays an error message if the number of bytes returned is not numTimes times the number returned by the call made by the original parent process.

Add statements in the main program to read the time before the first fork and after the last child has been waited for. Output the difference in these times. Make sure there is no output to the screen between the two statements that read the time. Use conditional compilation to include or not include the print statements of tunnelserver . The tunnelserver program should not produce any output after its initial startup unless an error occurs.

Start testing servertester by directly accessing a web server. For example, access www.usp.cs.utsa.edu , using the following command to estimate how long it takes to directly access the web server.

 servertester www.usp.cs.utsa.edu 80 10 20 

Then, do some production runs of tunnelserver and compare the times. You can also run servertester on multiple machines to generate a heavier load.

Exercise 19.21

Suppose, as in Exercise 19.19, that tunnelserver was started on port 15002 of host os1.cs.utsa.edu to service the web server www.usp.cs.utsa.edu on port 8080. How would you start servertester to make 20 requests from each of 10 children?

Answer:

 servertester os1.cs.utsa.edu 15002 10 20 
Exercise 19.22

How do you expect the elapsed time for servertester to complete in Exercise 19.21 to compare with that of directly accessing the origin server?

Answer:

If both programs are run under the same conditions, Exercise 19.21 should take longer. The difference in time is an indication of the overhead incurred by going through the tunnel.

Team-FLY


Unix Systems Programming
UNIX Systems Programming: Communication, Concurrency and Threads
ISBN: 0130424110
EAN: 2147483647
Year: 2003
Pages: 274

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net