KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > benchmark > proactive > latency > Client


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Gael Harbonnier.
23 Contributor(s): _________________.
24
25 ====================================================================*/

26
27 package org.objectweb.benchmark.proactive.latency;
28
29 //Package dependencies.
30
import org.objectweb.benchmark.util.ResultPrinter;
31
32 /**
33  * This client tests Proactive latency by calling several times the ping method.
34  *
35  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
36  *
37  * @version 0.1
38  */

39 public class Client
40 {
41     // ==================================================================
42
//
43
// Internal states.
44
//
45
// ==================================================================
46

47     /** Number of steps*/
48     private int nb_step;
49
50     /** Number of invocations per step*/
51     private int nb_step_invocation;
52     
53     /** Beginning of the first step*/
54     private int step_start;
55     
56     /** Results file name */
57     private String JavaDoc result_file;
58
59     /** host */
60     private String JavaDoc host;
61     
62     /** Ping interface reference */
63     private PingItf ping = null;
64
65     // ==================================================================
66
//
67
// Constructors.
68
//
69
// ==================================================================
70

71     /**
72      * The default constructor.
73      *
74      * @param name - Results file name.
75      */

76     public Client(String JavaDoc name)
77     {
78         result_file = name;
79         java.util.Properties JavaDoc properties = new java.util.Properties JavaDoc();
80         java.io.InputStream JavaDoc propStream = null;
81
82         try {
83         
84             propStream = getClass().getClassLoader().getResourceAsStream("benchmark.properties");
85             properties.load(propStream);
86         
87             nb_step = Integer.parseInt( properties.getProperty("step.number") );
88             nb_step_invocation = Integer.parseInt( properties.getProperty("step.invocation.number") );
89             step_start = Integer.parseInt( properties.getProperty("step.start") );
90             host = properties.getProperty("com.host");
91         } catch (Exception JavaDoc e) {
92             e.printStackTrace();
93         }
94     }
95
96     // ==================================================================
97
//
98
// Internal methods.
99
//
100
// ==================================================================
101

102     // ==================================================================
103
//
104
// Public methods.
105
//
106
// ==================================================================
107

108     /**
109      * The bootstrap method.
110      *
111      * @param args - Client arguments.
112      */

113     public static void main(String JavaDoc[] args)
114     {
115         if (args.length != 1)
116         {
117             System.out.println("Usage: Client <dest_file>");
118             System.exit(0);
119         }
120
121         Client c = new Client(args[0]);
122         c.run();
123     }
124
125     /**
126      * Runs n invocations on the Rmi client.
127      */

128     public void run()
129     {
130         // Obtains the Ping Itf reference
131
try{
132             ping = (PingItf) org.objectweb.proactive.ProActive.lookupActive(Ping.class.getName(),"//"+host+"/hello");
133         }catch(Exception JavaDoc ex){
134             ex.printStackTrace();
135         }
136         
137         // Runs benchmark
138
test();
139         System.exit(0);
140     }
141
142     /**
143      * Runs the latency benchmark.
144      */

145     public void test()
146     {
147         // Don't include the first step_start invocations
148
try
149         {
150             for (int i=0; i<step_start; i++)
151                 ping.ping();
152         } catch (Exception JavaDoc e) {
153             e.printStackTrace();
154         }
155     
156         // Runs test
157
System.out.println("Running Rmi Benchmark with " + nb_step + " step(s) of " + nb_step_invocation +" method calls.");
158         try
159         {
160             for(int j=0; j<nb_step; j++)
161             {
162                 long timer = System.currentTimeMillis();
163                 
164                 for (int i=0; i<nb_step_invocation; i++)
165                     ping.ping();
166                 timer = (long) ( ( System.currentTimeMillis() - timer ) * 1000 / (float)nb_step_invocation );
167             
168                 // write results
169
ResultPrinter p = new ResultPrinter(result_file);
170                 p.write(timer);
171                 p.close();
172             }
173         }catch(Exception JavaDoc ex){
174             ex.printStackTrace();
175         }
176     }
177 }
178
Popular Tags