CSC 132 Fall 2000
Homework 9
Due: 9 a.m. 7 December 2000
65 points
"Web Server Simulator"
This assignment will pull together elements of several previous assignments into something of a capstone project. The project will be to simulate and measure the performance of a web server. Additional design information is close at hand (generated 30 November).
You will use classes developed in two previous assignments: the Statistic class from Homework 1 and the PrioQueue and SimEvent classes of Homework 8. You will also craft a small applet similar to those in several previous homework and lab assignments. The eccentric download folder for each these assignments contains a solution folder from which you should get the source code. Note: solutions for the PrioQueue and SimEvent classes will not be available until after November 27. Go ahead and use your own if you are confident that they work correctly.
Description of the system you will be simulating: Requests for web pages arrive at the server. For each request, the server fetches the page and transmits it on the network port. For purposes of this simulation, that's basically it. When you run the program, system parameters are entered into the applet, the simulation is run, and the results are output to the applet. Here are the specifications:
Simulation input: System performance depends on the values that these parameters take on. The values are entered into the applet before the simulation is run, and defaults are defined. The system parameters are:
1. Time between web page requests, in milliseconds. Low end of the range is fixed at 1 and default for high end of the range is 50.
2. Size of the page requested, in bytes. Default range is from 500 to 8000.
3. Transmission capacity, in bits per second. Default value is 1,544,000.
4. Time period to be simulated, in seconds. Default value is 60.
Simulation output: System performance will be measured by your program and reported to the applet. Performance measures come from Statistic objects. The Statistic class is documented at http://eccentric.smsu.edu/download/csc132/001/hw1/solution/index.html, and you should download Statistic.java from there. The output measures are:
1. Time from arrival of page request until page begins transmitting (e.g. server response time). This delay time will be recorded for each request when it begins transmission, in a Statistic object.
2. Size of requested page. This will confirm that system parameter for page size works correctly. This will be recorded as each request arrives, in a Statistic object.
3. Number of page requests received. This will confirm that system parameter for page requests works correctly. This value can be obtained from the Statistic object for page size -- it will be the number of samples (getLength method).
4. Utilization of transmission port. Utilization means percentage of transmission capacity that was actually utilized for web page transmission. If capacity is 10 megabits per second, and a one second simulation results in transmission of 1000 web pages of 1000 bytes apiece, the utilization is 80% = (1000 * 1000 * 8 bits per byte)/(10,000,000). There are different ways of measuring this; here is my suggestion. Define a Statistic object and collect, at the end of a page's transmission, the size of that page. NOTE: if the server is overworked, this will not yield the same set of values as #2 because many pages will still be awaiting transmission when the simulation ends. At the end of the simulation, multiply the average page size by the number of pages transmitted (both values are available from the Statistic object). This will give you the total number of bytes transmitted. Divide that by the transmission rate times the final clock value (scale as necessary to make sure everything is based on the same units).
Applet: The simulation inputs and outputs will be arranged on a GUI window along with one button to Start the simulation. Each simulation input value has a TextField with default value already displayed. The user makes any changes to the input values then presses the Start button. The simulation runs until the specified stop time has arrived. When the simulation stops the output values should each be displayed (use your imagination here, display them in a TextArea, separate TextFields or in some other fashion). The applet also needs to display the current value of the simulation clock (which is initially 0 and increases until the simulation stops). The value needs to be redisplayed each time the clock value is updated. The user should be able to make repeated simulation runs, changing input parameter values for each run if desired.
Program Structure: A program such as this requires several elements all interacting to produce the desired result. Here are the major structural elements of the program:
1. Simulation clock. This will be an object of the SimClock class, which you will define. The instance variable that represents the clock is an "int" variable. Each integer unit will represent one microsecond (e.g. clock value of 1,000,000 means you are one second into the simulation run). Using this scale, the int type is sufficient for a simulation run of just over 2,000 seconds or a little over 30 minutes. Note that these values represent simulated time only and bear no relationship to actual clock time. Define a constructor and accessor and modifier methods. Do not allow the clock value to be decreased. The simulation clock will be a public instance variable of the Simulation class, defined in #5 below.
2. Web Page Request. This will be an object of the Entity class, which you will define. The Entity class has two instance variables: one to represent the size in bytes of the web page being requested and another to record the simulation time that the request arrived at the server. Both are "int" values. You will need to implement constructor and accessor methods. Modifier methods are not necessary. Make sure your constructor has two parameters to set the values of both instance variables.
3. An object to represent the transmission port. It will be an object of the Resource class, which you will define. This class has two instance variables. One is a boolean busy/idle status variable and the other is a reference to a queue of Entity objects. The constructor does not require any parameters. The busy/idle status variable should be private but the queue should be public because it needs to be manipulated by the SimEvent handlers described below. The queue can be represented either by an ObjectQueue (see Chapter 7 pages 351-357 and downloadable from http://www.cs.colorado.edu/~main/edu/colorado/collections/ObjectQueue.java) or by a java.util.LinkedList (documented at http://java.sun.com/j2se/1.3/docs/api/java/util/LinkedList.html). Your choice.
4. Future Events Queue (FEQ). This will be an object of the PrioQueue class, and will hold SimEvent objects. The SimEvent objects will be created by the SimEvent handlers described below. Extend the SimEvent class to have an additional instance variable: a reference to an Entity object. This will require an additional constructor parameter and accessor method. The other two, type and time, remain the same. The FEQ will be manipulated by the simulation control mechanism described next and is a public instance variable of the Simulation class.
5. Event-oriented simulation control mechanism. This will be an object of the Simulation class, which you will define. This class has two public instance variables, the simulation clock and the FEQ, a constructor and one method called run. The constructor will create the simulation clock and the FEQ. Run will kick off the simulation by creating the first arrival event then go into an infinite loop! Here is what happens for each loop iteration: remove the first SimEvent object from the FEQ and extract its event time and event type. Update the simulation clock to the event time. Then use its event type in a switch condition. Each SimEvent is handled in a specific way, as described in the Event Types paragraph. Once it is handled, you simply move on to the next loop iteration. The loop is exited when a "Stop the simulation!" event is handled.
Event Types: Several different types of SimEvents will occur in the system. They are:
0 - Stop the simulation! When the Start button is clicked, a single SimEvent object with this type should be created and placed in the FEQ. The time for this event will be the value assigned to the simulation time period input (see Simulation Input #4). This SimEvent type does not have an associated Entity. This event type has the lowest priority.
1 - Web page request has arrived! This event simulates the arrival at the server of a web page request. The SimEvent is created when the previous request arrives. In other words, when handling the arrival of a web page request, the next request is scheduled (explanation below). The first arrival must be scheduled when the user clicks the Start button! Note that two arrivals cannot occur at the same time (see restriction under Simulation Input #1). This SimEvent type does not have an associated Entity. The entity will be created when the event is handled.
2 - Finished transmitting! This event simulates transmission of the last byte of a requested web page. This SimEvent is created and added to the FEQ when an Entity gains control of the transmission port and thus begins transmission. The transmission completion time can be calculated based on the current time, the web page size and the transmission rate. Remember that clock time unit is milliseconds.
If the PrioQueue and SimEvent classes from Homework 8 are correctly implemented, SimEvents will be removed from the FEQ in the correct order. The event types are numbered so that multiple events scheduled for the same time will be handled properly (departure first, then arrival, then stop). In this program, it is not possible for two events of the same type to be scheduled for the same clock time (There is only one transmission output port, so only one transmission can finish at a given time. Each request arrival schedules the next arrival, so only one web page request can arrive at a given time. Finally, only one simulation Stop event is ever scheduled.).
Event Handling: Here is how to handle a SimEvent object of the types above. This is done in the switch statement described in the simulation control loop, Program Structure #5.
0 - Stop the simulation! Break out of the infinite loop and output the required statistical values (see Simulation Output). The simulation run is now complete. Allow the user to make another run.
1 - Web page request has arrived! Determine the size in bytes of the requested web page (using a random number generator). Create a new Entity object, giving it this page size and the current clock time. Collect the page size statistic (for Simulation Outputs #2 and #3). Check to see if the transmission port is busy or idle. If busy, insert the Entity into its queue. If idle, set the transmission port to busy, collect the value 0 for response time (for Simulation Output #1), determine the transmission completion time (based on current time, page size and transmission rate), and schedule the type 2 SimEvent for that time. Finally, determine when the next arrival will occur and schedule the type 1 event for that time. The next arrival time will be the current time plus the random value selected from the range specified for Simulation Input #1.
2 - Finished transmitting! Collect page size for Simulation Output #4. Check to see whether the transmission port's queue is empty. If it is, set the transmission port status to idle. If it is not, remove the first Entity from the queue, collect the response time for Simulation Output #1 (response time is calculated by subtracting the Entity's arrival time from the current clock time), determine the transmission completion time (based on current time, page size and transmission rate), and schedule the type 2 SimEvent for that time.
Using Random Number Generators: Create two java.util.Random (documentation at http://java.sun.com/j2se/1.3/docs/api/java/util/Random.html) objects, one for determining arrival times and a different one for determining web page size. To get each random value, call the nextInt(int n) method. This will return an integer value in the range from 0 through n-1. You will have to apply a formula to this return value, to transform it into the range specified by Simulation Input values #1 and #2 for arrival interval and page size, respectively.
Final comments:
The simulation run is controlled by the Simulation class's run method. Simulation begins when the user clicks the Start button, so the action listener for that button is responsible for starting the simulation run.
When finished, submit a folder called hw9 to your eccentric upload account. This folder should contain all source code needed to compile and run your program.
Allocation of the 65 points is as follows: 10 points documentation, 30 points design and code structure, 25 points reliable and reasonable results.
[ Assignments | CSC 132 | Peter Sanderson | Computer Science | SMSU ]
Last reviewed: 20 November 2000
Peter Sanderson (
PeteSanderson@smsu.edu )