PDC@UNL

Distributed Computing - Java Demonstration

Code Demonstration - Java version

We have written a producer-consumer simulation in Java that is available in the same Eclipse project available at https://github.com/cbourke/PDCatUNL

We have provided several classes (in unl.soc.producer_consumer) that simulate a producer-consumer scenario:

  • RequestGenerator is the producer class. It runs continuously in its own thread and generates a new request at random intervals.
  • RequestHandler is the consumer class. It also runs continuously in its own thread and handles requests.
  • HttpDelayRequest is the actual request class that is generated and handled. It simply makes a dummy request to a webserver that "simulates" work by making an artificial delay between 2 and 5 seconds (randomly)
  • RequestManager coordinates the simulation by managing all the threads and keeping track of all requests in a blocking queue.
  • RequestMonitor is a special class that monitors the queue and reports how many requests are awaiting execution (it reports every 5 seconds).

Instructions

  1. Open the Simulation class and observe the parameters. You can specify how many RequestGenerators and RequestHandlers to create in the simulation and an interval that specifies how often each RequestGenerator generates a request (initially it is between 2 and 5 seconds).
  2. Run the simulation by running the Simulation class with the provided parameters and observe the output. The RequestGenerators and RequestHandlers report on each action and the RequestMonitor periodically reports how many tasks are waiting in the queue. The simulation runs continuously; to stop it you'll need to kill the program manually (the stop button in Eclipse).
  3. Run/rerun the simulation for a few minutes with the following parameters and observe and note the results.
  4. Number of Producers Number of Consumers Interval Min Interval Max
    5
    5
    2 6
    1
    5
    2 6
    5
    1 2 6
    5
    5
    1 2
    5
    5 5 10