1 17 package org.apache.jmeter.monitor.util; 18 19 import java.util.List ; 20 import java.util.LinkedList ; 21 import org.apache.jmeter.monitor.model.*; 22 import org.apache.jmeter.visualizers.*; 23 27 public class MemoryBenchmark 28 { 29 30 public static void main(String [] args) 31 { 32 if (args.length != 1){ 33 int objects = 10000; 34 if (args[0] != null){ 35 objects = Integer.parseInt(args[0]); 36 } 37 List objs = new LinkedList (); 38 ObjectFactory of = ObjectFactory.getInstance(); 39 40 long bfree = Runtime.getRuntime().freeMemory(); 41 long btotal = Runtime.getRuntime().totalMemory(); 42 System.out.println("Before we create objects:"); 44 System.out.println("------------------------------"); 45 System.out.println("free: " + bfree); 46 System.out.println("total: " + btotal); 47 49 for (int idx=0; idx < objects; idx++){ 50 Connector cnn = of.createConnector(); 51 Workers wkrs = of.createWorkers(); 52 for (int idz=0; idz < 26; idz++){ 53 Worker wk0 = of.createWorker(); 54 wk0.setCurrentQueryString("/manager/status"); 55 wk0.setCurrentUri("http://localhost/manager/status"); 56 wk0.setMethod("GET"); 57 wk0.setProtocol("http"); 58 wk0.setRemoteAddr("?"); 59 wk0.setRequestBytesReceived(132); 60 wk0.setRequestBytesSent(18532); 61 wk0.setStage("K"); 62 wk0.setVirtualHost("?"); 63 wkrs.getWorker().add(wk0); 64 } 65 cnn.setWorkers(wkrs); 66 67 RequestInfo rqinfo = of.createRequestInfo(); 68 rqinfo.setBytesReceived(0); 69 rqinfo.setBytesSent(434374); 70 rqinfo.setErrorCount(10); 71 rqinfo.setMaxTime(850); 72 rqinfo.setProcessingTime(2634); 73 rqinfo.setRequestCount(1002); 74 cnn.setRequestInfo(rqinfo); 75 76 ThreadInfo thinfo = of.createThreadInfo(); 77 thinfo.setCurrentThreadCount(50); 78 thinfo.setCurrentThreadsBusy(12); 79 thinfo.setMaxSpareThreads(50); 80 thinfo.setMaxThreads(150); 81 thinfo.setMinSpareThreads(10); 82 cnn.setThreadInfo(thinfo); 83 84 Jvm vm = of.createJvm(); 85 Memory mem = of.createMemory(); 86 mem.setFree(77280); 87 mem.setTotal(134210000); 88 mem.setMax(134217728); 89 vm.setMemory(mem); 90 91 Status st = of.createStatus(); 92 st.setJvm(vm); 93 st.getConnector().add(cnn); 94 95 MonitorStats mstats = new MonitorStats( 96 Stats.calculateStatus(st), 97 Stats.calculateLoad(st), 98 0, 99 Stats.calculateMemoryLoad(st), 100 Stats.calculateThreadLoad(st), 101 "localhost", 102 "8080", 103 "http", 104 System.currentTimeMillis()); 105 MonitorModel monmodel = new MonitorModel(mstats); 106 objs.add(monmodel); 107 } 108 long afree = Runtime.getRuntime().freeMemory(); 109 long atotal = Runtime.getRuntime().totalMemory(); 110 long delta = ((atotal - afree) - (btotal - bfree)); 112 System.out.println("After we create objects:"); 113 System.out.println("------------------------------"); 114 System.out.println("free: " + afree); 115 System.out.println("total: " + atotal); 116 System.out.println("------------------------------"); 118 System.out.println("delta: "+ (delta/1024) + " kilobytes"); 119 System.out.println("delta: "+ (delta/1024/1024) + " megabytes"); 120 System.out.println("number of objects: " + objects); 121 System.out.println("potential number of servers: " + 122 (objects/1000)); 123 124 } else { 125 System.out.println("Please provide the number of objects"); 126 } 127 } 128 } 129 | Popular Tags |