Reputation: 786
Question Background:
We are rolling out an upgrade to a 3rd party application that uses ehcache for caching. We plan to have four servers clustered in production.
The vendor has provided the default ehcache configuration to cluster over rmi, using multicast to discover the peers.
The problem is that our network does not support multicast in the short term, so we are having to overwrite the default configuration to manually specify the peers. Using terracotta is out of the question due to budget constraints.
As this is an upgrade project, I will not be able to truly test the results of the manual configuration until go-live. The manual configuration is many characters long, manually written, so there is risk that errors may exist.
My question
Is there an open source jsp or similar that can be used to display the cache clustering information to the screen. We can incorporate this into the 3rd party application, and use it to quickly validate that the peers were discovered correctly.
What I've looked into
I've used google to search for ehache, but my filtering skills have failed to narrow down the results to anything useful.
I've looked at using logs to track when caching occurs, and am not 100% happy with this approach.
Failing to find a pre-built solution will require me to write my own.
Upvotes: 0
Views: 1051
Reputation: 114
Ehcache monitoring tool is available which gives cache statistics. Some references.
Upvotes: 1
Reputation: 86
Regarding terracotta and budget constraints - there is a free open-source version as well: see http://terracotta.org/downloads/open-source/catalog
A commercial license is needed as soon as you want to use offheap memory, distributed search or horizontal scaling, but since your use case seems to involve only basic syncing between nodes the open-source version would be sufficient.
Letting the terracotta server sync your caches means less network overhead and improved consistency guarantees (which are not given using peer-to-peer replication).
Upvotes: 1
Reputation: 786
I had to write this myself. Here is the code if others need it.
@Controller
@RequestMapping(value = "/tools/ehcache")
public class EhcacheManagerController {
private static final String VIEW_URL = "/WEB-INF/views/tools/ehcache/ehcache.jsp";
private static final String ALL = "all";
List<CacheManager> allCacheManagers = CacheManager.ALL_CACHE_MANAGERS;
private static final Log logger = LogFactory.getLog(EhcacheManagerController.class);
@RequestMapping(method = RequestMethod.GET)
protected String loadPage(ModelMap modelMap) throws Exception {
// Manager (keyed by name) --> Cache (keyed by name) --> Peer Information (keyed by peer Name)
Map<String,Map<String,Map<String,String>>> managerMap = new HashMap<String,Map<String,Map<String,String>>>();
for (CacheManager cacheManager : allCacheManagers) {
Map<String,Map<String,String>> cacheMap = new HashMap<String,Map<String,String>>();
managerMap.put(cacheManager.getName(), cacheMap);
String[] cacheNames = cacheManager.getCacheNames();
for (String name : cacheNames) {
Map<String,String> peerInfoMap = new HashMap<String,String>();
cacheMap.put(name,peerInfoMap);
CacheManagerPeerProvider provider = cacheManager.getCacheManagerPeerProvider("RMI");
if (provider == null) {
peerInfoMap.put("nopeer","no status");
break;
}
Cache ehcache = cacheManager.getCache(name);
List<CachePeer> cachePeers = provider.listRemoteCachePeers(ehcache);
for (CachePeer cachePeer : cachePeers) {
StringBuilder cacheStatus = new StringBuilder();
String peerName = cachePeer.getName();
cacheStatus.append("url='").append(cachePeer.getUrl()).append("' ");
cacheStatus.append("keyssize='").append(cachePeer.getKeys().size()).append("' ");
peerInfoMap.put(peerName,cacheStatus.toString());
}
}
}
modelMap.put("managerMap", managerMap);
return VIEW_URL;
}
}
the jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>EHCache</title>
</head>
<body>
<h1>EHCache</h1>
<p><a href="/tools/ehcache/clear?name=all">Clear All</a></p>
<c:forEach items="${managerMap}" var="manager">
<h2>Manager: '${manager.key}'</h2>
<c:forEach var="cacheMap" items="${manager.value}">
<h3>Cache: '${cacheMap.key}'</h3>
<p><a href="/tools/ehcache/clear?cacheManagerName=${manager.key}&cacheName=${cacheMap.key}">clear</a></p>
<c:forEach var="peerInfoMap" items="${cacheMap.value}">
<li>peer name = ${peerInfoMap.key} peer status = ${peerInfoMap.value}</li>
</c:forEach>
</c:forEach>
</c:forEach>
</body>
</html>
Upvotes: 0
Reputation: 1133
There is an MBean you can use to monitor ehcache at runtime:
See http://ehcache.org/documentation/user-guide/jmx
Upvotes: 0