2

Mysqlを使用してJdbcでプリペアドステートメントを使用したバッチ挿入は非常に遅いです。3億レコードを挿入しようとしています。レコードは29のテーブルに分割されます。バッチごとに2000レコードと1000レコードを試してみましたが、挿入にかかる時間はそれぞれ20分と10分です。1つのテーブルだけに20列が残り、すべてのテーブルに3から6の列があります。

Javaコードは5秒で10000行を読み取りますが、バッチ挿入には90分の時間がかかります

私は4GBのRAMを搭載したWindows7で作業しています

私のMysqlmy.ini構成は

[client]

port=3306

[mysql]

default-character-set=latin1

[mysqld]

max_allowed_packet=100M
wait_timeout=3000

port=3306

basedir="C:/Program Files (x86)/MySQL/MySQL Server 5.1/"

datadir="C:/ProgramData/MySQL/MySQL Server 5.1/Data/"

default-character-set=latin1

default-storage-engine=INNODB

sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

max_connections=100

query_cache_size=0

table_cache=256

tmp_table_size=33M

thread_cache_size=8

myisam_max_sort_file_size=100G

myisam_sort_buffer_size=66M

key_buffer_size=53M

read_buffer_size=64K
read_rnd_buffer_size=256K

sort_buffer_size=256K

innodb_additional_mem_pool_size=3M

innodb_flush_log_at_trx_commit=1

innodb_log_buffer_size=2M

innodb_buffer_pool_size=206M

innodb_log_file_size=52M

innodb_thread_concurrency=10
4

1 に答える 1

0

My suggestion would be to DROP all of the tables' indexes, INSERT the rows, and then recreate the indexes. A database can insert data much faster if it doesn't need to update indexes for each row inserted. And an index can be created from scratch faster than by building it with a "random" sequence of inserts.

It may also improve things if you can sort the rows of the respective tables into primary key order, and insert them in that order.

Finally, batching is a trade-off between the costs of lots of little requests and the costs of doing large / long transactions. Try experimenting with batch sizes that are smaller and large than those you are currently using.

于 2012-11-01T13:28:51.827 に答える