Skip to content

Mini Project Elastic Computing

shanmuga sudan edited this page Aug 2, 2017 · 2 revisions
  • Objective:
    To Design an elastic load-balancer that manages incoming user requests. The Load Balancer interacts with Machine Pool that supplies Machines to handle user requests.

  • Design Specifications:

  1. Machine Factory: An Entity that takes care of creating Machines and giving them to Dispatcher as and when requested.
  2. Dispatcher: An Entity that acts as a central point of receiving incoming user requests and assigns them to machines.
  3. Machine: An Entity that has a defined capacity which tells the processing capacity of machine.
  4. Request: An Enumeration type that has three categories namely, SMALL, MEDIUM, HIGH requests.
  5. Request Queue: An Entity that is basically a queue to line-up incoming user requests for a machine.
  • Design Patterns Used:
    Creational: Factory pattern – To create Machines of required specifications.
    Behavioral: Strategy pattern – To Manage Various Load Balancing Algorithms handled by Dispatcher.
  • Entity Description:
  1. Dispatcher:
    a. Attributes:
    1. RequestQueue – To pile up the incoming requests
    2. Collection of Machine – To pick up a machine that serve a request
    3. Map of Requests and Machines – To know the status of Machines and their filling capacity at any point of time.
    4. Successful Requests – That tells the volume of requests that were processed successfully.
    5. Weighted Successful Requests – That tells the weighted volume summing up the value of each request processed successfully.
  2. Failed Requests – That tells the volume of requests that failed during processing.
  3. Weighted Failure Requests – That tells the weighted volume summing up the value of each request that failed.
  4. An instance of Load Balancer Algorithm – To switch to an algorithm as and when required by the dispatcher.
    b. Methods:
    1. Requests new Machine from Machine Factory
    2. Add up the newly arrived machines to dispatcher’s list.
    3. Initialized hash map.
    4. Updates Hash map.
    5. Process requests.
    6. Update failed Requests.
    7. Picks up an algorithm. (method overloading - 1. To process a request ,2. To switch to a different algorithm)
    8. Redo the process to get a new machine.
  5. Machine: a. Attributes:
    1. Processing capacity - That tells the Maximum capacity which can be processed by the machine.
    2. Used Capacity – That tells the used capacity of the machine at any point of time.
    3. Is Machine Available - Flag to notify if the machine is available to process future requests
    4. Is Machine at Machine Pool - Flag to notify if the machine is available at Machine pool or assigned to Dispatcher.
    5. Mac Count: A unique Id to Identify a machine.
    6. Mac Name: A Name assigned to a machine.
    7. Request Queue - A Queue to pile up the assigned requests from dispatcher.
      b. Methods:
    8. Is Machine Full - Tells if the machine is full with capacity
    9. Add to Process - Adds the new requests to request queue.
    10. Machine Capacity
      a. Methods:
    11. Get Machine Capacity – That provides that max capacity of machine.
  6. Machine Factory:
    a. Attributes:
    1. Machine Pool List – That holds the collection of machines available at Machine Factory
      b. Methods:
    2. Get machines for dispatcher – That provides the requested set of machines based on the category.
    3. Delete machine from Machine Pool – That removes the machines given away to dispatcher from collection present at Machine Pool.
  7. Machine Size: An Enumeration that tells the category of Machines available.
    a. Attributes: SMALL, MEDIUM, LARGE, XLARGE
    b. Methods:
    1. Get machine capacity – That provides the actual capacity of machine.
  8. Request: An Enumeration that tells the category of requests available.  
    
    a. Attributes: SMALL, MEDIUM, LARGE
    b. Methods:
    1. Get Request Time – That tells the weight of request
  9. RequestQueue:
    a. Attributes:
    1. Two Instances of Node class
    2. Current size – Size of the request queue
      b. Methods:
    3. Is Empty
    4. Enqueue
    5. Dequeue
    6. Has Next
    7. Next
      c. Inner Class: Node
      a. Attributes:
    8. Request Instance- That acts as a reference to next request
    9. Next – Holds the reference to next node instance pointer.
  • Algorithm:
  1. Load Balancer Algorithm Factory – A class to create instances of Load Balancer algorithm to be used by the dispatcher
  2. Load Balancer Algorithm – An Interface that extends Comparator interface to help sort the machines used in dispatcher based on any required implementation.
  3. Least Connections – The Implementation Algorithm used for this project work.
    a. Attributes:
    1. Dispatcher – An Instance of Dispatcher that is dealing with this algorithm
    2. Exhausted Machines – A Map of Integer and Hash Set of Machines as Key, value pairs.
      b. Methods:
    3. Look for Availability – First method to be called to check availability of machines.
    4. Best possible Machine – Per least connections, we compute the best possible machine using the max. capacity and used capacity of machines.
      Sorting is a key strategy used here and is carried out by another method.
    5. Look for left over space – checks if the any machine at Dispatcher has any leftover space to process a request before requesting for new machines from machine pool.
    6. Check Max Available Used Capacity Instance value – That checks if a request exceeds the available space for the picked machine. If true, then a total scan of all machines is performed to request for new machines.
    7. Scan all Machines – Method to compute the ratio of filled capacity to actual processing capacity of machines present in the dispatcher.
    8. Check fill Ratio – Method to check If the filled ratio is more than the threshold so that new machines can be requested.
    9. Add resources to Map – Add up the left-over machines for which the used capacity is more than actual request of higher order and that could process low weighted requests.
    10. Check and Add resource in Respective space – That adds the machine to a category in map based on the weight of request.
    11. Request Machines from machine pool – That adds newly received machines from machine pool to its look up.
    12. Sort Machines – To sort the machines based on max available capacity order.
    13. Compare – an implementation for comparator interface.
  • Exception:
  1. Resource Exhausted Exception – thrown when the machine pool runs short of created machines and dispatcher cannot process any more incoming requests.
  • Flow Chart: Flow chart

  • sample code: Sample code

  • sample output: Sample output

Clone this wiki locally