Home Forum Software Database optimisations Reply To: Database optimisations

#775
Hexide
Participant

>A cron script to compute average/month, ran once per month?
Yes, it could be. However if there will me many devices, high load will be generated on server. So to prevent this from happening there are couple ways:

1. Calculate each average with intervals, this will take longer for data to be generated but it works well.
2. Load entire months worth of data into a memory table and request it from there.
3. Load entire months worth of data into script variable and use it within script.
4. Have a read-only mysql replication and use it to query data.

Once averages are collected, raw data for previous month can be moved into archive table ( MySQL has special storage engine for this ), but downside of this engine is that we can’t search for data ( use WHERE clause ). So regular table should be used for archiving.

When displaying full historical graph, we can cache all data for at least few hours. So data from database it’s requested every few hours for single device.