Designing the web server simulator: helpful hints and information
1. Start with the applet. You will need a Start button, a textarea for output, a textfield to display the clock value (initially 0), plus textfields for each of the following integer inputs. Each has a default value which should be displayed in the field, but which can be changed by the user.
2. The key applet component will be the Start button's action listener. It will first need to get all the input fields (1a through 1e) and convert them to integers, using code similar to that from the BagApplet in Homework 3, e.g.
try { String userInput = targetText.getText( ); int whatever = Integer.parseInt(userInput); ..... } catch (NumberFormatException e) { feedback.append("invalid input.\n"); targetText.requestFocus( ); targetText.selectAll( ); }
3. After capturing all the inputs, the Start button's action listener then needs to create a Simulation object and call its run method. It should pass the following values to the run method as parameters:
4. Steps 2 and 3 are all that the Start button's action listener needs to do.
5. Turn your attention next to the Simulation class. Its constructor will create the clock, FEQ (which is a PrioQueue), and transmission port objects. It should also create all required Statistic objects, described in item 10 below. (This is a design choice; all of these things can alternatively be done in the run method. Doing them in the constructor forces the client to create a new Simulation object for each simulation run -- this will happen in the Start button's action listener anyway). Subsequently, all activities will be coordinated by its run method. Run is described in the next several items.
6. The actions of the run method are described in item 5 under Program Structure in the assignment. These are repeated in greater detail below. I strongly recommend you write the run method to expect all time parameters to be in microseconds (see #3 above) and all size parameters to be in bits. By doing this, time units at the user interface level can be modified without affecting any internal software component.
7. Run has two preliminary tasks to perform.
8. Here is a way to generate integer random values within a specified range. Call the low end of the range min and the high end max. There are a couple ways to do this; I’ll recommend the following: create a Random object, then use its nextInt(int N) method to get random values. This will return an integer in the range 0 through N-1. Your code then should look something like this:
ArriveTime = clock.getTime() + randu.nextInt(max-min+1) + min;
(the +1 will assure that the highest value added to the current clock value is actually max and not max-1). For step 7b, the clock will have value 0, but for subsequent arrivals it will not (see step 12 below).
9. Simulation activity is ultimately controlled by the run method’s loop. Each loop iteration will follow this sequence:
I strongly suggest that d and e be designed as two private methods in the Simulation class called arrival and completion. This will reduce the length of the run method.
10. After exiting the loop, output simulation results to the textarea. The assignment describes the results in items 1 through 4 under Simulation Output. You will need several Statistic objects. These should be declared as instance variables of the Simulation class and created in its constructor (or alternatively in run). One Statistic object will be needed to record delay times, one will be needed to record web page size for all requested pages, and one will be needed to record web page size for all transmitted pages (these last two will not be the same if requests are still waiting to be transmitted when simulation stops).
11. Steps 7 through 10 describe what the run method of the Simulation class does.
12. The Simulation class's arrival method handles arrivals to new web page requests. It will follow this sequence:
13. The Simulation class's completion method handles the completion of a web page transmission. It will follow this sequence:
That should just about cover it. Not in every detail, but in great detail.
To reiterate the default input parameters which were not included on the original handout.
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.
You can estimate transmission port utilization from this. Given the default values, there will be a web page request about once very 25 milliseconds, or 40 requests per second. An average request will be for about 4250 bytes, which is 34000 bits. So the demand on the system will be for about 40*34000 = 1,360,000 bits per second. Utilization should then be about 1,360,000/1,544,000 = 0.881 or just over 88%. This is pretty high, so expect significant queueing!
NOTE: The design described here is not an ideal object-oriented design because there is a higher degree of coupling between objects than necessary. One example is the simulation's run method displaying the clock value to the user interface each time the clock is updated. Ideally, the simulation's run mechanism would be isolated from the user interface. This can be done but it complicates the system structure somewhat. There is already enough complexity in this project!
[ Assignments | CSC 132 | Peter Sanderson | Computer Science | SMSU ]
Last reviewed: 30 November 2000
Peter Sanderson (
PeteSanderson@smsu.edu )