I am in the process of adding a new feature to a system. The process will read live data from PLC´s and store them in a database.
The data table will have 4 columns: variable_id (SMALLINT), timestamp (TIMESTAMP), value(FLOAT), quality(TINYINT).
The primary key is (variable_id, timestamp).
The system needs to be able to insert 1000-2000 records every second.
The data table will keep the last 24 hours of data, older data is deleted from the table.
The data table also needs to handle 5-10 select statements every second. The select statement is selecting the lastest value from the table for a specific variable and displaying it on the web.
Should I use MyISAM or InnoDB table format? Does MyISAM lock the entire table while doing inserts, thus blocking the select statements from the web interface?
Currently all the data tables in the data base are MyISAM tables.
For any project with frequent concurrent reads and writes, you should use
InnoDB.With
@@concurrent_insertenabled,MyISAMcan append inserted rows to the end while still reading concurrently from another session.However, if you ever to anything but the
INSERT, this can fail (i. e. the table will lock).It will be better to batch these inserts and do them in batches.
InnoDBis much faster in terms of rows per second than in transactions per second.Note that
InnoDBlocks all rows examined, not only those affected.If your
DELETEstatement will ever use a fullscan, the concurrentINSERTswill fail (since the fullscan will makeInnoDBto place the gap locks on all records browsed including the last one).