简体   繁体   English

与MYISAM相比,插入期间InnoDB的mysql速度很慢

[英]mysql is slow with InnoDB during insert compared to MYISAM

I just installed MySQL 5.5 which have InnoDB default engine and realized INSERT queries really slow! 我刚刚安装了MySQL 5.5,它有InnoDB默认引擎,实现INSERT查询真的很慢! After disabling general-log it got a bit better but still real slow. 禁用通用日志后,它会变得更好但仍然很慢。 I analyzing mysql to find the problem but no chance. 我分析mysql找到问题但没有机会。

Here's benchmark comparing this: 这是基准比较:

Testing a(n) MYISAM table using 500 rows. 使用500行测试(n)MYISAM表。 - 5866 inserts per second. - 每秒5866次插入。 - 128866 row reads per second. - 每秒128866行读取。 - 56306 updates per second. - 每秒56306次更新。

Testing a(n) INNODB table using 500 rows. 使用500行测试(n)INNODB表。 - 9 inserts per second. - 每秒9次插入。 - 28539 row reads per second. - 每秒28539行读取。 - 4358 updates per second. - 每秒4358次更新。

I've got 9 insert queries on InnoDB compared to 5866 with MyISAM. 我在InnoDB上有9个插入查询,而MyISAM有5866个。

here's my my.ini(windows 8 64bit): 这是我的my.ini(windows 8 64bit):

[mysql]

default-character-set=utf8
no-auto-rehash

[mysqld]
max_allowed_packet = 500M
table_open_cache = 512

# The TCP/IP Port the MySQL Server will listen on
port=3306

# Path to installation directory. All paths are usually resolved relative to this.
basedir="C:\Program Files\MySQL\MySQL Server 5.5\"

# Path to the database root
datadir="D:\MySQL Datafiles\data\"

# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8

# The default storage engine that will be used when create new tables when
# default-storage-engine=MYISAM

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

# Enable Windows Authentication
# plugin-load=authentication_windows.dll

# General and Slow logging.
#log-output=FILE
#general-log=0
#general_log_file="POOYA.log"
#slow-query-log=0
#slow_query_log_file="POOYA-slow.log"
#long_query_time=10

#innodb_flush_log_at_trx_commit = 2

# Binary Logging.
# log-bin

# Error Logging.
log-error="POOYA.err"


max_connections=100

query_cache_size=32M

table_cache=512

tmp_table_size=64M

thread_cache_size=8

myisam_max_sort_file_size=100G

myisam_sort_buffer_size=64M

key_buffer_size=256M

# Size of the buffer used for doing full table scans of MyISAM tables.
# Allocated per thread, if a full scan is needed.
read_buffer_size=1M
read_rnd_buffer_size=4M

# This buffer is allocated when MySQL needs to rebuild the index in
# REPAIR, OPTIMZE, ALTER table statements as well as in LOAD DATA INFILE
# into an empty table. It is allocated per thread so be careful with
# large settings.
sort_buffer_size=1M

#*** INNODB Specific options ***
# innodb_data_home_dir=0.0

# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
# skip-innodb

# Additional memory pool that is used by InnoDB to store metadata
# information.  If InnoDB requires more memory for this purpose it will
# start to allocate it from the OS.  As this is fast enough on most
# recent operating systems, you normally do not need to change this
# value. SHOW INNODB STATUS will display the current amount used.
innodb_additional_mem_pool_size=64M

# If set to 1, InnoDB will flush (fsync) the transaction logs to the
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# transactions, you may set this to 0 or 2 to reduce disk I/O to the
# logs. Value 0 means that the log is only written to the log file and
# the log file flushed to disk approximately once per second. Value 2
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
innodb_flush_log_at_trx_commit=1

# The size of the buffer InnoDB uses for buffering log data. As soon as
# it is full, InnoDB will have to flush it to disk. As it is flushed
# once per second anyway, it does not make sense to have it very large
# (even with long transactions).
innodb_log_buffer_size=8M

# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
# row data. The bigger you set this the less disk I/O is needed to
# access data in tables. On a dedicated database server you may set this
# parameter up to 80% of the machine physical memory size. Do not set it
# too large, though, because competition of the physical memory may
# cause paging in the operating system.  Note that on 32bit systems you
# might be limited to 2-3.5G of user level memory per process, so do not
# set it too high.
innodb_buffer_pool_size=512M

# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
innodb_log_file_size=49M

# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=17
[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

I've edited this file for high performance, also never had any problem with mysql 5.1 我已经编辑了这个文件以获得高性能,而且mysql 5.1也没有任何问题

As requested, the logging on commit level often causes a lot of disk-stress and by that reducing the throughput of data on mysql instances with inno for a great deal. 根据要求,登录提交级别通常会导致大量磁盘压力,并且通过使用inno大大减少mysql实例上的数据吞吐量。

Setting your mysql.ini to innodb_flush_log_at_trx_commit = 0 (or 2) does often solve this issue. 将mysql.ini设置为innodb_flush_log_at_trx_commit = 0 (或2)通常可以解决此问题。

Plese note, ACID rules would love that value to be at 1... 请注意,ACID规则会喜欢这个值为1 ...

Are you adding the rows one at a time? 您是一次添加一行吗?

If you add multiple rows per transaction, that helps a lot . 如果您为每个事务添加多行,这会有很大帮助。

# 1:
INSERT INTO my_table VALUES (1, "A");
INSERT INTO my_table VALUES (2, "B");

# 2:
INSERT INTO my_table VALUES (1, "A"),(2, "B");

# 3:
BEGIN;
INSERT INTO my_table VALUES (1, "A");
INSERT INTO my_table VALUES (2, "B");
COMMIT;

In InnoDB #2 and #3 will be much faster than #1. 在InnoDB#2和#3将比#1快得多。

#2 also helps with MyISAM, but not nearly as much. #2也有助于MyISAM,但差不多。 Rough numbers, I've seen this speed up MyISAM by 2x, and InnoDB by 100x. 粗糙的数字,我看到这个速度提高了MyISAM 2倍,InnoDB提高了100倍。

您也可以使用以下命令直接在MySQL命令行上进行设置:

SET GLOBAL innodb_flush_log_at_trx_commit = 0;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM