我正在运行一个插入很多行的应用程序,我们遇到了一些低性能。所以我开始用 sysbench 和 oltp_insert.lua(实际上是用随机密钥插入)对 Galera 集群进行基准测试。
集群的性能真的很差。
用同样的测试:
表结构是这样的:
Table: sbtest1
Create Table: CREATE TABLE `sbtest1` (
`id` int(11) NOT NULL,
`k` int(11) NOT NULL DEFAULT '0',
`c` char(120) NOT NULL DEFAULT '',
`pad` char(60) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `k_1` (`k`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过的(没有成功):
wsrep_slave_threads=16
wsrep_sync_wait=0
(虽然我不执行读取)配置:
[mysqld]
binlog_format=ROW
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
datadir=/var/lib/mysql
innodb_buffer_pool_size = 300MB
innodb_large_prefix=1
innodb_file_format=Barracuda
transaction-isolation = READ-COMMITTED
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_slave_threads = 16
wsrep_max_ws_rows=131072
wsrep_max_ws_size=1073741824
wsrep_convert_LOCK_to_trx=0
wsrep_causal_reads=OFF
wsrep_sst_method=xtrabackup-v2
Run Code Online (Sandbox Code Playgroud)
小智 4
我遇到了同样的问题。首先要做的是检查以下变量:
select @@innodb_flush_log_at_trx_commit;
select @@sync_binlog;
Run Code Online (Sandbox Code Playgroud)
将 innodb_flush_log_at_trx_commit 设置为 2 并将sync_binlog 设置为 0 将显着提高性能。
原因在于认证机制和多主行为的本质。插入会非常慢,因为为了提交事务,集群将确保在每个节点提交时刷新所有日志。
请确保您的缓存也适合使用以下查询的 RAM:
select ((@@thread_stack +@@binlog_cache_size +@@read_buffer_size + @@read_rnd_buffer_size +@@sort_buffer_size +@@join_buffer_size + @@global.net_buffer_length +@@global.query_prealloc_size + @@binlog_stmt_cache_size) * @@max_connections + (@@query_cache_size + @@innodb_buffer_pool_size + @@innodb_log_buffer_size + @@key_buffer_size))/(1024*1024);
Run Code Online (Sandbox Code Playgroud)