1 4 package com.tctest; 5 6 import com.tc.object.config.ConfigVisitor; 7 import com.tc.object.config.DSOClientConfigHelper; 8 import com.tc.object.config.TransparencyClassSpec; 9 import com.tc.simulator.app.ApplicationConfig; 10 import com.tc.simulator.listener.ListenerProvider; 11 import com.tctest.runner.AbstractTransparentApp; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 import java.util.Random ; 16 17 public class CacheLoadPerformanceTestApp extends AbstractTransparentApp { 18 private Map cache = new HashMap (); 19 private final static int CACHE_COUNT = 8; 20 private final static int ENTRIES = 500; 21 private final static int BATCH_SIZE = 100; 22 23 public CacheLoadPerformanceTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 24 super(appId, cfg, listenerProvider); 25 } 26 27 public void run() { 28 Random r = new Random (); 29 synchronized (cache) { 30 for (int i = 0; i < CACHE_COUNT; i++) { 31 cache.put(new Integer (i), new HashMap ()); 32 } 33 } 34 long start = System.currentTimeMillis(); 35 int added = 0; 36 while (added < ENTRIES) { 37 synchronized (cache) { 38 for (int i = 0; i < BATCH_SIZE; i++) { 39 Integer cid = new Integer (r.nextInt(CACHE_COUNT)); 40 Map m = (Map ) cache.get(cid); 41 m.put(new TestKey(), new TestValue()); 42 added++; 43 } 44 } 45 } 46 System.out.println("Total time:" + (System.currentTimeMillis() - start)); 47 } 48 49 private class TestKey { 50 public Object o = new Object (); 51 public String s = "Steve " + System.currentTimeMillis(); 52 } 53 54 private class TestValue { 55 public Object o = new Object (); 56 public String s = "Steve " + System.currentTimeMillis(); 57 } 58 59 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 60 String testClass = CacheLoadPerformanceTestApp.class.getName(); 61 String methodExpression = "* " + testClass + ".*(..)"; 62 config.addWriteAutolock(methodExpression); 63 TransparencyClassSpec spec = config.getOrCreateSpec(testClass); 64 spec.addRoot("cache", "cache"); 65 config.addIncludePattern(TestKey.class.getName()); 66 config.addIncludePattern(TestValue.class.getName()); 67 } 68 69 } 70
| Popular Tags
|