Last active
January 5, 2017 12:24
-
-
Save chetanmeh/5748650 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This scripts provide details related to various caches used in Oak MongoMK module while running within Sling OSGi Container | |
The script is based on (JAMM) [1]. Steps are provided below | |
1. Download JAMM from Maven | |
$wget http://repo1.maven.org/maven2/com/github/stephenc/jamm/0.2.5/jamm-0.2.5.jar | |
2. Modify the Quickstart launching by specifying agent and bootdelegation list | |
$java -javaagent:<path to>/jamm.jar -Dorg.apache.sling.launcher.bootdelegation=,org.github.jamm -jar | |
3. Deploy the Script Console jar | |
$wget http://repo1.maven.org/maven2/org/apache/sling/org.apache.sling.scripting.console/1.0.0/org.apache.sling.scripting.console-1.0.0.jar | |
$wget http://repo1.maven.org/maven2/org/codehaus/groovy/groovy-all/2.1.3/groovy-all-2.1.3.jar | |
$curl -u admin:admin -F action=install -F bundlestartlevel=20 -F bundlefile=@"org.apache.sling.scripting.console-1.0.0.jar" http://localhost:4502/system/console/bundles | |
$curl -u admin:admin -F action=install -F bundlestartlevel=20 -F bundlefile=@"groovy-all-2.1.3.jar" http://localhost:4502/system/console/bundles | |
4. Access http://localhost:4502/system/console/scriptconsole and execute the script | |
[1] https://github.com/jbellis/jamm | |
[2] http://stackoverflow.com/a/3758880/1035417 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.github.jamm.* | |
//Globals | |
mk = sling.getService(org.apache.jackrabbit.mk.api.MicroKernel.class) | |
nodeStore = sling.getService(org.apache.jackrabbit.oak.spi.state.NodeStore.class) | |
meter = new org.github.jamm.MemoryMeter(); | |
println "Cache Info " | |
println "--------------" | |
displayStats("Node Cache",mk.nodeCache) | |
displayStats("Node Children Cache", mk.nodeChildrenCache) | |
displayStats("Document Cache", mk.store.nodesCache) | |
//displayStats("Kernal Node Store Cache", nodeStore.cache) | |
def displayStats(String name, def cache){ | |
println name | |
println " Size : Actual (Allocated) ${prettyfy(meter.measureDeep(cache))} (${prettyfy(cache.asMap().@maxWeight)})" | |
println " Stats : " + cache.stats() | |
println " No of entries : " + cache.size() | |
} | |
//Based on http://stackoverflow.com/a/3758880/1035417 | |
def String prettyfy(long bytes) { | |
boolean si = true | |
int unit = si ? 1000 : 1024; | |
if (bytes < unit) return bytes + " B"; | |
int exp = (int) (Math.log(bytes) / Math.log(unit)); | |
String pre = "" + (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i"); | |
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment