LoadBalance.java
public class
LoadBalance
{
public static void main(String[] args)
{
int M = Integer.parseInt(args[0]);
int N = Integer.parseInt(args[1]);
int S = Integer.parseInt(args[2]);
RandomQueue>
servers = new RandomQueue>();
for (int i = 0; i < M; i++)
{
servers.enqueue(new
Queue());
}
for (int j = 0; j < N; j++)
{
Queue min =
servers.sample();
for (int k = 1; k < S; k++)
{
Queue q =
servers.sample();
if (q.length() <
min.length()) min = q;
}
min.enqueue(j);
}
int i = 0;
double[] lengths = new double[M];
for (Queue q: servers)
{
lengths[i++] = q.length();
StdDraw.setYscale(0, 2.0*N/M);
StdStats.plotBars(lengths);
}
}
}
No comments:
Post a Comment