Changeset 3347788


Ignore:
Timestamp:
Sep 6, 2012 7:53:01 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3c95f0b6
Parents:
0c5b4c0
Message:

add isBacklogged()

Location:
router/java/src/net/i2p/router/util
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/util/CoDelBlockingQueue.java

    r0c5b4c0 r3347788  
    3030    private final Log _log;
    3131    private final String _name;
     32    private final int _capacity;
    3233
    3334    // following 4 are state variables defined by sample code, locked by this
     
    6970    private final String STAT_DELAY;
    7071    private static final long[] RATES = {5*60*1000, 60*60*1000};
     72    private static final long BACKLOG_TIME = 2*1000;
    7173
    7274    /**
     
    7880        _log = ctx.logManager().getLog(CoDelBlockingQueue.class);
    7981        _name = name;
     82        _capacity = capacity;
    8083        STAT_DROP = "codel." + name + ".drop";
    8184        STAT_DELAY = "codel." + name + ".delay";
     
    167170    public int drainAllTo(Collection<? super E> c) {
    168171        return super.drainTo(c);
     172    }
     173
     174    /**
     175     *  Has the head of the queue been waiting too long,
     176     *  or is the queue almost full?
     177     */
     178    public boolean isBacklogged() {
     179        E e = peek();
     180        if (e == null)
     181            return false;
     182        return _context.clock().now() - e.getEnqueueTime() >= BACKLOG_TIME ||
     183               remainingCapacity() < _capacity / 4;
    169184    }
    170185
  • router/java/src/net/i2p/router/util/CoDelPriorityBlockingQueue.java

    r0c5b4c0 r3347788  
    7777    /** if priority is >= this, never drop */
    7878    public static final int DONT_DROP_PRIORITY = 1000;
     79    private static final long BACKLOG_TIME = 2*1000;
    7980
    8081    /**
     
    153154    public int drainAllTo(Collection<? super E> c) {
    154155        return super.drainTo(c);
     156    }
     157
     158    /**
     159     *  Has the head of the queue been waiting too long,
     160     *  or is the queue too big?
     161     */
     162    @Override
     163    public boolean isBacklogged() {
     164        E e = peek();
     165        if (e == null)
     166            return false;
     167        return _context.clock().now() - e.getEnqueueTime() >= BACKLOG_TIME ||
     168               size() >= BACKLOG_SIZE;
    155169    }
    156170
  • router/java/src/net/i2p/router/util/PriBlockingQueue.java

    r0c5b4c0 r3347788  
    1818
    1919    private final AtomicLong _seqNum = new AtomicLong();
     20
     21    protected static final int BACKLOG_SIZE = 256;
    2022
    2123    public PriBlockingQueue(int initialCapacity) {
     
    4749    }
    4850
     51    /**
     52     *  Is the queue too big?
     53     */
     54    public boolean isBacklogged() {
     55        return size() >= BACKLOG_SIZE;
     56    }
     57
    4958    /////// private below here
    5059
Note: See TracChangeset for help on using the changeset viewer.