IDEMPIERE-4405 Add basic cache statistics (#210)
add hit and miss count for cache
This commit is contained in:
parent
7894bd9ef4
commit
147eebb01b
|
@ -24,6 +24,7 @@ import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import org.adempiere.base.Service;
|
import org.adempiere.base.Service;
|
||||||
import org.idempiere.distributed.ICacheService;
|
import org.idempiere.distributed.ICacheService;
|
||||||
|
@ -136,6 +137,9 @@ public class CCache<K,V> implements CacheInterface, Map<K, V>, Serializable
|
||||||
/** Vetoable Change Support Name */
|
/** Vetoable Change Support Name */
|
||||||
private static String PROPERTYNAME = "cache";
|
private static String PROPERTYNAME = "cache";
|
||||||
|
|
||||||
|
private final AtomicLong m_hit = new AtomicLong();
|
||||||
|
private final AtomicLong m_miss = new AtomicLong();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get (table) Name
|
* Get (table) Name
|
||||||
* @return name
|
* @return name
|
||||||
|
@ -227,7 +231,10 @@ public class CCache<K,V> implements CacheInterface, Map<K, V>, Serializable
|
||||||
{
|
{
|
||||||
return "CCache[" + m_name
|
return "CCache[" + m_name
|
||||||
+ ",Exp=" + getExpireMinutes()
|
+ ",Exp=" + getExpireMinutes()
|
||||||
+ ", #" + cache.size() + "]";
|
+ ", #" + cache.size()
|
||||||
|
+ ", Hit=" + getHit()
|
||||||
|
+ ", Miss=" + getMiss()
|
||||||
|
+ "]";
|
||||||
} // toString
|
} // toString
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -294,7 +301,12 @@ public class CCache<K,V> implements CacheInterface, Map<K, V>, Serializable
|
||||||
public V get(Object key)
|
public V get(Object key)
|
||||||
{
|
{
|
||||||
expire();
|
expire();
|
||||||
return cache.get(key);
|
V v = cache.get(key);
|
||||||
|
if (v == null)
|
||||||
|
m_miss.getAndAdd(1);
|
||||||
|
else
|
||||||
|
m_hit.getAndAdd(1);
|
||||||
|
return v;
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -431,4 +443,12 @@ public class CCache<K,V> implements CacheInterface, Map<K, V>, Serializable
|
||||||
public boolean isDistributed() {
|
public boolean isDistributed() {
|
||||||
return m_distributed;
|
return m_distributed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getHit() {
|
||||||
|
return m_hit.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getMiss() {
|
||||||
|
return m_miss.get();
|
||||||
|
}
|
||||||
} // CCache
|
} // CCache
|
||||||
|
|
|
@ -61,6 +61,8 @@ public class CacheInfo implements Serializable {
|
||||||
private boolean distributed;
|
private boolean distributed;
|
||||||
private InetAddress nodeAddress;
|
private InetAddress nodeAddress;
|
||||||
private String nodeId;
|
private String nodeId;
|
||||||
|
private long hit;
|
||||||
|
private long miss;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -72,6 +74,8 @@ public class CacheInfo implements Serializable {
|
||||||
expireMinutes = cache.getExpireMinutes();
|
expireMinutes = cache.getExpireMinutes();
|
||||||
maxSize = cache.getMaxSize();
|
maxSize = cache.getMaxSize();
|
||||||
distributed = cache.isDistributed();
|
distributed = cache.isDistributed();
|
||||||
|
hit = cache.getHit();
|
||||||
|
miss = cache.getMiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,6 +135,22 @@ public class CacheInfo implements Serializable {
|
||||||
return nodeId;
|
return nodeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return hit count
|
||||||
|
*/
|
||||||
|
public long getHit() {
|
||||||
|
return hit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return miss count
|
||||||
|
*/
|
||||||
|
public long getMiss() {
|
||||||
|
return miss;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param sortByName
|
* @param sortByName
|
||||||
|
|
|
@ -1435,6 +1435,8 @@ public class AdempiereMonitor extends HttpServlet
|
||||||
line.addElement(new th().addElement("Size"));
|
line.addElement(new th().addElement("Size"));
|
||||||
line.addElement(new th().addElement("Expire (Minutes)"));
|
line.addElement(new th().addElement("Expire (Minutes)"));
|
||||||
line.addElement(new th().addElement("Max Size"));
|
line.addElement(new th().addElement("Max Size"));
|
||||||
|
line.addElement(new th().addElement("Hit"));
|
||||||
|
line.addElement(new th().addElement("Miss"));
|
||||||
line.addElement(new th().addElement("Distributed"));
|
line.addElement(new th().addElement("Distributed"));
|
||||||
table.addElement(line);
|
table.addElement(line);
|
||||||
|
|
||||||
|
@ -1453,6 +1455,8 @@ public class AdempiereMonitor extends HttpServlet
|
||||||
line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getSize())));
|
line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getSize())));
|
||||||
line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getExpireMinutes())));
|
line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getExpireMinutes())));
|
||||||
line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getMaxSize())));
|
line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getMaxSize())));
|
||||||
|
line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getHit())));
|
||||||
|
line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getMiss())));
|
||||||
line.addElement(new td().addElement(WebEnv.getCellContent(ccache.isDistributed())));
|
line.addElement(new td().addElement(WebEnv.getCellContent(ccache.isDistributed())));
|
||||||
if (ccache.getNodeId() != null)
|
if (ccache.getNodeId() != null)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue