OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
com.mapd.bench.BenchmarkCloud Class Reference
+ Collaboration diagram for com.mapd.bench.BenchmarkCloud:

Static Public Member Functions

static void main (String[] args)
 

Package Functions

void doWork (String[] args, int query)
 
Connection getConnection (String url, String iUser, String iPasswd)
 
String executeQuery (Connection conn1, String qid, String sql, int iterations)
 

Package Attributes

Connection bencherCon
 

Static Package Attributes

static final Logger logger = LoggerFactory.getLogger(BenchmarkCloud.class)
 
static final String QUERY_RESULT_MACHINE = "bencher"
 
static final String DB_URL = "jdbc:heavyai:localhost:6274:mapd"
 
static final String JDBC_DRIVER = "ai.heavy.jdbc.HeavyAIDriver"
 
static final String USER = "admin"
 
static final String PASS = ""
 
static final String RESULTS_USER = "admin"
 
static final String RESULTS_PASS = ""
 

Private Member Functions

void getQueries (Map< String, String > queryIDMap, Connection benderCon, String tableName)
 
void runQueries (List< String > resultArray, Map< String, String > queryIDMap, int iterations)
 
void storeResults ()
 

Private Attributes

String driver
 
String url
 
String iUser
 
String queryResultMachine
 
String iPasswd
 
String iResultsUser
 
String iResultsPasswd
 
String rid
 
String rTimestamp
 
String tableName
 
String label
 
String gpuCount
 
String targetDBVersion
 
List< String > LResult = new ArrayList<String>()
 
String headDescriptor
 
String header2
 
String lineDescriptor
 
String insertDescriptor
 

Detailed Description

Definition at line 37 of file BenchmarkCloud.java.

Member Function Documentation

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

Definition at line 108 of file BenchmarkCloud.java.

References com.mapd.bench.BenchmarkCloud.bencherCon, com.mapd.bench.BenchmarkCloud.DB_URL, com.mapd.bench.BenchmarkCloud.driver, com.mapd.bench.BenchmarkCloud.getConnection(), com.mapd.bench.BenchmarkCloud.getQueries(), com.mapd.bench.BenchmarkCloud.gpuCount, com.mapd.bench.BenchmarkCloud.header2, com.mapd.bench.BenchmarkCloud.iPasswd, com.mapd.bench.BenchmarkCloud.iResultsPasswd, com.mapd.bench.BenchmarkCloud.iResultsUser, com.mapd.bench.BenchmarkCloud.iUser, com.mapd.bench.BenchmarkCloud.JDBC_DRIVER, com.mapd.bench.BenchmarkCloud.label, com.mapd.bench.BenchmarkCloud.PASS, com.mapd.bench.BenchmarkCloud.QUERY_RESULT_MACHINE, com.mapd.bench.BenchmarkCloud.queryResultMachine, com.mapd.bench.BenchmarkCloud.RESULTS_PASS, com.mapd.bench.BenchmarkCloud.RESULTS_USER, com.mapd.bench.BenchmarkCloud.rid, com.mapd.bench.BenchmarkCloud.rTimestamp, com.mapd.bench.BenchmarkCloud.runQueries(), com.mapd.bench.BenchmarkCloud.storeResults(), com.mapd.bench.BenchmarkCloud.tableName, com.mapd.bench.BenchmarkCloud.url, and com.mapd.bench.BenchmarkCloud.USER.

108  {
109  // Grab parameters from args
110  // parm0 number of iterations per query
111  // parm1 file containing sql queries {contains quoted query, expected result
112  // count]
113  // parm2 table name
114  // parm3 run label
115  // parm4 gpu count
116  // parm5 optional query and result machine
117  // parm6 optional DB URL
118  // parm7 optional JDBC Driver class name
119  // parm8 optional user
120  // parm9 optional passwd
121  // parm10 optional query results db user
122  // parm11 optional query results db passwd
123  int iterations = Integer.valueOf(args[0]);
124  logger.debug("Iterations per query is " + iterations);
125 
126  String queryFile = args[1];
127  tableName = args[2];
128  label = args[3];
129  gpuCount = args[4];
130 
131  // int expectedResults = Integer.valueOf(args[2]);
132  queryResultMachine = (args.length > 5) ? args[5] : QUERY_RESULT_MACHINE;
133  url = (args.length > 6) ? args[6] : DB_URL;
134  driver = (args.length > 7) ? args[7] : JDBC_DRIVER;
135 
136  iUser = (args.length > 8) ? args[8] : USER;
137  iPasswd = (args.length > 9) ? args[9] : PASS;
138 
139  iResultsUser = (args.length > 10) ? args[10] : RESULTS_USER;
140  iResultsPasswd = (args.length > 11) ? args[11] : RESULTS_PASS;
141 
142  // register the driver
143  try {
144  // Register JDBC driver
145  Class.forName(driver);
146  } catch (ClassNotFoundException ex) {
147  logger.error("Could not load class " + driver + " " + ex.getMessage());
148  System.exit(1);
149  }
150 
151  UUID uuid = UUID.randomUUID();
152  rid = uuid.toString();
153  java.util.Date date = new java.util.Date();
154  Timestamp t = new Timestamp(date.getTime());
155  rTimestamp = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(t);
156 
157  System.out.println("run id is " + rid + " date is " + rTimestamp);
158 
159  // read from query file and execute queries
160  String sCurrentLine;
161  List<String> resultArray = new ArrayList();
162  Map<String, String> queryIDMap = new LinkedHashMap();
163  BufferedReader br;
164  try {
165  br = new BufferedReader(new FileReader(queryFile));
166 
167  while ((sCurrentLine = br.readLine()) != null) {
168  queryIDMap.put(sCurrentLine, null);
169  }
170  br.close();
171 
172  } catch (FileNotFoundException ex) {
173  logger.error("Could not find file " + queryFile + " " + ex.getMessage());
174  System.exit(2);
175  } catch (IOException ex) {
176  logger.error("IO Exeception " + ex.getMessage());
177  System.exit(3);
178  }
179 
180  bencherCon = getConnection("jdbc:heavyai:" + queryResultMachine + ":6274:mapd",
181  iResultsUser,
183 
184  getQueries(queryIDMap, bencherCon, tableName);
185 
186  runQueries(resultArray, queryIDMap, iterations);
187 
188  // if all completed ok store the results
189  storeResults();
190 
191  // All done dump out results
192  System.out.println(header2);
193  for (String s : resultArray) {
194  System.out.println(s);
195  }
196  }
static final String RESULTS_PASS
static final String JDBC_DRIVER
Connection getConnection(String url, String iUser, String iPasswd)
static final String RESULTS_USER
void getQueries(Map< String, String > queryIDMap, Connection benderCon, String tableName)
static final String QUERY_RESULT_MACHINE
void runQueries(List< String > resultArray, Map< String, String > queryIDMap, int iterations)

+ Here is the call graph for this function:

String com.mapd.bench.BenchmarkCloud.executeQuery ( Connection  conn1,
String  qid,
String  sql,
int  iterations 
)
inlinepackage

Definition at line 216 of file BenchmarkCloud.java.

References report.conn, com.mapd.bench.BenchmarkCloud.driver, com.mapd.bench.BenchmarkCloud.getConnection(), com.mapd.bench.BenchmarkCloud.gpuCount, com.mapd.bench.BenchmarkCloud.insertDescriptor, com.mapd.bench.BenchmarkCloud.iPasswd, com.mapd.bench.BenchmarkCloud.iUser, com.mapd.bench.BenchmarkCloud.JDBC_DRIVER, com.mapd.bench.BenchmarkCloud.label, com.mapd.bench.BenchmarkCloud.lineDescriptor, com.mapd.bench.BenchmarkCloud.targetDBVersion, and com.mapd.bench.BenchmarkCloud.url.

Referenced by com.mapd.bench.BenchmarkCloud.runQueries().

216  {
217  Statement stmt = null;
218  Connection conn = getConnection(url, iUser, iPasswd);
219 
220  Long firstExecute = 0l;
221  Long firstJdbc = 0l;
222  Long firstIterate = 0l;
223 
224  DescriptiveStatistics statsExecute = new DescriptiveStatistics();
225  DescriptiveStatistics statsJdbc = new DescriptiveStatistics();
226  DescriptiveStatistics statsIterate = new DescriptiveStatistics();
227  DescriptiveStatistics statsTotal = new DescriptiveStatistics();
228 
229  long totalTime = 0;
230  int resultCount = 0;
231  try {
232  long startTime = System.currentTimeMillis();
233  for (int loop = 0; loop < iterations; loop++) {
234  // Execute a query
235  stmt = conn.createStatement();
236 
237  long timer = System.currentTimeMillis();
238  if (loop == 0) {
239  System.out.println(String.format("Query Id is %s : query is '%s'", qid, sql));
240  }
241  ResultSet rs = stmt.executeQuery(sql);
242 
243  long executeTime = 0;
244  long jdbcTime = 0;
245 
246  // gather internal execute time for HeavyAI as we are interested in that
247  if (driver.equals(JDBC_DRIVER)) {
248  executeTime = ((HeavyAIStatement) stmt).getQueryInternalExecuteTime();
249  jdbcTime = (System.currentTimeMillis() - timer) - executeTime;
250  } else {
251  jdbcTime = (System.currentTimeMillis() - timer);
252  executeTime = 0;
253  }
254  // this is fake to get our intenal execute time.
255  logger.debug("Query Timeout/AKA internal Execution Time was "
256  + stmt.getQueryTimeout() + " ms Elapsed time in JVM space was "
257  + (System.currentTimeMillis() - timer) + "ms");
258 
259  timer = System.currentTimeMillis();
260  // Extract data from result set
261  resultCount = 0;
262  while (rs.next()) {
263  Object obj = rs.getObject(1);
264  if (obj != null && obj.equals(statsExecute)) {
265  logger.info("Impossible");
266  }
267  resultCount++;
268  }
269  long iterateTime = (System.currentTimeMillis() - timer);
270 
271  // if (resultCount != expected) {
272  // logger.error("Expect " + expected + " actual " + resultCount + " for
273  // query " + sql);
274  // // don't run anymore
275  // break;
276  // }
277  if (loop == 0) {
278  firstJdbc = jdbcTime;
279  firstExecute = executeTime;
280  firstIterate = iterateTime;
281 
282  } else {
283  statsJdbc.addValue(jdbcTime);
284  statsExecute.addValue(executeTime);
285  statsIterate.addValue(iterateTime);
286  statsTotal.addValue(jdbcTime + executeTime + iterateTime);
287  }
288 
289  // Clean-up environment
290  rs.close();
291  stmt.close();
292  }
293  totalTime = System.currentTimeMillis() - startTime;
294  conn.close();
295  } catch (SQLException se) {
296  // Handle errors for JDBC
297  se.printStackTrace();
298  System.exit(4);
299  } catch (Exception e) {
300  // Handle errors for Class.forName
301  e.printStackTrace();
302  System.exit(3);
303  } finally {
304  // finally block used to close resources
305  try {
306  if (stmt != null) {
307  stmt.close();
308  }
309  } catch (SQLException se2) {
310  } // nothing we can do
311  try {
312  if (conn != null) {
313  conn.close();
314  }
315  } catch (SQLException se) {
316  se.printStackTrace();
317  System.exit(6);
318  } // end finally try
319  } // end try
320 
321  // write it to the db here as well
322  String insertPart = String.format(insertDescriptor,
323  this.rid,
324  this.rTimestamp,
325  url,
326  this.driver,
327  label,
328  gpuCount,
329  this.tableName,
330  qid,
331  resultCount,
332  "",
333  statsTotal.getMean(),
334  statsTotal.getMin(),
335  statsTotal.getMax(),
336  statsTotal.getPercentile(85),
337  statsExecute.getMean(),
338  statsExecute.getMin(),
339  statsExecute.getMax(),
340  statsExecute.getPercentile(85),
341  statsExecute.getPercentile(25),
342  statsExecute.getStandardDeviation(),
343  statsJdbc.getMean(),
344  statsJdbc.getMin(),
345  statsJdbc.getMax(),
346  statsJdbc.getPercentile(85),
347  statsIterate.getMean(),
348  statsIterate.getMin(),
349  statsIterate.getMax(),
350  statsIterate.getPercentile(85),
351  firstExecute,
352  firstJdbc,
353  firstIterate,
354  iterations,
355  totalTime,
356  (long) statsTotal.getSum() + firstExecute + firstJdbc + firstIterate,
358 
359  LResult.add("Insert into results values " + insertPart);
360 
361  return String.format(lineDescriptor,
362  qid,
363  statsTotal.getMean(),
364  statsTotal.getMin(),
365  statsTotal.getMax(),
366  statsTotal.getPercentile(85),
367  statsExecute.getMean(),
368  statsExecute.getMin(),
369  statsExecute.getMax(),
370  statsExecute.getPercentile(85),
371  statsExecute.getPercentile(25),
372  statsExecute.getStandardDeviation(),
373  statsJdbc.getMean(),
374  statsJdbc.getMin(),
375  statsJdbc.getMax(),
376  statsJdbc.getPercentile(85),
377  statsIterate.getMean(),
378  statsIterate.getMin(),
379  statsIterate.getMax(),
380  statsIterate.getPercentile(85),
381  firstExecute,
382  firstJdbc,
383  firstIterate,
384  iterations,
385  totalTime,
386  (long) statsTotal.getSum() + firstExecute + firstJdbc + firstIterate);
387  }
static final String JDBC_DRIVER
Connection getConnection(String url, String iUser, String iPasswd)
tuple conn
Definition: report.py:41

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Connection com.mapd.bench.BenchmarkCloud.getConnection ( String  url,
String  iUser,
String  iPasswd 
)
inlinepackage

Definition at line 198 of file BenchmarkCloud.java.

References report.conn, com.mapd.bench.BenchmarkCloud.iPasswd, com.mapd.bench.BenchmarkCloud.iUser, com.mapd.bench.BenchmarkCloud.targetDBVersion, and com.mapd.bench.BenchmarkCloud.url.

Referenced by com.mapd.bench.BenchmarkCloud.doWork(), com.mapd.bench.BenchmarkCloud.executeQuery(), and com.mapd.bench.BenchmarkCloud.runQueries().

198  {
199  // Open a connection
200  logger.debug("Connecting to database url :" + url);
201  try {
202  Connection conn = DriverManager.getConnection(url, iUser, iPasswd);
203 
204  targetDBVersion = conn.getMetaData().getDatabaseProductVersion();
205  logger.debug("Target DB version is " + targetDBVersion);
206 
207  return conn;
208  } catch (SQLException ex) {
209  logger.error(
210  "Exception making connection to " + url + " text is " + ex.getMessage());
211  System.exit(2);
212  }
213  return null;
214  }
tuple conn
Definition: report.py:41

+ Here is the caller graph for this function:

void com.mapd.bench.BenchmarkCloud.getQueries ( Map< String, String >  queryIDMap,
Connection  benderCon,
String  tableName 
)
inlineprivate

Definition at line 389 of file BenchmarkCloud.java.

References com.mapd.bench.BenchmarkCloud.tableName.

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

390  {
391  for (Map.Entry<String, String> entry : queryIDMap.entrySet()) {
392  String key = entry.getKey();
393  String value = entry.getValue();
394 
395  Statement stmt = null;
396  try {
397  stmt = benderCon.createStatement();
398  } catch (SQLException ex) {
399  logger.error("Exception creating statement text is " + ex.getMessage());
400  System.exit(2);
401  }
402  String sql =
403  String.format("Select query_text from queries where query_id = '%s'", key);
404  ResultSet rs = null;
405  try {
406  rs = stmt.executeQuery(sql);
407  } catch (SQLException ex) {
408  logger.error("Exception running query " + sql + " text is " + ex.getMessage());
409  System.exit(2);
410  }
411  int resultCount = 0;
412  try {
413  while (rs.next()) {
414  String qString = rs.getString(1);
415  qString = qString.replaceAll("##TAB##", tableName);
416  // System.out.println(String.format("Query Id is %s : query is '%s'", key,
417  // qString));
418  queryIDMap.put(key, qString);
419  resultCount++;
420  }
421  } catch (SQLException ex) {
422  logger.error("Exception making next call text is " + ex.getMessage());
423  System.exit(2);
424  }
425  if (resultCount > 1) {
426  System.out.println("multiple values for queryId " + key);
427  }
428  }
429  }

+ Here is the caller graph for this function:

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

Definition at line 103 of file BenchmarkCloud.java.

References run_benchmark_import.args.

103  {
104  BenchmarkCloud bm = new BenchmarkCloud();
105  bm.doWork(args, 1);
106  }
void com.mapd.bench.BenchmarkCloud.runQueries ( List< String >  resultArray,
Map< String, String >  queryIDMap,
int  iterations 
)
inlineprivate

Definition at line 431 of file BenchmarkCloud.java.

References report.conn, com.mapd.bench.BenchmarkCloud.executeQuery(), com.mapd.bench.BenchmarkCloud.getConnection(), com.mapd.bench.BenchmarkCloud.iPasswd, com.mapd.bench.BenchmarkCloud.iUser, and com.mapd.bench.BenchmarkCloud.url.

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

432  {
433  Connection conn = getConnection(url, iUser, iPasswd);
434  for (Map.Entry<String, String> entry : queryIDMap.entrySet()) {
435  String id = entry.getKey();
436  String query = entry.getValue();
437 
438  resultArray.add(executeQuery(conn, id, query, iterations));
439  }
440  }
String executeQuery(Connection conn1, String qid, String sql, int iterations)
Connection getConnection(String url, String iUser, String iPasswd)
tuple conn
Definition: report.py:41

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void com.mapd.bench.BenchmarkCloud.storeResults ( )
inlineprivate

Definition at line 442 of file BenchmarkCloud.java.

References com.mapd.bench.BenchmarkCloud.LResult.

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

442  {
443  for (String insertPart : LResult) {
444  Statement sin;
445  try {
446  sin = bencherCon.createStatement();
447  sin.execute(insertPart);
448  } catch (SQLException ex) {
449  logger.error("Exception performing insert '" + insertPart + "' text is "
450  + ex.getMessage());
451  System.exit(2);
452  }
453  }
454  }

+ Here is the caller graph for this function:

Member Data Documentation

Connection com.mapd.bench.BenchmarkCloud.bencherCon
package

Definition at line 67 of file BenchmarkCloud.java.

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

final String com.mapd.bench.BenchmarkCloud.DB_URL = "jdbc:heavyai:localhost:6274:mapd"
staticpackage

Definition at line 43 of file BenchmarkCloud.java.

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

String com.mapd.bench.BenchmarkCloud.driver
private
String com.mapd.bench.BenchmarkCloud.gpuCount
private
String com.mapd.bench.BenchmarkCloud.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 70 of file BenchmarkCloud.java.

String com.mapd.bench.BenchmarkCloud.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 72 of file BenchmarkCloud.java.

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

String com.mapd.bench.BenchmarkCloud.insertDescriptor
private
Initial value:
=
"('%s','%s','%s','%s','%s',%s,'%s','%s',%d,'%s', %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, '%s')"

Definition at line 100 of file BenchmarkCloud.java.

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

String com.mapd.bench.BenchmarkCloud.iResultsPasswd
private

Definition at line 60 of file BenchmarkCloud.java.

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

String com.mapd.bench.BenchmarkCloud.iResultsUser
private

Definition at line 59 of file BenchmarkCloud.java.

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

final String com.mapd.bench.BenchmarkCloud.JDBC_DRIVER = "ai.heavy.jdbc.HeavyAIDriver"
staticpackage
String com.mapd.bench.BenchmarkCloud.lineDescriptor
private
Initial value:
=
"%3s, %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 98 of file BenchmarkCloud.java.

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

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

Definition at line 38 of file BenchmarkCloud.java.

List<String> com.mapd.bench.BenchmarkCloud.LResult = new ArrayList<String>()
private

Definition at line 68 of file BenchmarkCloud.java.

Referenced by com.mapd.bench.BenchmarkCloud.storeResults().

final String com.mapd.bench.BenchmarkCloud.PASS = ""
staticpackage

Definition at line 48 of file BenchmarkCloud.java.

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

final String com.mapd.bench.BenchmarkCloud.QUERY_RESULT_MACHINE = "bencher"
staticpackage

Definition at line 40 of file BenchmarkCloud.java.

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

String com.mapd.bench.BenchmarkCloud.queryResultMachine
private

Definition at line 57 of file BenchmarkCloud.java.

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

final String com.mapd.bench.BenchmarkCloud.RESULTS_PASS = ""
staticpackage

Definition at line 52 of file BenchmarkCloud.java.

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

final String com.mapd.bench.BenchmarkCloud.RESULTS_USER = "admin"
staticpackage

Definition at line 51 of file BenchmarkCloud.java.

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

String com.mapd.bench.BenchmarkCloud.rid
private

Definition at line 61 of file BenchmarkCloud.java.

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

String com.mapd.bench.BenchmarkCloud.rTimestamp
private

Definition at line 62 of file BenchmarkCloud.java.

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

String com.mapd.bench.BenchmarkCloud.tableName
private
String com.mapd.bench.BenchmarkCloud.targetDBVersion
private
final String com.mapd.bench.BenchmarkCloud.USER = "admin"
staticpackage

Definition at line 47 of file BenchmarkCloud.java.

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


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