High CPU usage after API data import
Posted: Mon Jan 22, 2018 2:15 am
I'm running MT on a Raspberry Pi (RPI Model B, single core) and, while it works, I've noticed that the CPU usage shoots up to 100% for a minute or two after each time WeeWx writes its 'current' data via the API. (It does this every 5 minutes)
Looking at the 'api.php' script I can see where the data in written to the database ("INSERT INTO alldata...") but it seems to be followed immediately by an "ALTER TABLE alldata ORDER BY dateTime" statement.
I can see that the 'alldata' table has a index on the 'dateTime' field (still learning about MySQL but I have a very long experience with relational databases in general - I don;t think I have misinterpreted the output of the 'show index from alldata' statement).
I've not studied this further but I'm guessing that the 'ALTER TABLE' statement is where MySQL is spending its time as it (currently) has to sort 138687 records.
Is there any reason why the records in the table are being reordered after each single record insertion rather than leaving this up to the index defined on the same field? (Or am I showing my ignorance of the finer features of MySQL?)
Susan
Looking at the 'api.php' script I can see where the data in written to the database ("INSERT INTO alldata...") but it seems to be followed immediately by an "ALTER TABLE alldata ORDER BY dateTime" statement.
I can see that the 'alldata' table has a index on the 'dateTime' field (still learning about MySQL but I have a very long experience with relational databases in general - I don;t think I have misinterpreted the output of the 'show index from alldata' statement).
I've not studied this further but I'm guessing that the 'ALTER TABLE' statement is where MySQL is spending its time as it (currently) has to sort 138687 records.
Is there any reason why the records in the table are being reordered after each single record insertion rather than leaving this up to the index defined on the same field? (Or am I showing my ignorance of the finer features of MySQL?)
Susan