How to query the Coherence cache for metrics?

Regarding Coherence cache metrics, how can I find the key size? The key size is a wrapped java object, for example a 32 character guid. When the POF wrapper is put on it, it ends up being 35 bytes. To be perfectly accurate you would have to query in cache and grab metrics around its key size. POF isn’t fixed, a different sized java string wouldn’t be calculable by adding 2 bytes safely. So, how can the Coherence cache be queried to review metrics around the key size being used?

Best Answer

  • There is no real easy way to query the Coherence cache to get key metrics. If you want totally accurate measurements for your keys, you would need to ask the cache for a list of all the keys, and then iterate thru that list and run them thru the POF serializer and examine the byte counts yourself. that being said, my experience has been for Strings, you can get close enough by just using the number of chars in the string + 2. that will get you close enough. if you happen to use large strings as keys, you could do +3 or +4. If you use data objects as your key, you obviously need to do something else(IE, explicitly call POF serializers). I usually don't worry about being right on due to the fact that when sizing there are multiple things to worry about. 1) need to determine size of keys 2) need to determine size of objects 3) need to determine if you need backups or not, if yes, your memory usage at least doubles. 4) need to add in straight coherence overhead/object in cache, this is about 220 bytes. 5) need to determine if you need indexes or not. if so, there is no way to get this number exactly, it is just a ball park number. In the next version of Coherence, they may resolve this, but they are not sure at this time. 6) usually we add 10-30% fudge factor also, in case of miscalculations or unforseen usage. thanks kevin

Answers

  • One additional thing, you may be able to get your key size answer via EntryProcessor's or cache.aggragate(). You could hit all objects in the cache and have coherence tally the results for you, but some legwork would need to be done to see if this it totally possible. kevin
  • Ok. I think you're saying that I need to manually code up a way to query Coherence... there is no tool that would do it for me. Thanks!