16 package com.mapd.bench;
19 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 import java.io.BufferedReader;
24 import java.io.FileNotFoundException;
25 import java.io.FileReader;
26 import java.io.IOException;
28 import java.text.SimpleDateFormat;
29 import java.util.ArrayList;
30 import java.util.LinkedHashMap;
31 import java.util.List;
33 import java.util.UUID;
38 final static Logger
logger = LoggerFactory.getLogger(BenchmarkCloud.class);
43 static final String
DB_URL =
"jdbc:heavyai:localhost:6274:mapd";
44 static final String
JDBC_DRIVER =
"ai.heavy.jdbc.HeavyAIDriver";
47 static final String
USER =
"admin";
48 static final String
PASS =
"";
68 private List<String>
LResult =
new ArrayList<String>();
71 "%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";
99 "%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";
101 "('%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')";
123 int iterations = Integer.valueOf(args[0]);
124 logger.debug(
"Iterations per query is " + iterations);
126 String queryFile = args[1];
133 url = (args.length > 6) ? args[6] :
DB_URL;
136 iUser = (args.length > 8) ? args[8] :
USER;
146 }
catch (ClassNotFoundException ex) {
147 logger.error(
"Could not load class " +
driver +
" " + ex.getMessage());
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);
157 System.out.println(
"run id is " + rid +
" date is " +
rTimestamp);
161 List<String> resultArray =
new ArrayList();
162 Map<String, String> queryIDMap =
new LinkedHashMap();
165 br =
new BufferedReader(
new FileReader(queryFile));
167 while ((sCurrentLine = br.readLine()) != null) {
168 queryIDMap.put(sCurrentLine, null);
172 }
catch (FileNotFoundException ex) {
173 logger.error(
"Could not find file " + queryFile +
" " + ex.getMessage());
175 }
catch (IOException ex) {
176 logger.error(
"IO Exeception " + ex.getMessage());
186 runQueries(resultArray, queryIDMap, iterations);
193 for (String s : resultArray) {
194 System.out.println(s);
200 logger.debug(
"Connecting to database url :" +
url);
208 }
catch (SQLException ex) {
210 "Exception making connection to " + url +
" text is " + ex.getMessage());
216 String
executeQuery(Connection conn1, String qid, String sql,
int iterations) {
217 Statement stmt = null;
220 Long firstExecute = 0l;
222 Long firstIterate = 0l;
224 DescriptiveStatistics statsExecute =
new DescriptiveStatistics();
225 DescriptiveStatistics statsJdbc =
new DescriptiveStatistics();
226 DescriptiveStatistics statsIterate =
new DescriptiveStatistics();
227 DescriptiveStatistics statsTotal =
new DescriptiveStatistics();
232 long startTime = System.currentTimeMillis();
233 for (
int loop = 0; loop < iterations; loop++) {
235 stmt = conn.createStatement();
237 long timer = System.currentTimeMillis();
239 System.out.println(String.format(
"Query Id is %s : query is '%s'", qid, sql));
241 ResultSet rs = stmt.executeQuery(sql);
243 long executeTime = 0;
249 jdbcTime = (System.currentTimeMillis() - timer) - executeTime;
251 jdbcTime = (System.currentTimeMillis() - timer);
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");
259 timer = System.currentTimeMillis();
263 Object obj = rs.getObject(1);
264 if (obj != null && obj.equals(statsExecute)) {
265 logger.info(
"Impossible");
269 long iterateTime = (System.currentTimeMillis() - timer);
278 firstJdbc = jdbcTime;
279 firstExecute = executeTime;
280 firstIterate = iterateTime;
283 statsJdbc.addValue(jdbcTime);
284 statsExecute.addValue(executeTime);
285 statsIterate.addValue(iterateTime);
286 statsTotal.addValue(jdbcTime + executeTime + iterateTime);
293 totalTime = System.currentTimeMillis() - startTime;
295 }
catch (SQLException se) {
297 se.printStackTrace();
299 }
catch (Exception e) {
309 }
catch (SQLException se2) {
315 }
catch (SQLException se) {
316 se.printStackTrace();
333 statsTotal.getMean(),
336 statsTotal.getPercentile(85),
337 statsExecute.getMean(),
338 statsExecute.getMin(),
339 statsExecute.getMax(),
340 statsExecute.getPercentile(85),
341 statsExecute.getPercentile(25),
342 statsExecute.getStandardDeviation(),
346 statsJdbc.getPercentile(85),
347 statsIterate.getMean(),
348 statsIterate.getMin(),
349 statsIterate.getMax(),
350 statsIterate.getPercentile(85),
356 (long) statsTotal.getSum() + firstExecute + firstJdbc + firstIterate,
359 LResult.add(
"Insert into results values " + insertPart);
363 statsTotal.getMean(),
366 statsTotal.getPercentile(85),
367 statsExecute.getMean(),
368 statsExecute.getMin(),
369 statsExecute.getMax(),
370 statsExecute.getPercentile(85),
371 statsExecute.getPercentile(25),
372 statsExecute.getStandardDeviation(),
376 statsJdbc.getPercentile(85),
377 statsIterate.getMean(),
378 statsIterate.getMin(),
379 statsIterate.getMax(),
380 statsIterate.getPercentile(85),
386 (long) statsTotal.getSum() + firstExecute + firstJdbc + firstIterate);
390 Map<String, String> queryIDMap, Connection benderCon, String
tableName) {
391 for (Map.Entry<String, String> entry : queryIDMap.entrySet()) {
392 String key = entry.getKey();
393 String value = entry.getValue();
395 Statement stmt = null;
397 stmt = benderCon.createStatement();
398 }
catch (SQLException ex) {
399 logger.error(
"Exception creating statement text is " + ex.getMessage());
403 String.format(
"Select query_text from queries where query_id = '%s'", key);
406 rs = stmt.executeQuery(sql);
407 }
catch (SQLException ex) {
408 logger.error(
"Exception running query " + sql +
" text is " + ex.getMessage());
414 String qString = rs.getString(1);
415 qString = qString.replaceAll(
"##TAB##",
tableName);
418 queryIDMap.put(key, qString);
421 }
catch (SQLException ex) {
422 logger.error(
"Exception making next call text is " + ex.getMessage());
425 if (resultCount > 1) {
426 System.out.println(
"multiple values for queryId " + key);
432 List<String> resultArray, Map<String, String> queryIDMap,
int iterations) {
434 for (Map.Entry<String, String> entry : queryIDMap.entrySet()) {
435 String
id = entry.getKey();
436 String query = entry.getValue();
438 resultArray.add(
executeQuery(conn,
id, query, iterations));
443 for (String insertPart :
LResult) {
446 sin = bencherCon.createStatement();
447 sin.execute(insertPart);
448 }
catch (SQLException ex) {
449 logger.error(
"Exception performing insert '" + insertPart +
"' text is "
static final String RESULTS_PASS
String executeQuery(Connection conn1, String qid, String sql, int iterations)
static final String JDBC_DRIVER
void doWork(String[] args, int query)
static final String DB_URL
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
String queryResultMachine
void runQueries(List< String > resultArray, Map< String, String > queryIDMap, int iterations)
static final Logger logger
static void main(String[] args)