OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
com.mapd.bench.Benchmark Class Reference
+ Collaboration diagram for com.mapd.bench.Benchmark:

Static Public Member Functions

static void main (String[] args)
 

Package Functions

void doWork (String[] args, int query)
 
String executeQuery (String sql, int expected, int iterations, int queryNum)
 

Static Package Attributes

static final Logger logger = LoggerFactory.getLogger(Benchmark.class)
 
static final String JDBC_DRIVER = "com.omnisci.jdbc.OmniSciDriver"
 
static final String DB_URL = "jdbc:omnisci:localhost:6274:mapd"
 
static final String USER = "admin"
 
static final String PASS = "HyperInteractive"
 

Private Attributes

String driver
 
String url
 
String iUser
 
String iPasswd
 
String headDescriptor
 
String header2
 
String lineDescriptor
 

Detailed Description

Definition at line 34 of file Benchmark.java.

Member Function Documentation

void com.mapd.bench.Benchmark.doWork ( String[]  args,
int  query 
)
inlinepackage

Definition at line 86 of file Benchmark.java.

References com.mapd.bench.Benchmark.DB_URL, com.mapd.bench.Benchmark.driver, com.mapd.bench.Benchmark.executeQuery(), com.mapd.bench.Benchmark.header2, com.mapd.bench.Benchmark.iPasswd, com.mapd.bench.Benchmark.iUser, com.mapd.bench.Benchmark.JDBC_DRIVER, com.mapd.bench.Benchmark.PASS, Experimental.String, com.mapd.bench.Benchmark.url, and com.mapd.bench.Benchmark.USER.

86  {
87  // Grab parameters from args
88  // parm0 number of iterations per query
89  // parm1 file containing sql queries {contains quoted query, expected result
90  // count]
91  // parm2 optional JDBC Driver class name
92  // parm3 optional DB URL
93  // parm4 optionsl user
94  // parm5 optional passwd
95  int iterations = Integer.valueOf(args[0]);
96  logger.debug("Iterations per query is " + iterations);
97 
98  String queryFile = args[1];
99 
100  // int expectedResults = Integer.valueOf(args[2]);
101  driver = (args.length > 2) ? args[2] : JDBC_DRIVER;
102  url = (args.length > 3) ? args[3] : DB_URL;
103  iUser = (args.length > 4) ? args[4] : USER;
104  iPasswd = (args.length > 5) ? args[5] : PASS;
105 
106  // register the driver
107  try {
108  // Register JDBC driver
109  Class.forName(driver);
110  } catch (ClassNotFoundException ex) {
111  logger.error("Could not load class " + driver + " " + ex.getMessage());
112  System.exit(1);
113  }
114 
115  // read from query file and execute queries
116  String sCurrentLine;
117  List<String> resultArray = new ArrayList();
118  BufferedReader br;
119  try {
120  br = new BufferedReader(new FileReader(queryFile));
121  int qCount = 1;
122 
123  while ((sCurrentLine = br.readLine()) != null) {
124  int expected = 0;
125  String sqlQuery = null;
126  // find the last comma and then grab the rest as sql
127  for (int i = sCurrentLine.length(); i > 0; i--) {
128  if (sCurrentLine.charAt(i - 1) == ',') {
129  // found the comma
130  expected = Integer.valueOf(sCurrentLine.substring(i).trim());
131  sqlQuery = sCurrentLine.substring(0, i - 1).trim().substring(1);
132  break;
133  }
134  }
135  // remove final "
136  sqlQuery = sqlQuery.substring(0, sqlQuery.length() - 1);
137 
138  System.out.println(String.format("Q%02d %s", qCount, sqlQuery));
139 
140  resultArray.add(executeQuery(sqlQuery, expected, iterations, qCount));
141 
142  qCount++;
143  }
144  } catch (FileNotFoundException ex) {
145  logger.error("Could not find file " + queryFile + " " + ex.getMessage());
146  System.exit(2);
147  } catch (IOException ex) {
148  logger.error("IO Exeception " + ex.getMessage());
149  System.exit(3);
150  }
151 
152  // All done dump out results
153  System.out.println(header2);
154  for (String s : resultArray) {
155  System.out.println(s);
156  }
157  }
static final String PASS
Definition: Benchmark.java:43
static final String USER
Definition: Benchmark.java:42
static final String DB_URL
Definition: Benchmark.java:39
static final String JDBC_DRIVER
Definition: Benchmark.java:38
String executeQuery(String sql, int expected, int iterations, int queryNum)
Definition: Benchmark.java:159

+ Here is the call graph for this function:

String com.mapd.bench.Benchmark.executeQuery ( String  sql,
int  expected,
int  iterations,
int  queryNum 
)
inlinepackage

Definition at line 159 of file Benchmark.java.

References com.mapd.bench.Benchmark.driver, com.mapd.bench.Benchmark.iPasswd, com.mapd.bench.Benchmark.iUser, com.mapd.bench.Benchmark.JDBC_DRIVER, com.mapd.bench.Benchmark.lineDescriptor, and com.mapd.bench.Benchmark.url.

Referenced by com.mapd.bench.Benchmark.doWork().

159  {
160  Connection conn = null;
161  Statement stmt = null;
162 
163  Long firstExecute = 0l;
164  Long firstJdbc = 0l;
165  Long firstIterate = 0l;
166 
167  DescriptiveStatistics statsExecute = new DescriptiveStatistics();
168  DescriptiveStatistics statsJdbc = new DescriptiveStatistics();
169  DescriptiveStatistics statsIterate = new DescriptiveStatistics();
170  DescriptiveStatistics statsTotal = new DescriptiveStatistics();
171 
172  long totalTime = 0;
173 
174  try {
175  // Open a connection
176  logger.debug("Connecting to database url :" + url);
177  conn = DriverManager.getConnection(url, iUser, iPasswd);
178 
179  long startTime = System.currentTimeMillis();
180  for (int loop = 0; loop < iterations; loop++) {
181  // Execute a query
182  stmt = conn.createStatement();
183 
184  long timer = System.currentTimeMillis();
185  ResultSet rs = stmt.executeQuery(sql);
186 
187  long executeTime = 0;
188  long jdbcTime = 0;
189 
190  // gather internal execute time for OmniSci as we are interested in that
191  if (driver.equals(JDBC_DRIVER)) {
192  executeTime = ((OmniSciStatement) stmt).getQueryInternalExecuteTime();
193  jdbcTime = (System.currentTimeMillis() - timer) - executeTime;
194  } else {
195  jdbcTime = (System.currentTimeMillis() - timer);
196  executeTime = 0;
197  }
198  // this is fake to get our intenal execute time.
199  logger.debug("Query Timeout/AKA internal Execution Time was "
200  + stmt.getQueryTimeout() + " ms Elapsed time in JVM space was "
201  + (System.currentTimeMillis() - timer) + "ms");
202 
203  timer = System.currentTimeMillis();
204  // Extract data from result set
205  int resultCount = 0;
206  while (rs.next()) {
207  Object obj = rs.getObject(1);
208  if (obj != null && obj.equals(statsExecute)) {
209  logger.info("Impossible");
210  }
211  resultCount++;
212  }
213  long iterateTime = (System.currentTimeMillis() - timer);
214 
215  if (resultCount != expected) {
216  logger.error(
217  "Expect " + expected + " actual " + resultCount + " for query " + sql);
218  // don't run anymore
219  break;
220  }
221 
222  if (loop == 0) {
223  firstJdbc = jdbcTime;
224  firstExecute = executeTime;
225  firstIterate = iterateTime;
226 
227  } else {
228  statsJdbc.addValue(jdbcTime);
229  statsExecute.addValue(executeTime);
230  statsIterate.addValue(iterateTime);
231  statsTotal.addValue(jdbcTime + executeTime + iterateTime);
232  }
233 
234  // Clean-up environment
235  rs.close();
236  stmt.close();
237  }
238  totalTime = System.currentTimeMillis() - startTime;
239  conn.close();
240  } catch (SQLException se) {
241  // Handle errors for JDBC
242  se.printStackTrace();
243  } catch (Exception e) {
244  // Handle errors for Class.forName
245  e.printStackTrace();
246  } finally {
247  // finally block used to close resources
248  try {
249  if (stmt != null) {
250  stmt.close();
251  }
252  } catch (SQLException se2) {
253  } // nothing we can do
254  try {
255  if (conn != null) {
256  conn.close();
257  }
258  } catch (SQLException se) {
259  se.printStackTrace();
260  } // end finally try
261  } // end try
262 
263  return String.format(lineDescriptor,
264  queryNum,
265  statsTotal.getMean(),
266  statsTotal.getMin(),
267  statsTotal.getMax(),
268  statsTotal.getPercentile(85),
269  statsExecute.getMean(),
270  statsExecute.getMin(),
271  statsExecute.getMax(),
272  statsExecute.getPercentile(85),
273  statsExecute.getPercentile(25),
274  statsExecute.getStandardDeviation(),
275  statsJdbc.getMean(),
276  statsJdbc.getMin(),
277  statsJdbc.getMax(),
278  statsJdbc.getPercentile(85),
279  statsIterate.getMean(),
280  statsIterate.getMin(),
281  statsIterate.getMax(),
282  statsIterate.getPercentile(85),
283  firstExecute,
284  firstJdbc,
285  firstIterate,
286  iterations,
287  totalTime,
288  (long) statsTotal.getSum() + firstExecute + firstJdbc + firstIterate);
289  }
static final String JDBC_DRIVER
Definition: Benchmark.java:38

+ Here is the caller graph for this function:

static void com.mapd.bench.Benchmark.main ( String[]  args)
inlinestatic

Definition at line 81 of file Benchmark.java.

References run_benchmark_import.args.

81  {
82  Benchmark bm = new Benchmark();
83  bm.doWork(args, 1);
84  }

Member Data Documentation

final String com.mapd.bench.Benchmark.DB_URL = "jdbc:omnisci:localhost:6274:mapd"
staticpackage

Definition at line 39 of file Benchmark.java.

Referenced by com.mapd.bench.Benchmark.doWork().

String com.mapd.bench.Benchmark.driver
private
String com.mapd.bench.Benchmark.headDescriptor
private
Initial value:
=
"%3s, %8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s"

Definition at line 50 of file Benchmark.java.

String com.mapd.bench.Benchmark.header2
private
Initial value:
= String.format(headDescriptor,
"QRY",
"T-Avg",
"T-Min",
"T-Max",
"T-85%",
"E-Avg",
"E-Min",
"E-Max",
"E-85%",
"E-25%",
"E-StdD",
"J-Avg",
"J-Min",
"J-Max",
"J-85%",
"I-Avg",
"I-Min",
"I-Max",
"I-85%",
"F-Exec",
"F-jdbc",
"F-iter",
"ITER",
"Total",
"Account")

Definition at line 52 of file Benchmark.java.

Referenced by com.mapd.bench.Benchmark.doWork().

String com.mapd.bench.Benchmark.iPasswd
private
String com.mapd.bench.Benchmark.iUser
private
final String com.mapd.bench.Benchmark.JDBC_DRIVER = "com.omnisci.jdbc.OmniSciDriver"
staticpackage
String com.mapd.bench.Benchmark.lineDescriptor
private
Initial value:
=
"Q%02d, %8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8.1f,%8d,%8d,%8d,%8d,%8d,%8d"

Definition at line 78 of file Benchmark.java.

Referenced by com.mapd.bench.Benchmark.executeQuery().

final Logger com.mapd.bench.Benchmark.logger = LoggerFactory.getLogger(Benchmark.class)
staticpackage

Definition at line 35 of file Benchmark.java.

final String com.mapd.bench.Benchmark.PASS = "HyperInteractive"
staticpackage

Definition at line 43 of file Benchmark.java.

Referenced by com.mapd.bench.Benchmark.doWork().

String com.mapd.bench.Benchmark.url
private
final String com.mapd.bench.Benchmark.USER = "admin"
staticpackage

Definition at line 42 of file Benchmark.java.

Referenced by com.mapd.bench.Benchmark.doWork().


The documentation for this class was generated from the following file: