1 26 27 package org.objectweb.benchmark.rmi.latency; 28 29 import java.rmi.Naming ; 31 import java.rmi.RemoteException ; 32 33 import org.objectweb.benchmark.util.ResultPrinter; 34 35 42 public class Client 43 { 44 50 51 private int nb_step; 52 53 54 private int nb_step_invocation; 55 56 57 private int step_start; 58 59 60 private String result_file; 61 62 63 private String host; 64 65 66 private PingItf ping_impl = null; 67 68 74 79 public Client(String name) 80 { 81 result_file = name; 82 java.util.Properties properties = new java.util.Properties (); 83 84 try { 85 java.io.InputStream 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 e) { 95 e.printStackTrace(); 96 } 97 } 98 99 105 111 116 public static void main(String [] 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 131 public void run() 132 { 133 try{ 135 ping_impl = (PingItf) Naming.lookup("//"+host+"/pingServer"); 136 }catch(Exception ex){ 137 ex.printStackTrace(); 138 } 139 140 test(); 142 } 143 144 147 public void test() 148 { 149 try 151 { 152 for (int i=0; i<step_start; i++) 153 ping_impl.ping(); 154 } catch (RemoteException e) { 155 e.printStackTrace(); 156 } 157 158 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 ResultPrinter p = new ResultPrinter(result_file); 172 p.write(timer); 173 p.close(); 174 } 175 }catch(Exception ex){ 176 ex.printStackTrace(); 177 } 178 } 179 } | Popular Tags |