001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jmeter.monitor.util;
018:
019: import java.util.List;
020: import java.util.LinkedList;
021: import org.apache.jmeter.monitor.model.*;
022: import org.apache.jmeter.visualizers.*;
023:
024: /**
025: *
026: * @version $Revision: 501270 $ $Date: 2007-01-30 01:16:29 +0000 (Tue, 30 Jan 2007) $
027: */
028: public class MemoryBenchmark {
029:
030: public static void main(String[] args) {
031: if (args.length != 1) {
032: int objects = 10000;
033: if (args[0] != null) {
034: objects = Integer.parseInt(args[0]);
035: }
036: List objs = new LinkedList();
037: ObjectFactory of = ObjectFactory.getInstance();
038:
039: long bfree = Runtime.getRuntime().freeMemory();
040: long btotal = Runtime.getRuntime().totalMemory();
041: long bmax = Runtime.getRuntime().maxMemory();
042: System.out.println("Before we create objects:");
043: System.out.println("------------------------------");
044: System.out.println("free: " + bfree);
045: System.out.println("total: " + btotal);
046: System.out.println("max: " + bmax);
047:
048: for (int idx = 0; idx < objects; idx++) {
049: Connector cnn = of.createConnector();
050: Workers wkrs = of.createWorkers();
051: for (int idz = 0; idz < 26; idz++) {
052: Worker wk0 = of.createWorker();
053: wk0.setCurrentQueryString("/manager/status");
054: wk0
055: .setCurrentUri("http://localhost/manager/status");
056: wk0.setMethod("GET");
057: wk0.setProtocol("http");
058: wk0.setRemoteAddr("?");
059: wk0.setRequestBytesReceived(132);
060: wk0.setRequestBytesSent(18532);
061: wk0.setStage("K");
062: wk0.setVirtualHost("?");
063: wkrs.getWorker().add(wk0);
064: }
065: cnn.setWorkers(wkrs);
066:
067: RequestInfo rqinfo = of.createRequestInfo();
068: rqinfo.setBytesReceived(0);
069: rqinfo.setBytesSent(434374);
070: rqinfo.setErrorCount(10);
071: rqinfo.setMaxTime(850);
072: rqinfo.setProcessingTime(2634);
073: rqinfo.setRequestCount(1002);
074: cnn.setRequestInfo(rqinfo);
075:
076: ThreadInfo thinfo = of.createThreadInfo();
077: thinfo.setCurrentThreadCount(50);
078: thinfo.setCurrentThreadsBusy(12);
079: thinfo.setMaxSpareThreads(50);
080: thinfo.setMaxThreads(150);
081: thinfo.setMinSpareThreads(10);
082: cnn.setThreadInfo(thinfo);
083:
084: Jvm vm = of.createJvm();
085: Memory mem = of.createMemory();
086: mem.setFree(77280);
087: mem.setTotal(134210000);
088: mem.setMax(134217728);
089: vm.setMemory(mem);
090:
091: Status st = of.createStatus();
092: st.setJvm(vm);
093: st.getConnector().add(cnn);
094:
095: MonitorStats mstats = new MonitorStats(Stats
096: .calculateStatus(st), Stats.calculateLoad(st),
097: 0, Stats.calculateMemoryLoad(st), Stats
098: .calculateThreadLoad(st), "localhost",
099: "8080", "http", System.currentTimeMillis());
100: MonitorModel monmodel = new MonitorModel(mstats);
101: objs.add(monmodel);
102: }
103: long afree = Runtime.getRuntime().freeMemory();
104: long atotal = Runtime.getRuntime().totalMemory();
105: long amax = Runtime.getRuntime().maxMemory();
106: long delta = ((atotal - afree) - (btotal - bfree));
107: System.out.println("After we create objects:");
108: System.out.println("------------------------------");
109: System.out.println("free: " + afree);
110: System.out.println("total: " + atotal);
111: System.out.println("max: " + amax);
112: System.out.println("------------------------------");
113: System.out.println("delta: " + (delta / 1024)
114: + " kilobytes");
115: System.out.println("delta: " + (delta / 1024 / 1024)
116: + " megabytes");
117: System.out.println("number of objects: " + objects);
118: System.out.println("potential number of servers: "
119: + (objects / 1000));
120:
121: } else {
122: System.out.println("Please provide the number of objects");
123: }
124: }
125: }
|