This question can probably be asked on StackOverflow as well, but I'll try here first...
Performance of INSERT and UPDATE statements in our database seems to be degrading and causing poor performance in our web app.
Tables are InnoDB and the application uses transactions. Are there any easy tweaks that I can make to speed things up?
I think we might be seeing some locking issues, how can I find out?
Check if your hardware and OS is properly configured and tuned:
Check, if your MySQL/InnoDB instance is properly tuned:
Load data infile
command is much faster for series of inserts.select count(*) from table;
is much slower for innodb than for myisam.Some useful links:
With the default innoDB config you'll be limited to how fast you can write and flush transactions to disk. If you can deal with losing a little ACID, experiment with innodb_flush_log_at_trx_commit. Set to 0 to write and flush the log to disk about every second. Set to 1 (default) to write and flush on every commit. Set to 2 to write to the log file after every commit but flush only once per second.
If you can deal with losing 1s of transactions, this can be a great way to vastly improve write performance.
Also, pay attention to what your disks are doing. RAID 10 > RAID 5 for writes at the cost of an extra disk.
Locking issues will be exampled by the connection statuses in
show full processlist;
Read through the
my.cnf
and MySQL documentation. Configuration options are very well documented.Generally speaking, you want as much to be processed in memory as possible. For query optimization, that means avoiding temporary tables. Proper application of indexes.
Tuning is going to be specific to your preferred database engine and application architecture. There's substantial resources pre-existing an Internet search away.
Switching on the Innodb monitors can help identify the causes of locks and deadlocks:
SHOW ENGINE INNODB STATUS and the InnoDB Monitors
InnoDB is a pretty good engine. However, it highly relies on being 'tuned'. One thing is that if your inserts are not in the order of increasing primary keys, innoDB can take a bit longer than MyISAM. This can easily be overcome by setting a higher innodb_buffer_pool_size. My suggestion is to set it at 60-70% of your total RAM. I am running 4 such servers in production now, inserting about 3.5 million rows a minute. They already have close to 3 Terabytes. InnoDB it had to be , because of the highly concurrent inserts. There are further ways to speed up inserts. And I've benchmarked some.
How I solve insert and update performance issues in MySQL in web application just by disable the auto-commit and commit changes once in java. As suggested in the mysql documentation.
MySQL Docs