1 package org.opensrf.test;
3 import org.opensrf.util.*;
6 import java.util.ArrayList;
7 import java.io.PrintStream;
10 public class MathBench {
12 public static void main(String args[]) throws Exception {
14 PrintStream out = System.out;
17 out.println("usage: java org.opensrf.test.MathBench <osrfConfig> <numIterations>");
21 /** connect to the opensrf network */
22 Sys.bootstrapClient(args[0], "/config/opensrf");
24 /** how many iterations */
25 int count = Integer.parseInt(args[1]);
27 /** create the client session */
28 ClientSession session = new ClientSession("opensrf.math");
31 List<Object> params = new ArrayList<Object>();
32 params.add(new Integer(1));
33 params.add(new Integer(2));
40 for(int i = 0; i < count; i++) {
42 start = new Date().getTime();
44 /** create (and send) the request */
45 request = session.request("add", params);
47 /** wait up to 3 seconds for a response */
48 result = request.recv(3000);
50 /** collect the round-trip time */
51 total += new Date().getTime() - start;
53 if(result.getStatusCode() == Status.OK) {
56 out.println("\nrequest failed");
57 out.println("status = " + result.getStatus());
58 out.println("status code = " + result.getStatusCode());
61 /** remove this request from the session's request set */
64 if((i+1) % 100 == 0) /** print 100 responses per line */
65 out.println(" [" + (i+1) + "]");
68 out.println("\nAverage request time is " + (total/count) + " ms");
70 /** remove this session from the global session cache */
73 /** disconnect from the opensrf network */