-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL performance in feed_model #93
Comments
Hello Henols Thanks a lot for your insight, I can see the benefit of the first two, it would be interesting to see the timing difference. I did quite a bit of work on establishing the best method for get_feed_data of which creating 1000's of queries actually came out best. Here's the blogpost I did detailing the investigation: http://openenergymonitor.blogspot.co.uk/2012/04/speeding-up-emoncms-feed-data-requests.html Do you think your query will be faster at selecting 400 datapoints over months of 5s time series data? I was wondering if creating many queries was an issue hence my initial use of a mysql only resolution query for get_feed_data but after the test it seemed that as long as the data was indexed it was actually faster at certain queries than the alternative. Lets get some timing data on this Thanks a lot Trystan |
Hi Tristan The test data are over 5 month and 10 seconds time series. 1000 queries
1 query
1000 queries
1 query
The single query preforms faster if series of data are less then 45000 records. Maybe there shall be an option to choose how the data shall be collected or a query can be made check the number of rows and then decide what the approach shall be. Henrik |
Forgot to add the java script that I did the timings with. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="content-script-type" content="text/javascript">
<script language="javascript" type="text/javascript" src="/emon/Includes/Vis/flot/jquery.js"></script>
</head>
<body>
<script type="text/javascript">
var url = "/emon/feed/data.json";
var apiKey ="33c23d935b49746f8b5efe3e2a9d3763";
var id = 3;
$(function() {
var end = ((new Date()).getTime());
document.write("<table><tr><th>millis</th><th>month</th><th>rows</th><th>dp</th></tr>");
callApi(1,end, 400);
callApi(1,end, 1000);
callApi(2,end, 400);
callApi(2,end, 1000);
callApi(3,end, 400);
callApi(3,end, 1000);
callApi(4,end, 400);
callApi(4,end, 1000);
callApi(5,end, 400);
callApi(5,end, 1000);
});
function callApi(month, end, dp){
var start = end - 3600000 * 24 * 30 * month;
var payLoad = buildPayLoad(apiKey, id, start, end, dp);
var totalTime = 0;
for (i=1; i<=10; i++){
var startCall = ((new Date()).getTime());
$.ajax({
url: url,
data: payLoad,
async: false,
method: 'GET',
dataType: 'json',
success: function(dataVal){
totalTime += (new Date()).getTime() - startCall;
dataLength = dataVal.length;
}
});
}
document.write("<tr><td align='right'>"+ (totalTime/10)+ "</td><td align='right'>"+month+"</td><td align='right'>"+dataLength+"</td><td align='right'>"+dp+"</td></tr>");
}
function buildPayLoad(apiKey, id, start, end, dp){
var apiKeyData ="&apikey="+apiKey;
var idData = "&id=" + id;
var endData = "&end=" + end;
var startData = "&start=" + start;
var dpData = "&dp=" + dp;
return apiKeyData+idData+startData+endData+dpData;
}
</script>
</body>
</html> Henrik |
Hello Henols, that's fantastic!! a definite improvement at the below 45000 records range as you say. Coupled with averaging being a technically more correct implementation, great! lets implement it this way. |
Background:
Creating a db query are more costly then executing a complex query.
The strategy in emoncms seams to be creating db queries instead of doing complex queries and that kills performance, on a fast system it may not be noticeable but on slow boxes and i guess on an Raspberry PI its very noticeable.
Performance is a must and to keep emoncms in the pole position this has to be done right...
function get_user_feeds creates 1 + nr_of_feeds * 2 queries and can be done in 1, this function seams to be hitted every 10th second per opened page
Its the same with function get_user_feeds_size and it can be taken down to 2 queries.
Function get_feed_data are creating 1000 queries per feed if you display a multi-graph chart!
And it can be reduced to 1 query, its not doing 100% the same but in my opinion its more correct to get an average value between the time slots.
There are much more to be done and I will create issues when I find some show stoppers.
The text was updated successfully, but these errors were encountered: