17 package com.mapd.bench;
20 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import java.io.BufferedReader;
25 import java.io.FileNotFoundException;
26 import java.io.FileReader;
27 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.List;
35 final static Logger
logger = LoggerFactory.getLogger(Benchmark.class);
38 static final String
JDBC_DRIVER =
"ai.heavy.jdbc.HeavyAIDriver";
39 static final String
DB_URL =
"jdbc:heavyai:localhost:6274:mapd";
42 static final String
USER =
"admin";
43 static final String
PASS =
"HyperInteractive";
51 "%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";
79 "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";
95 int iterations = Integer.valueOf(args[0]);
96 logger.debug(
"Iterations per query is " + iterations);
98 String queryFile = args[1];
102 url = (args.length > 3) ? args[3] :
DB_URL;
103 iUser = (args.length > 4) ? args[4] :
USER;
110 }
catch (ClassNotFoundException ex) {
111 logger.error(
"Could not load class " +
driver +
" " + ex.getMessage());
117 List<String> resultArray =
new ArrayList();
120 br =
new BufferedReader(
new FileReader(queryFile));
123 while ((sCurrentLine = br.readLine()) != null) {
125 String sqlQuery = null;
127 for (
int i = sCurrentLine.length(); i > 0; i--) {
128 if (sCurrentLine.charAt(i - 1) ==
',') {
130 expected = Integer.valueOf(sCurrentLine.substring(i).trim());
131 sqlQuery = sCurrentLine.substring(0, i - 1).trim().substring(1);
136 sqlQuery = sqlQuery.substring(0, sqlQuery.length() - 1);
138 System.out.println(String.format(
"Q%02d %s", qCount, sqlQuery));
140 resultArray.add(
executeQuery(sqlQuery, expected, iterations, qCount));
144 }
catch (FileNotFoundException ex) {
145 logger.error(
"Could not find file " + queryFile +
" " + ex.getMessage());
147 }
catch (IOException ex) {
148 logger.error(
"IO Exeception " + ex.getMessage());
154 for (String s : resultArray) {
155 System.out.println(s);
159 String
executeQuery(String sql,
int expected,
int iterations,
int queryNum) {
160 Connection
conn = null;
161 Statement stmt = null;
163 Long firstExecute = 0l;
165 Long firstIterate = 0l;
167 DescriptiveStatistics statsExecute =
new DescriptiveStatistics();
168 DescriptiveStatistics statsJdbc =
new DescriptiveStatistics();
169 DescriptiveStatistics statsIterate =
new DescriptiveStatistics();
170 DescriptiveStatistics statsTotal =
new DescriptiveStatistics();
176 logger.debug(
"Connecting to database url :" +
url);
179 long startTime = System.currentTimeMillis();
180 for (
int loop = 0; loop < iterations; loop++) {
182 stmt = conn.createStatement();
184 long timer = System.currentTimeMillis();
185 ResultSet rs = stmt.executeQuery(sql);
187 long executeTime = 0;
193 jdbcTime = (System.currentTimeMillis() - timer) - executeTime;
195 jdbcTime = (System.currentTimeMillis() - timer);
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");
203 timer = System.currentTimeMillis();
207 Object obj = rs.getObject(1);
208 if (obj != null && obj.equals(statsExecute)) {
209 logger.info(
"Impossible");
213 long iterateTime = (System.currentTimeMillis() - timer);
215 if (resultCount != expected) {
217 "Expect " + expected +
" actual " + resultCount +
" for query " + sql);
223 firstJdbc = jdbcTime;
224 firstExecute = executeTime;
225 firstIterate = iterateTime;
228 statsJdbc.addValue(jdbcTime);
229 statsExecute.addValue(executeTime);
230 statsIterate.addValue(iterateTime);
231 statsTotal.addValue(jdbcTime + executeTime + iterateTime);
238 totalTime = System.currentTimeMillis() - startTime;
240 }
catch (SQLException se) {
242 se.printStackTrace();
243 }
catch (Exception e) {
252 }
catch (SQLException se2) {
258 }
catch (SQLException se) {
259 se.printStackTrace();
265 statsTotal.getMean(),
268 statsTotal.getPercentile(85),
269 statsExecute.getMean(),
270 statsExecute.getMin(),
271 statsExecute.getMax(),
272 statsExecute.getPercentile(85),
273 statsExecute.getPercentile(25),
274 statsExecute.getStandardDeviation(),
278 statsJdbc.getPercentile(85),
279 statsIterate.getMean(),
280 statsIterate.getMin(),
281 statsIterate.getMax(),
282 statsIterate.getPercentile(85),
288 (long) statsTotal.getSum() + firstExecute + firstJdbc + firstIterate);
static void main(String[] args)
void doWork(String[] args, int query)
static final String DB_URL
static final String JDBC_DRIVER
static final Logger logger
String executeQuery(String sql, int expected, int iterations, int queryNum)