Question

I'm really new to MySQL and just started to use the InnoDB table engine on my VPS.

Server info: 4 x 2.4 ghz, 8 Gb ram, 120gb Raid10.

My.cfg:

[mysqld]
innodb_file_per_table=1
innodb_buffer_pool_size=4G
innodb_log_file_size=512M
innodb_flush_log_at_trx_commit=2

Table to insert has 6 ints and 1 date and 1 trigger for mapping -> inserts 1 row for each row into a mapping table.

The last line helps a lot with speeding up the inserts (the database is 80% insert/update vs 20% read).

But when I do some tests, I call a PHP file in the webbrowser which will do 10 000 inserts, it takes about 3 seconds (is this fast/slow for this hardware?). But when I open multiple tabs and open the PHP file at the same time, they all have an execution time of 3 seconds, but they are waiting for each other to finish :/

Any ideas which settings I should add? Or other settings I should add for faster inserts are greatly appreciated!

Was it helpful?

Solution

3,300 inserts a second is quite respectable, especially with a trigger. It's hard to know more about that without understanding the tables.

What are you doing about commits? Are you doing all 10K inserts and then committing once? If so, other clients doing similar tasks are probably locked out until each client runs. That's a feature!

On the other hand, if you're using autocommit you're making your MySQL server churn.

The best strategy is to insert chunks of something like 100 or 500 rows, and then commit.

You should attempt to solve this kind of lockout not with configuration settings, but by tuning your web php application to manage transactions carefully.

You might want to consider using a MyISAM table if you don't need robust transaction semantics for this application. MyISAM handles large volumes of inserts more quickly. That is, if you don't particularly care if you read data that's current or a few seconds old, then MyISAM will serve you well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top