- Type Parameters:
E- type of elements in this queue, extendingCDPQEntry
- All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>
Extends CoDelBlockingQueue to add priority-based dropping functionality. Implements enhanced CoDel algorithm with configurable priority thresholds and per-priority statistics.
Provides priority-aware packet dropping where higher priority packets are protected from dropping during congestion events. Includes comprehensive statistics tracking and performance monitoring for different priority levels.
Input methods are overridden to add timestamps for delay calculation. Output methods implement AQM behavior with enhanced statistics tracking for priority-based operations.
- See Also:
Field Summary
Modifier and TypeFieldDescription(package private) static final AtomicLongUnique ID generator for instances.private intPackets dropped since going into drop state.private longTime to drop next packet.private booleanTrue if in drop state.private longTime when we'll declare we're above target (0 if below).private final longInstance ID.private longCoDel interval in ms.private intLast dropped priority.private longPer-request global for ease of use, locked by this.private longCoDel target delay in ms.private static final longHow long a job may wait before it counts as backlog, in ms.private static final long[]Rate windows kept for the backlog statistics.private static final intQuote: A setting of 100 ms works well across a range of RTTs from 10 ms to 1 secondprivate static final intQuote: Below a target of 5 ms, utilization suffers for some conditions and traffic loads; above 5 ms there is very little or no improvement in utilization.static final intPriorities at or above this value are never dropped.private static final CopyOnWriteArrayList<WeakReference<CoDelPriorityBlockingQueue>> Active instances for dynamic tuning — weak refs prevent leak when tunnels expire.static final intMinimum priority.private static final int[]Priority values assigned to the job classes.static final StringProperty key for CoDel interval.static final StringProperty key for CoDel target delay.private final StringStat name for delay tracking.private final StringRateStat name for dropped messages.Fields inherited from class PriBlockingQueue
_context, _log, _name, DEFAULT_BACKLOG_SIZE, DEFAULT_MAX_SIZE, PROP_BACKLOG_SIZE, PROP_MAX_SIZEModifier and TypeFieldDescriptionprotected final I2PAppContextThe I2P application context.protected final LogThe log instance.protected final StringThe queue name.protected static final intDefault backlog size threshold, depends on system speed.protected static final intDefault maximum queue size.static final StringProperty key for backlog threshold.static final StringProperty key for maximum queue size.Constructor Summary
ConstructorsConstructorDescriptionCoDelPriorityBlockingQueue(I2PAppContext ctx, String name, int initialCapacity) CoDel priority blocking queue with default target and interval.CoDelPriorityBlockingQueue(I2PAppContext ctx, String name, int initialCapacity, int target, int interval) Creates a queue and registers the per-priority drop stats and the delay stat under the given queue name, so the tuning page can graph them per queue.Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the queue and reset CoDel state.private EApply CoDel control to the given entry, dropping if needed.private voidcontrol_law(long t) Caller must synch on this.static StringdelayDescription(String queueName) Description for a queue's mean delay stat.private Edeque()Dequeue the next element, applying CoDel drops as needed.voiddispose()Remove this instance from the tuning list.intdrainAllTo(Collection<? super E> c) Drains all, without updating stats or dropping.intdrainTo(Collection<? super E> c) Updates stats and possibly drops while draining.intdrainTo(Collection<? super E> c, int maxElements) Updates stats and possibly drops while draining.private voidDrops a job that waited too long in the backlog.static StringdropDescription(String queueName, int priority) Description for a queue's per-priority drop-delay stat.static voidRemove cleared (GC'd) weak references from the list.private voidTakes the current time for the backlog measurement.longThe CoDel measuring interval, the sliding window over which the minimum queuing delay is observed.longThe CoDel target queuing delay, the delay considered acceptable before the queue is judged congested.booleanHas the head of the queue been waiting too long, or is the queue too big?poll()Poll the next element, applying CoDel drops as needed.voidsetInterval(long interval) Current CoDel interval in ms.voidsetTarget(long target) Current CoDel target delay in ms.take()Take the next element, applying CoDel drops as needed.protected voidTimestamp the added element.static voidupdateAllIntervals(long interval) Update the interval for all active instances.static voidupdateAllTargets(long target) Update the target delay for all active instances.private booleanupdateVars(E entry) Caller must synch on this.Methods inherited from class PriBlockingQueue
offerMethods inherited from class PriorityBlockingQueue
add, comparator, contains, forEach, iterator, offer, peek, poll, put, remainingCapacity, remove, removeAll, removeIf, retainAll, size, spliterator, toArray, toArray, toStringMethods inherited from class AbstractQueue
addAll, element, removeMethods inherited from class AbstractCollection
containsAll, isEmptyMethods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Collection
equals, hashCode, parallelStream, stream, toArray
Field Details
_first_above_time
private long _first_above_timeTime when we'll declare we're above target (0 if below). Part of the CoDel sample-code state, locked by this queue._drop_next
private long _drop_nextTime to drop next packet._count
private int _countPackets dropped since going into drop state._dropping
private boolean _droppingTrue if in drop state._now
private volatile long _nowPer-request global for ease of use, locked by this._lastDroppedPriority
private int _lastDroppedPriorityLast dropped priority.__id
Unique ID generator for instances._id
private final long _idInstance ID.CODEL_RATES
private static final long[] CODEL_RATESRate windows kept for the backlog statistics.DEFAULT_CODEL_TARGET
private static final int DEFAULT_CODEL_TARGETQuote: Below a target of 5 ms, utilization suffers for some conditions and traffic loads; above 5 ms there is very little or no improvement in utilization.I2P: Lowered to 5ms for reduced latency in high-performance scenarios.
- See Also:
PROP_CODEL_TARGET
Property key for CoDel target delay.- See Also:
_target
private volatile long _targetCoDel target delay in ms.DEFAULT_CODEL_INTERVAL
private static final int DEFAULT_CODEL_INTERVALQuote: A setting of 100 ms works well across a range of RTTs from 10 ms to 1 secondI2P: Lowered to 50ms for faster reaction to congestion.
- See Also:
PROP_CODEL_INTERVAL
Property key for CoDel interval.- See Also:
_interval
private volatile long _intervalCoDel interval in ms.STAT_DROP
RateStat name for dropped messages.INSTANCES
Active instances for dynamic tuning — weak refs prevent leak when tunnels expire.STAT_DELAY
Stat name for delay tracking.MIN_PRIORITY
PRIORITIES
private static final int[] PRIORITIESPriority values assigned to the job classes.DONT_DROP_PRIORITY
public static final int DONT_DROP_PRIORITYPriorities at or above this value are never dropped.- See Also:
BACKLOG_TIME
private static final long BACKLOG_TIMEHow long a job may wait before it counts as backlog, in ms.
Constructor Details
CoDelPriorityBlockingQueue
CoDel priority blocking queue with default target and interval.- Parameters:
ctx- the I2P application contextname- a name for this queue instanceinitialCapacity- the initial capacity for the priority queue
CoDelPriorityBlockingQueue
public CoDelPriorityBlockingQueue(I2PAppContext ctx, String name, int initialCapacity, int target, int interval) Creates a queue and registers the per-priority drop stats and the delay stat under the given queue name, so the tuning page can graph them per queue.- Parameters:
ctx- context supplying the stat manager the stats are created inname- the queue's short name, used as the stat name prefixinitialCapacity- the number of entries to size the internal array fortarget- CoDel target delay in ms, the queueing delay the controller aims forinterval- CoDel interval in ms, how long to sample before deciding to drop
Method Details
dispose
public void dispose()Remove this instance from the tuning list.expungeStaleInstances
public static void expungeStaleInstances()Remove cleared (GC'd) weak references from the list.updateAllTargets
public static void updateAllTargets(long target) Update the target delay for all active instances.- Parameters:
target- the new target delay in ms
updateAllIntervals
public static void updateAllIntervals(long interval) Update the interval for all active instances.- Parameters:
interval- the new interval in ms
delayDescription
Description for a queue's mean delay stat.Names the queue because several queues publish the same measure: OBGW and UDP-Sender both come through here, and IBGW, UDP-Receiver and UDP-MessageReceiver register theirs by hand. A single shared description left five graphs in the list called "Average queue delay (ms)", indistinguishable from one another.
- Parameters:
queueName- the queue's short name, as used in its stat names- Returns:
- the stat description, which names the queue so that queues sharing this measure are distinguishable on the tuning page
dropDescription
Description for a queue's per-priority drop-delay stat.Names the queue as well as the priority, for the same reason: without it
codel.OBGW.drop.0andcodel.UDP-Sender.drop.0were two graphs with the same name.- Parameters:
queueName- the queue's short name, as used in its stat namespriority- the CoDel priority band- Returns:
- the stat description, naming both the queue and the priority band so their drop-delay graphs are distinguishable
getTarget
public long getTarget()The CoDel target queuing delay, the delay considered acceptable before the queue is judged congested.- Returns:
- the target delay in ms
setTarget
public void setTarget(long target) Current CoDel target delay in ms.- Parameters:
target- the new target delay in ms
getInterval
public long getInterval()The CoDel measuring interval, the sliding window over which the minimum queuing delay is observed.- Returns:
- the interval in ms
setInterval
public void setInterval(long interval) Current CoDel interval in ms.- Parameters:
interval- the new interval in ms
clear
public void clear()Clear the queue and reset CoDel state.- Specified by:
clearin interfaceCollection<E extends CDPQEntry>- Overrides:
clearin classPriorityBlockingQueue<E extends CDPQEntry>
take
Take the next element, applying CoDel drops as needed.- Specified by:
takein interfaceBlockingQueue<E extends CDPQEntry>- Overrides:
takein classPriorityBlockingQueue<E extends CDPQEntry>- Throws:
InterruptedException
poll
drainTo
Updates stats and possibly drops while draining.- Specified by:
drainToin interfaceBlockingQueue<E extends CDPQEntry>- Overrides:
drainToin classPriorityBlockingQueue<E extends CDPQEntry>
drainTo
Updates stats and possibly drops while draining.- Specified by:
drainToin interfaceBlockingQueue<E extends CDPQEntry>- Overrides:
drainToin classPriorityBlockingQueue<E extends CDPQEntry>
drainAllTo
Drains all, without updating stats or dropping.- Parameters:
c- the collection to drain into- Returns:
- the number of elements drained
isBacklogged
public boolean isBacklogged()Has the head of the queue been waiting too long, or is the queue too big?- Overrides:
isBackloggedin classPriBlockingQueue<E extends CDPQEntry>- Returns:
- true if the head has waited out the backlog delay, the queue is already dropping, or the backlog size limit has been reached
timestamp
Timestamp the added element.- Overrides:
timestampin classPriBlockingQueue<E extends CDPQEntry>- Parameters:
o- the element to timestamp
updateVars
Caller must synch on this.- Parameters:
entry- may be null- Returns:
- true if the sojourn time has stayed above target for at least the interval, making it OK to drop
getCurrentTime
private void getCurrentTime()Takes the current time for the backlog measurement.deque
Dequeue the next element, applying CoDel drops as needed.- Returns:
- if null, call again
- Throws:
InterruptedException- if interrupted while waiting for the next element
codel
drop
Drops a job that waited too long in the backlog.- Parameters:
entry- the job to drop
control_law
private void control_law(long t) Caller must synch on this.- Parameters:
t- the time, in ms, to schedule the next drop from