How to Perform Auction Based Resource Allocation using Cloudsim?
Share
Condition for Perform Auction Based Resource Allocation using Cloudsim
Description: To perform a Particle Swarm Optimization (PSO) scheduling algorithm in CloudSim, the task scheduling problem is treated as an optimization problem, where each particle represents a potential task-to-VM mapping. The PSO algorithm uses a population of particles, each with a position (task schedule) and velocity (changes in the schedule). The fitness of each particle is evaluated based on an objective function like minimizing makespan, energy consumption, or cost. Particles update their positions using their own best-known position and the global best-known position of the swarm. The algorithm iterates through multiple generations to converge on the optimal solution, stopping when a predefined criterion is met.
Define Users (Bidders) and Providers: The auction mechanism could be sealed-bid, where users submit bids in secret, or ascending-bid where users bid in real-time until no more bids are made. In a typical setup, the auction can be executed based on a reverse auction (where providers bid for the user) or a forward auction (where users bid for resources).
Set Up the Auction System: Each cloud user (buyer) will define the resources they need (e.g., VM specifications, bandwidth, storage) and their bid value (based on the cost they are willing to pay). The cloud provider (seller) will have a set of available resources, such as virtual machines, bandwidth, and storage.
Auction Process: Each user bids for the resources based on their requirements (e.g., required CPU, memory, storage, and duration). The provider evaluates these bids, and resources are allocated based on the highest bids or the most efficient allocation strategy. CloudSim can simulate this by using its broker and VM allocation policies to match the users with the appropriate resources.
Auction Process: Create the users (bidders): Define the resource needs and bids for each cloud user. Set up a broker: Use the DatacenterBroker to handle the resource allocation and submit VM requests to the cloud provider. Simulate the auction: Implement the bidding process, where each user submits a bid. The broker then evaluates the bids and allocates resources (VMs) to the users based on their bids.
Evaluate the Auction Results: After the auction, you can evaluate the outcome based on how efficiently the resources were allocated, the revenue generated by the provider, and the satisfaction of the users.
Sample Code
import org.cloudbus.cloudsim.*;
import org.cloudbus.cloudsim.lists.*;
import org.cloudbus.cloudsim.provisioners.*;
import java.util.*;
import org.cloudbus.cloudsim.core.CloudSim;
public class AuctionBasedResourceAllocation {
public static void main(String[] args) {
try {
int numUsers = 3; // Number of users (bidders)
int numVms = 5; // Number of VMs available for auction
// Initialize CloudSim
Calendar calendar = Calendar.getInstance();
boolean traceFlag = false;
CloudSim.init(numUsers, calendar, traceFlag);
// Create Datacenter
Datacenter datacenter = createDatacenter("Datacenter_1");
// Create Broker
DatacenterBroker broker = createBroker();
int brokerId = broker.getId();
// Create VMs
List vmList = new ArrayList<>();
for (int i = 0; i < numVms; i++) {
Vm vm = new Vm(i, brokerId, 1000, 1, 512, 1000, 10000, "Xen", new CloudletSchedulerTimeShared());
vmList.add(vm);
}
broker.submitVmList(vmList);
// Create Users (Bidders) with their bids
List users = new ArrayList<>();
for (int i = 0; i < numUsers; i++) {
User user = new User(i, (int) (Math.random() * 1000) + 500, // Random bid
(int) (Math.random() * 500) + 300); // Random VM requirement
users.add(user);
}
// Perform Auction: Assign VMs based on highest bid
assignResourcesToUsers(users, vmList);
// Start the simulation
CloudSim.startSimulation();
// Stop the simulation
CloudSim.stopSimulation();
// Print Results
List cloudletList = broker.getCloudletReceivedList();
printCloudletList(cloudletList);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void assignResourcesToUsers(List users, List vmList) {
// Sort users based on their bids (highest bid first)
users.sort((user1, user2) -> Integer.compare(user2.getBid(), user1.getBid()));
// Allocate VMs to users based on highest bids
for (int i = 0; i < users.size() && i < vmList.size(); i++) {
Vm vm = vmList.get(i);
User user = users.get(i);
System.out.println("User " + user.getId() + " allocated VM " + vm.getId() + " with bid " + user.getBid());
}
}
private static Datacenter createDatacenter(String name) {
List hostList = new ArrayList<>();
List peList = new ArrayList<>();
peList.add(new Pe(0, new PeProvisionerSimple(1000))); // One CPU with 1000 MIPS
int hostId = 0;
int ram = 2048;
long storage = 1000000;
int bw = 10000;
hostList.add(new Host(hostId, new RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList, new VmSchedulerTimeShared(peList)));
String arch = "x86";
String os = "Linux";
String vmm = "Xen";
double timeZone = 10.0;
double cost = 3.0;
double costPerMem = 0.05;
double costPerStorage = 0.001;
double costPerBw = 0.0;
LinkedList storageList = new LinkedList<>();
DatacenterCharacteristics characteristics = new DatacenterCharacteristics(arch, os, vmm, hostList, timeZone, cost, costPerMem, costPerStorage, costPerBw);
try {
return new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static DatacenterBroker createBroker() {
try {
return new DatacenterBroker("Broker");
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private static void printCloudletList(List list) {
int size = list.size();
Cloudlet cloudlet;
String indent = " ";
System.out.println();
System.out.println("========== OUTPUT ==========");
System.out.println("Cloudlet ID" + indent + "STATUS" + indent + "Resource ID" + indent + "VM ID");
for (int i = 0; i < size; i++) {
cloudlet = list.get(i);
System.out.println(indent + cloudlet.getCloudletId() + indent + cloudlet.getStatus() + indent + cloudlet.getResourceId() + indent + cloudlet.getVmId());
}
}
// User class to represent cloud users (bidders)
static class User {
private int id;
private int bid; // User's bid for resources
private int requiredResources;
public User(int id, int bid, int requiredResources) {
this.id = id;
this.bid = bid;
this.requiredResources = requiredResources;
}
public int getId() {
return id;
}
public int getBid() {
return bid;
}
public int getRequiredResources() {
return requiredResources;
}
}
}