Changeset 4c9558c


Ignore:
Timestamp:
Dec 15, 2010 5:08:11 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
fe575a3
Parents:
2deee2b1
Message:

adjust limits to reduce chance of running out; adjust limits based on max mem

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/crypto/YKGenerator.java

    r2deee2b1 r4c9558c  
    4242    private static final int MAX_NUM_BUILDERS;
    4343    private static final int CALC_DELAY;
    44     private static final LinkedBlockingQueue<BigInteger[]> _values = new LinkedBlockingQueue(50); // list of BigInteger[] values (y and k)
     44    private static final LinkedBlockingQueue<BigInteger[]> _values;
    4545    private static final Thread _precalcThread;
    4646    private static final I2PAppContext ctx;
     
    5454
    5555    /** check every 30 seconds whether we have less than the minimum */
    56     private static long CHECK_DELAY = 30 * 1000;
     56    private static long _checkDelay = 30 * 1000;
    5757
    5858    static {
    5959        ctx = I2PAppContext.getGlobalContext();
    60         MIN_NUM_BUILDERS = ctx.getProperty(PROP_YK_PRECALC_MIN, DEFAULT_YK_PRECALC_MIN);
    61         MAX_NUM_BUILDERS = ctx.getProperty(PROP_YK_PRECALC_MAX, DEFAULT_YK_PRECALC_MAX);
     60
     61        // add to the defaults for every 128MB of RAM, up to 1GB
     62        long maxMemory = Runtime.getRuntime().maxMemory();
     63        int factor = Math.min(8, (int) (1 + (maxMemory / (128*1024*1024l))));
     64        int defaultMin = DEFAULT_YK_PRECALC_MIN * factor;
     65        int defaultMax = DEFAULT_YK_PRECALC_MAX * factor;
     66        MIN_NUM_BUILDERS = ctx.getProperty(PROP_YK_PRECALC_MIN, defaultMin);
     67        MAX_NUM_BUILDERS = ctx.getProperty(PROP_YK_PRECALC_MAX, defaultMax);
     68
    6269        CALC_DELAY = ctx.getProperty(PROP_YK_PRECALC_DELAY, DEFAULT_YK_PRECALC_DELAY);
     70        _values = new LinkedBlockingQueue(MAX_NUM_BUILDERS);
    6371
    6472        //if (_log.shouldLog(Log.DEBUG))
     
    138146            negTime += endNeg - startNeg;
    139147        }
     148        // 173ms each on a 2008 netbook
    140149        System.out.println("YK fetch time for 5 runs: " + negTime + " @ " + negTime / 5l + "ms each");
    141150    }
    142151
    143152    private static class YKPrecalcRunner implements Runnable {
    144         private int _minSize;
    145         private int _maxSize;
     153        private final int _minSize;
     154        private final int _maxSize;
    146155
    147156        private YKPrecalcRunner(int minSize, int maxSize) {
     
    156165                int startSize = getSize();
    157166                // Adjust delay
    158                 if (startSize <= (_minSize / 2) && CHECK_DELAY > 1000)
    159                     CHECK_DELAY -= 1000;
    160                 else if (startSize > (_minSize * 2) && CHECK_DELAY < 60000)
    161                          CHECK_DELAY += 1000;
     167                if (startSize <= (_minSize * 2 / 3) && _checkDelay > 1000)
     168                    _checkDelay -= 1000;
     169                else if (startSize > (_minSize * 3 / 2) && _checkDelay < 60*1000)
     170                    _checkDelay += 1000;
    162171                curSize = startSize;
    163172                if (curSize < _minSize) {
     
    184193                //}
    185194                try {
    186                     Thread.sleep(CHECK_DELAY);
     195                    Thread.sleep(_checkDelay);
    187196                } catch (InterruptedException ie) { // nop
    188197                }
Note: See TracChangeset for help on using the changeset viewer.