in shardingsphere-benchmark/src/main/java/org/apache/shardingsphere/benchmark/common/statistic/BenchmarkStatistic.java [58:117]
public BenchmarkResultBean getTargetResult(DataSource dataSource, String sql, List params, List<BenchmarkResultBean> result){
Connection connection = null;
BenchmarkResultBean benchmarkResultBean = new BenchmarkResultBean();
try {
double totalTps = 0;
int totalCount = 0;
int totalRequestCount = 0;
double totalMaxTime = 0;
double totalMinTime = 0;
double totalTp95Th = 0;
double totalTp90Th = 0;
double totalTp50Th = 0;
connection = dataSource.getConnection();
ResultSet rs = JDBCDataSourceUtil.select(connection, sql, params);
while(rs.next()){
totalCount = totalCount + 1;
benchmarkResultBean.setProduct(rs.getString(2));
benchmarkResultBean.setVersion(rs.getString(3));
benchmarkResultBean.setScenario(rs.getString(4));
benchmarkResultBean.setRules(rs.getString(5));
totalTps = totalTps + rs.getDouble(6);
totalRequestCount = totalRequestCount + rs.getInt(7);
totalTp50Th = totalTp50Th + rs.getDouble(8);
totalTp90Th = totalTp50Th + rs.getDouble(9);
totalTp95Th = totalTp50Th + rs.getDouble(10);
totalMaxTime = totalMaxTime + rs.getDouble(11);
totalMinTime = totalMinTime + rs.getDouble(12);
benchmarkResultBean.setSql(rs.getString(13));
benchmarkResultBean.setDbAction(rs.getString(14));
benchmarkResultBean.setConcurrency(rs.getInt(15));
benchmarkResultBean.setUpdateTime(rs.getLong(16));
benchmarkResultBean.setDbShardingCount(rs.getInt(17));
benchmarkResultBean.setTableShardingCount(rs.getInt(18));
}
if (totalCount > 0){
Map benchmarkPerformanceData = new HashMap<>(1,1);
benchmarkPerformanceData.put("tps", totalTps / totalCount);
benchmarkPerformanceData.put("total" , totalRequestCount / totalCount);
benchmarkPerformanceData.put("maxCost" , totalMaxTime / totalCount);
benchmarkPerformanceData.put("minCost" , totalMinTime / totalCount);
benchmarkPerformanceData.put("tp50th", totalTp50Th / totalCount);
benchmarkPerformanceData.put("tp90th", totalTp90Th / totalCount);
benchmarkPerformanceData.put("tp95th", totalTp95Th / totalCount);
benchmarkResultBean.setBenchmarkResult(benchmarkPerformanceData);
result.add(benchmarkResultBean);
} else {
return null;
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
try {
connection.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
return benchmarkResultBean;
}