mysql autocommit问题导致的gtid同步变慢

这几天在研究mysql数据同步,查看一些资料发现5.7版本可以使用gtid来实现主备数据库的数据同步。

经过一些折腾,搭建完毕,在master上建库、建表、插入数据,在从库上都能看到。看来一切正常。

随着测试的深入发现了一些问题,通过一个存储过程批量往表里插入10000条数据,发现速度慢的离奇。

如果不开启gtid只是单个数据库的话速度很快。

存储过程如下:

DELIMITER ;;
create procedure vip5()
begin
declare i int default 0;
while i < 100000
do
insert into a values(1,2);
set i = i + 1;
end while;
end;;

后来发现原来是autocommit(自动提交,把数据从内存写入磁盘)搞得鬼,在执行存储过程前先执行set autocommit=0,问题解决。

my.cnf配置如下:

master:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
gtid-mode = on
enforce-gtid-consistency = 1
log-bin = /var/lib/mysql/mysql-bin-gtid
server-id = 3306100
binlog_format = row
skip_slave_start = 1
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
sync_binlog = 1

#-------------------gobal variables------------#
max_connect_errors = 100000
max_connections = 10000
wait_timeout = 3600
interactive_timeout = 3600
net_read_timeout = 3600
net_write_timeout = 3600
table_open_cache = 2000
table_definition_cache = 2000
open_files_limit = 20000
thread_cache_size = 512
#thread_handling = pool-of-threads
#thread_pool_max_threads = 5000
#thread_pool_size = 8
character-set-server = utf8
collation-server = utf8_general_ci
skip_external_locking
performance_schema = 1
myisam_recover_options = DEFAULT
skip-name-resolve
local_infile = 0
lower_case_table_names = 0
key_buffer_size = 384M
max_allowed_packet = 128M

master_info_repository = table
relay_log_info_repository = table


#--------------------innoDB------------#
innodb_buffer_pool_size = 1G
#innodb_data_file_path = ibdata1:200M:autoextend
innodb_flush_log_at_trx_commit = 0
innodb_io_capacity = 3000
innodb_lock_wait_timeout = 30
innodb_log_buffer_size = 8M
innodb_log_file_size = 200M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 85
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_support_xa = 1
innodb_thread_concurrency = 8
innodb_file_per_table
innodb_rollback_on_timeout


#------------session variables-------#
join_buffer_size = 8M
bulk_insert_buffer_size = 32M
max_heap_table_size = 96M
tmp_table_size = 96M
read_buffer_size = 16M
sort_buffer_size = 4M
read_rnd_buffer_size = 32M


expire_logs_days = 15
max_binlog_size = 200M
binlog_cache_size = 64k
log_warnings = 1
long_query_time = 0.125
##log_timestamps=SYSTEM

#---------------replicate--------------#
#slave-parallel-threads = 4
slave_parallel_workers=4
#slave_parallel_type='logical_clock'

replicate-ignore-db = mysql_identity
init_slave = 'set sql_mode=STRICT_ALL_TABLES'
log-slave-updates = 1

 

slave:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
gtid-mode = on
enforce-gtid-consistency = 1
log-bin = /var/lib/mysql/mysql-bin-gtid
server-id = 3306101
binlog_format = row
skip_slave_start = 1
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
sync_binlog = 1

#-------------------gobal variables------------#
max_connect_errors = 100000
max_connections = 10000
wait_timeout = 3600
interactive_timeout = 3600
net_read_timeout = 3600
net_write_timeout = 3600
table_open_cache = 2000
table_definition_cache = 2000
open_files_limit = 20000
thread_cache_size = 512
#thread_handling = pool-of-threads
#thread_pool_max_threads = 5000
#thread_pool_size = 8
character-set-server = utf8
collation-server = utf8_general_ci
skip_external_locking
performance_schema = 1
myisam_recover_options = DEFAULT
skip-name-resolve
local_infile = 0
lower_case_table_names = 0
key_buffer_size = 384M
max_allowed_packet = 128M

master_info_repository = table
relay_log_info_repository = table


#--------------------innoDB------------#
innodb_buffer_pool_size = 1G
#innodb_data_file_path = ibdata1:200M:autoextend
innodb_flush_log_at_trx_commit = 0
innodb_io_capacity = 3000
innodb_lock_wait_timeout = 30
innodb_log_buffer_size = 8M
innodb_log_file_size = 200M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 85
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_support_xa = 1
innodb_thread_concurrency = 8
innodb_file_per_table
innodb_rollback_on_timeout


#------------session variables-------#
join_buffer_size = 8M
bulk_insert_buffer_size = 32M
max_heap_table_size = 96M
tmp_table_size = 96M
read_buffer_size = 16M
sort_buffer_size = 4M
read_rnd_buffer_size = 32M


expire_logs_days = 15
max_binlog_size = 200M
binlog_cache_size = 64k
log_warnings = 1
long_query_time = 0.125
##log_timestamps=SYSTEM

#---------------replicate--------------#
#slave-parallel-threads = 4
slave_parallel_workers=4
#slave_parallel_type='logical_clock'

replicate-ignore-db = mysql_identity
init_slave = 'set sql_mode=STRICT_ALL_TABLES'
log-slave-updates = 1

posted on 2018-04-03 15:04  hymvp  阅读(171)  评论(0编辑  收藏  举报

导航