You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directmemory.apache.org by ra...@apache.org on 2011/10/18 21:38:14 UTC
svn commit: r1185815 -
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/OffHeapMemoryBuffer.java
Author: raffaeleguidi
Date: Tue Oct 18 19:38:14 2011
New Revision: 1185815
URL: http://svn.apache.org/viewvc?rev=1185815&view=rev
Log:
added a very basic check to avoid unnecessary LFU eviction if we are not in shortage of free buffers
Modified:
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/OffHeapMemoryBuffer.java
Modified: incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/OffHeapMemoryBuffer.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/OffHeapMemoryBuffer.java?rev=1185815&r1=1185814&r2=1185815&view=diff
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/OffHeapMemoryBuffer.java (original)
+++ incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/OffHeapMemoryBuffer.java Tue Oct 18 19:38:14 2011
@@ -44,7 +44,8 @@ public class OffHeapMemoryBuffer {
// public List<Pointer> pointers = new CopyOnWriteArrayList<Pointer>();
AtomicInteger used = new AtomicInteger();
public int bufferNumber;
-
+ public int allocationErrors = 0;
+ public static int maxAllocationErrors = 0;
public int used() {
return used.get();
@@ -138,6 +139,7 @@ public class OffHeapMemoryBuffer {
}
public void clear() {
+ allocationErrors = 0;
pointers.clear();
createAndAddFirstPointer();
buffer.clear();
@@ -156,7 +158,8 @@ public class OffHeapMemoryBuffer {
Pointer goodOne = firstMatch(payload.length);
if (goodOne == null ) {
- throw new NullPointerException("did not find a suitable buffer");
+ allocationErrors++;
+ throw new NullPointerException("did not find a suitable buffer " + allocationErrors + " times since last cleanup");
}
Pointer fresh = slice(goodOne, payload.length);
@@ -201,7 +204,15 @@ public class OffHeapMemoryBuffer {
return qr;
}
+ private boolean inShortage() {
+ // a place holder for a more refined version
+ return allocationErrors > OffHeapMemoryBuffer.maxAllocationErrors;
+ }
+
public long collectLFU(int limit) {
+ if (!inShortage()) {
+ return 0;
+ }
if (limit<=0) limit = pointers.size()/10;
QueryResults qr;
try {