forked from I2P_Developers/i2p.i2p
* SDSCache: Reduce min and increase max size
* SimpleByteCache: Change from LBQ to ABQ to reduce object churn
This commit is contained in:
@ -45,8 +45,8 @@ public class SDSCache<V extends SimpleDataStructure> {
|
||||
//private static final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(SDSCache.class);
|
||||
|
||||
private static final Class[] conArg = new Class[] { byte[].class };
|
||||
private static final double MIN_FACTOR = 0.25;
|
||||
private static final double MAX_FACTOR = 3.0;
|
||||
private static final double MIN_FACTOR = 0.20;
|
||||
private static final double MAX_FACTOR = 5.0;
|
||||
private static final double FACTOR;
|
||||
static {
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
|
@ -2,6 +2,7 @@ package net.i2p.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
@ -19,6 +20,9 @@ public final class SimpleByteCache {
|
||||
|
||||
private static final int DEFAULT_SIZE = 16;
|
||||
|
||||
/** up to this, use ABQ to minimize object churn and for performance; above this, use LBQ for two locks */
|
||||
private static final int MAX_FOR_ABQ = 64;
|
||||
|
||||
/**
|
||||
* Get a cache responsible for arrays of the given size
|
||||
*
|
||||
@ -58,11 +62,11 @@ public final class SimpleByteCache {
|
||||
/** list of available and available entries */
|
||||
private Queue<byte[]> _available;
|
||||
private int _maxCached;
|
||||
private int _entrySize;
|
||||
private final int _entrySize;
|
||||
|
||||
private SimpleByteCache(int maxCachedEntries, int entrySize) {
|
||||
_available = new LinkedBlockingQueue(maxCachedEntries);
|
||||
_maxCached = maxCachedEntries;
|
||||
_available = createQueue();
|
||||
_entrySize = entrySize;
|
||||
}
|
||||
|
||||
@ -70,13 +74,23 @@ public final class SimpleByteCache {
|
||||
if (_maxCached >= maxCachedEntries) return;
|
||||
_maxCached = maxCachedEntries;
|
||||
// make a bigger one, move the cached items over
|
||||
Queue<byte[]> newLBQ = new LinkedBlockingQueue(maxCachedEntries);
|
||||
Queue<byte[]> newLBQ = createQueue();
|
||||
byte[] ba;
|
||||
while ((ba = _available.poll()) != null)
|
||||
newLBQ.offer(ba);
|
||||
_available = newLBQ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LBQ or ABQ
|
||||
* @since 0.9.2
|
||||
*/
|
||||
private Queue<byte[]> createQueue() {
|
||||
if (_maxCached <= MAX_FOR_ABQ)
|
||||
return new ArrayBlockingQueue(_maxCached);
|
||||
return new LinkedBlockingQueue(_maxCached);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next available array, either from the cache or a brand new one
|
||||
*/
|
||||
|
Reference in New Issue
Block a user