2015-01-12 17:24:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
var HyriseConnector = function(endpointUrl) {
|
|
|
|
this._endpointUrl = endpointUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
HyriseConnector.prototype.executeSQL = function(query, callback, errorCallback) {
|
|
|
|
var url = encodeURI(this._endpointUrl);
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
jQuery.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: url,
|
|
|
|
dataType: 'json',
|
|
|
|
data: {
|
|
|
|
performance: true,
|
|
|
|
sql: query
|
|
|
|
},
|
|
|
|
success: function(result) {
|
|
|
|
if (typeof result.real_size === "undefined") {
|
|
|
|
result.real_size = 0;
|
|
|
|
result.rows = [];
|
|
|
|
result.header = [];
|
|
|
|
if (!result.performanceData) result.performanceData = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
self._formatPerformanceData(result);
|
|
|
|
callback(result);
|
|
|
|
},
|
|
|
|
error: errorCallback
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
HyriseConnector.prototype._formatPerformanceData = function(object) {
|
|
|
|
var performanceData = object.performanceData;
|
|
|
|
|
|
|
|
var totalTime = 0;
|
|
|
|
var queryTaskTime = 0;
|
2015-01-26 15:40:39 +01:00
|
|
|
var parseTime = 0;
|
2015-01-12 17:24:24 +01:00
|
|
|
|
|
|
|
$.each(performanceData, function(i, data) {
|
|
|
|
data.time_ms = data.endTime - data.startTime;
|
|
|
|
|
|
|
|
totalTime += data.time_ms;
|
|
|
|
if (data.name === 'SQLQueryTask') queryTaskTime += data.time_ms;
|
2015-01-26 15:40:39 +01:00
|
|
|
if (data.name === 'RequestParseTask') parseTime += data.time_ms;
|
2015-01-12 17:24:24 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
object.performanceData = {
|
|
|
|
totalTime: totalTime,
|
|
|
|
queryTaskTime: queryTaskTime,
|
2015-01-26 15:40:39 +01:00
|
|
|
parseTime: parseTime,
|
|
|
|
operators: performanceData,
|
2015-01-12 17:24:24 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
HyriseConnector.prototype.benchmarkSQL = function(query, numRuns, callback) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
function __aggregateData(allData) {
|
|
|
|
var result = {
|
|
|
|
totalTime: 0,
|
|
|
|
queryTaskTime: 0,
|
2015-01-26 15:40:39 +01:00
|
|
|
parseTime: 0,
|
2015-01-12 17:24:24 +01:00
|
|
|
numRuns: allData.length,
|
|
|
|
operators: []
|
|
|
|
};
|
|
|
|
|
|
|
|
var operatorMap = {};
|
|
|
|
|
|
|
|
$.each(allData, function(i, run) {
|
|
|
|
var perfData = run.performanceData;
|
|
|
|
result.totalTime += perfData.totalTime;
|
|
|
|
result.queryTaskTime += perfData.queryTaskTime;
|
2015-01-26 15:40:39 +01:00
|
|
|
result.parseTime += perfData.parseTime;
|
2015-01-12 17:24:24 +01:00
|
|
|
|
|
|
|
$.each(perfData.operators, function(i, data) {
|
|
|
|
if (!(data.id in operatorMap)) {
|
|
|
|
operatorMap[data.id] = data;
|
|
|
|
} else {
|
|
|
|
operatorMap[data.id].duration += data.duration;
|
|
|
|
operatorMap[data.id].startTime += data.startTime;
|
|
|
|
operatorMap[data.id].endTime += data.endTime;
|
|
|
|
operatorMap[data.id].time_ms += data.time_ms;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Calc average and Transform into array
|
|
|
|
result.totalTime /= result.numRuns;
|
|
|
|
result.queryTaskTime /= result.numRuns;
|
2015-01-26 15:40:39 +01:00
|
|
|
result.parseTime /= result.numRuns;
|
2015-01-12 17:24:24 +01:00
|
|
|
|
|
|
|
$.each(operatorMap, function(id, data) {
|
|
|
|
data.duration /= result.numRuns;
|
|
|
|
data.startTime /= result.numRuns;
|
|
|
|
data.time_ms /= result.numRuns;
|
|
|
|
result.operators.push(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
callback({
|
|
|
|
performanceData: result
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var allData = [];
|
2015-01-26 15:40:39 +01:00
|
|
|
var num_completed = 0;
|
|
|
|
|
2015-01-12 17:24:24 +01:00
|
|
|
function __run() {
|
|
|
|
self.executeSQL(query, function(result) {
|
|
|
|
allData.push(result);
|
|
|
|
|
|
|
|
// Run again or return aggregated Data
|
2015-01-26 15:40:39 +01:00
|
|
|
num_completed++;
|
|
|
|
if (num_completed == numRuns) __aggregateData(allData);
|
2015-01-12 17:24:24 +01:00
|
|
|
});
|
|
|
|
}
|
2015-01-26 15:40:39 +01:00
|
|
|
|
|
|
|
for (var i = 0; i < numRuns; ++i) {
|
|
|
|
__run();
|
|
|
|
}
|
2015-01-12 17:24:24 +01:00
|
|
|
|
|
|
|
__run();
|
|
|
|
};
|