|
@@ -77,21 +77,28 @@ public class FairCallQueue<E extends Schedulable> extends AbstractQueue<E>
|
|
|
|
|
|
/**
|
|
/**
|
|
* Create a FairCallQueue.
|
|
* Create a FairCallQueue.
|
|
- * @param capacity the maximum size of each sub-queue
|
|
|
|
|
|
+ * @param capacity the total size of all sub-queues
|
|
* @param ns the prefix to use for configuration
|
|
* @param ns the prefix to use for configuration
|
|
* @param conf the configuration to read from
|
|
* @param conf the configuration to read from
|
|
- * Notes: the FairCallQueue has no fixed capacity. Rather, it has a minimum
|
|
|
|
- * capacity of `capacity` and a maximum capacity of `capacity * number_queues`
|
|
|
|
|
|
+ * Notes: Each sub-queue has a capacity of `capacity / numSubqueues`.
|
|
|
|
+ * The first or the highest priority sub-queue has an excess capacity
|
|
|
|
+ * of `capacity % numSubqueues`
|
|
*/
|
|
*/
|
|
public FairCallQueue(int capacity, String ns, Configuration conf) {
|
|
public FairCallQueue(int capacity, String ns, Configuration conf) {
|
|
int numQueues = parseNumQueues(ns, conf);
|
|
int numQueues = parseNumQueues(ns, conf);
|
|
- LOG.info("FairCallQueue is in use with " + numQueues + " queues.");
|
|
|
|
|
|
+ LOG.info("FairCallQueue is in use with " + numQueues +
|
|
|
|
+ " queues with total capacity of " + capacity);
|
|
|
|
|
|
this.queues = new ArrayList<BlockingQueue<E>>(numQueues);
|
|
this.queues = new ArrayList<BlockingQueue<E>>(numQueues);
|
|
this.overflowedCalls = new ArrayList<AtomicLong>(numQueues);
|
|
this.overflowedCalls = new ArrayList<AtomicLong>(numQueues);
|
|
-
|
|
|
|
|
|
+ int queueCapacity = capacity / numQueues;
|
|
|
|
+ int capacityForFirstQueue = queueCapacity + (capacity % numQueues);
|
|
for(int i=0; i < numQueues; i++) {
|
|
for(int i=0; i < numQueues; i++) {
|
|
- this.queues.add(new LinkedBlockingQueue<E>(capacity));
|
|
|
|
|
|
+ if (i == 0) {
|
|
|
|
+ this.queues.add(new LinkedBlockingQueue<E>(capacityForFirstQueue));
|
|
|
|
+ } else {
|
|
|
|
+ this.queues.add(new LinkedBlockingQueue<E>(queueCapacity));
|
|
|
|
+ }
|
|
this.overflowedCalls.add(new AtomicLong(0));
|
|
this.overflowedCalls.add(new AtomicLong(0));
|
|
}
|
|
}
|
|
|
|
|