KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > benchmark > rmi > 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): Christophe Demarey.
23 Contributor(s): Gael Harbonnier.
24
25 ====================================================================*/

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

42 public class Client
43 {
44     // ==================================================================
45
//
46
// Internal states.
47
//
48
// ==================================================================
49

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

74     /**
75      * The default constructor.
76      *
77      * @param name - Results file name.
78      */

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

105     // ==================================================================
106
//
107
// Public methods.
108
//
109
// ==================================================================
110

111     /**
112      * The bootstrap method.
113      *
114      * @param args - Client arguments.
115      */

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

131     public void run()
132     {
133         // Obtains the Ping Itf reference
134
try{
135             ping_impl = (PingItf) Naming.lookup("//"+host+"/pingServer");
136         }catch(Exception JavaDoc ex){
137             ex.printStackTrace();
138         }
139         
140         // Runs benchmark
141
test();
142     }
143
144     /**
145      * Runs the latency benchmark.
146      */

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