-
Notifications
You must be signed in to change notification settings - Fork 0
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:
- Machine Factory: An Entity that takes care of creating Machines and giving them to Dispatcher as and when requested.
- Dispatcher: An Entity that acts as a central point of receiving incoming user requests and assigns them to machines.
- Machine: An Entity that has a defined capacity which tells the processing capacity of machine.
- Request: An Enumeration type that has three categories namely, SMALL, MEDIUM, HIGH requests.
- 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:
- Dispatcher:
a. Attributes:- RequestQueue – To pile up the incoming requests
- Collection of Machine – To pick up a machine that serve a request
- Map of Requests and Machines – To know the status of Machines and their filling capacity at any point of time.
- Successful Requests – That tells the volume of requests that were processed successfully.
- Weighted Successful Requests – That tells the weighted volume summing up the value of each request processed successfully.
- Failed Requests – That tells the volume of requests that failed during processing.
- Weighted Failure Requests – That tells the weighted volume summing up the value of each request that failed.
- An instance of Load Balancer Algorithm – To switch to an algorithm as and when required by the dispatcher.
b. Methods:- Requests new Machine from Machine Factory
- Add up the newly arrived machines to dispatcher’s list.
- Initialized hash map.
- Updates Hash map.
- Process requests.
- Update failed Requests.
- Picks up an algorithm. (method overloading - 1. To process a request ,2. To switch to a different algorithm)
- Redo the process to get a new machine.
- Machine:
a. Attributes:
- Processing capacity - That tells the Maximum capacity which can be processed by the machine.
- Used Capacity – That tells the used capacity of the machine at any point of time.
- Is Machine Available - Flag to notify if the machine is available to process future requests
- Is Machine at Machine Pool - Flag to notify if the machine is available at Machine pool or assigned to Dispatcher.
- Mac Count: A unique Id to Identify a machine.
- Mac Name: A Name assigned to a machine.
- Request Queue - A Queue to pile up the assigned requests from dispatcher.
b. Methods: - Is Machine Full - Tells if the machine is full with capacity
- Add to Process - Adds the new requests to request queue.
- Machine Capacity
a. Methods: - Get Machine Capacity – That provides that max capacity of machine.
- Machine Factory:
a. Attributes:- Machine Pool List – That holds the collection of machines available at Machine Factory
b. Methods: - Get machines for dispatcher – That provides the requested set of machines based on the category.
- Delete machine from Machine Pool – That removes the machines given away to dispatcher from collection present at Machine Pool.
- Machine Pool List – That holds the collection of machines available at Machine Factory
- Machine Size: An Enumeration that tells the category of Machines available.
a. Attributes: SMALL, MEDIUM, LARGE, XLARGE
b. Methods:- Get machine capacity – That provides the actual capacity of machine.
-
a. Attributes: SMALL, MEDIUM, LARGE
Request: An Enumeration that tells the category of requests available.
b. Methods:- Get Request Time – That tells the weight of request
- RequestQueue:
a. Attributes:- Two Instances of Node class
- Current size – Size of the request queue
b. Methods: - Is Empty
- Enqueue
- Dequeue
- Has Next
- Next
c. Inner Class: Node
a. Attributes: - Request Instance- That acts as a reference to next request
- Next – Holds the reference to next node instance pointer.
Algorithm:
- Load Balancer Algorithm Factory – A class to create instances of Load Balancer algorithm to be used by the dispatcher
- Load Balancer Algorithm – An Interface that extends Comparator interface to help sort the machines used in dispatcher based on any required implementation.
- Least Connections – The Implementation Algorithm used for this project work.
a. Attributes:- Dispatcher – An Instance of Dispatcher that is dealing with this algorithm
- Exhausted Machines – A Map of Integer and Hash Set of Machines as Key, value pairs.
b. Methods: - Look for Availability – First method to be called to check availability of machines.
- 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. - 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.
- 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.
- Scan all Machines – Method to compute the ratio of filled capacity to actual processing capacity of machines present in the dispatcher.
- Check fill Ratio – Method to check If the filled ratio is more than the threshold so that new machines can be requested.
- 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.
- Check and Add resource in Respective space – That adds the machine to a category in map based on the weight of request.
- Request Machines from machine pool – That adds newly received machines from machine pool to its look up.
- Sort Machines – To sort the machines based on max available capacity order.
- Compare – an implementation for comparator interface.
Exception:
- Resource Exhausted Exception – thrown when the machine pool runs short of created machines and dispatcher cannot process any more incoming requests.
-
Flow Chart:
-
sample code:
-
sample output: