Re: Insert speed (JDBC and MySQL)
- From: John <no@email>
- Date: Tue, 24 Jan 2006 16:29:35 +0000
Mark Matthews wrote:
John wrote:
Hi,
I am writing a program that needs to typically carry out around 100,000 INSERTs to a mysql database. I would normally load the data using a text file, but in this case, there is the occasional query required (evenly spread through, and dependent on, the INSERTs).
I had the program connecting to a remote database and was achieving around 47ms per INSERT. I thought that connecting to the database locally would improve the speed, but it is unchanged at around 47ms.
This compares (very) unfavourably with the 0.3 ms that can be achieved by piping a text file of sql into the command line tool.
Does anyone know how to improve the performance of these INSERTs?
Similarly, what speeds can be achieved for INSERTS using JDBC? (using one sensible machine only).
Thanks,
John
John,
How are your inserts crafted? Without knowing that, you're comparing apples and oranges.
I can load 100 thousand rows using JDBC in just under a second over 100mbit ethernet via batched inserts (i.e. of the form INSERT INTO foo VALUES (...), (...), (...)), so you've definitely got something not efficient with the way you're doing it.
-Mark
Hi Mark,
I am using one Connection object.
For each INSERT, I obtain a statement using createStatement(), then call executeUpdate("queryString") on that statement. This takes the 47ms.
90% of the INSERT statements would be of the form "INSERT INTO table_name VALUES(data, data)".
I am quite reluctant to combine multiple INSERTS into one batch, because if there is an error with an update I would like the program to detect this, log it, and take corrective action.
If there is a way of improving performance without batching the inserts or combining multiple queries into one statement that would be ideal. (I'm hoping that I am doing something simple inefficiently and there is some easy way of speeding it up.)
Thanks,
John .
- Follow-Ups:
- Re: Insert speed (JDBC and MySQL)
- From: Mark Matthews
- Re: Insert speed (JDBC and MySQL)
- References:
- Insert speed (JDBC and MySQL)
- From: John
- Re: Insert speed (JDBC and MySQL)
- From: Mark Matthews
- Insert speed (JDBC and MySQL)
- Prev by Date: Re: Insert speed (JDBC and MySQL)
- Next by Date: Re: newbie question: processing large database in chunks?
- Previous by thread: Re: Insert speed (JDBC and MySQL)
- Next by thread: Re: Insert speed (JDBC and MySQL)
- Index(es):
Relevant Pages
|
|