There are three simple practices that can improve general INSERT
throughput. Each requires consideration on how the data is
collected and what is acceptable data loss in a disaster.
General inserting of rows can be performed as single INSERT’s for
example.
INSERT INTO table (col1, col2, col3) VALUES (?, ?, ?);
INSERT INTO table (col1, col2, col3) VALUES (?, ?, ?);
INSERT INTO table (col1, col2, col3) VALUES (?, ?, ?);
While this works, there are two scalability limitations. First is
the network overhead of the back and forth of each SQL statement,
the second is the synchronous nature, that is your code can not
continue until your INSERT is successfully completed.
The first improvement is to use MySQL’s multi values capability
with INSERT. That is you can insert multiple rows with a single
INSERT statement. For example:
INSERT INTO table (col1, col2, col3) VALUES (?, ?, ?), (?, ?, ?), (?, ?, ?);
…
[Read more]