KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > monitor > util > MemoryBenchmark


1 // $Header: /home/cvs/jakarta-jmeter/src/monitor/components/org/apache/jmeter/monitor/util/MemoryBenchmark.java,v 1.2 2004/03/19 23:29:25 sebb Exp $
2
/*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.jmeter.monitor.util;
18
19 import java.util.List JavaDoc;
20 import java.util.LinkedList JavaDoc;
21 import org.apache.jmeter.monitor.model.*;
22 import org.apache.jmeter.visualizers.*;
23 /**
24  *
25  * @version $Revision: 1.2 $ $Date: 2004/03/19 23:29:25 $
26  */

27 public class MemoryBenchmark
28 {
29
30     public static void main(String JavaDoc[] 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 JavaDoc objs = new LinkedList JavaDoc();
38             ObjectFactory of = ObjectFactory.getInstance();
39             
40             long bfree = Runtime.getRuntime().freeMemory();
41             long btotal = Runtime.getRuntime().totalMemory();
42             //long bmax = Runtime.getRuntime().maxMemory();//JDK1.4 only
43
System.out.println("Before we create objects:");
44             System.out.println("------------------------------");
45             System.out.println("free: " + bfree);
46             System.out.println("total: " + btotal);
47             //System.out.println("max: " + bmax);
48

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 amax = Runtime.getRuntime().maxMemory();//JDK1.4 only
111
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("max: " + amax);
117
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