Mysql

HAproxy 與 MySQL Master-Master Replication 非常慢

  • June 27, 2012

我有兩台 MySQL 伺服器處於多主機模式,一台 HAproxy 機器用於簡單的負載平衡/冗餘。當我直接連接到其中一台伺服器並嘗試更新大約 100,000 個條目時,它在大約半分鐘內完成,包括複製。通過代理連接時,通常需要整整三分鐘。有這種延遲是正常的嗎?我的代理配置有問題嗎(包括在下面)?這真的令人沮喪,因為我認為代理會進行某種負載平衡,或者至少幾乎沒有成本。

#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events.  This is done
#    by adding the '-r' option to the SYSLOGD_OPTIONS in
#    /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
#   file. A line like the following can be added to
#   /etc/sysconfig/syslog
#
#    local2.*                       /var/log/haproxy.log
#
log         127.0.0.1 local2

#    chroot      /var/lib/haproxy
#    pidfile     /var/run/haproxy.pid
maxconn     4096
user        haproxy
group       haproxy
daemon
#debug
#quiet


# turn on stats unix socket
stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode                    tcp
log                     global
#option                  tcplog
option                  dontlognull
option                  tcp-smart-accept
option                  tcp-smart-connect
#option http-server-close
#option forwardfor       except 127.0.0.0/8
#option                  redispatch
retries                 3
#timeout http-request    10s
#timeout queue           1m
timeout connect         400
timeout client          500
timeout server          300
#timeout http-keep-alive 10s
#timeout check           10s
maxconn                 2000

listen mysql-cluster 0.0.0.0:3306
   mode tcp
   balance roundrobin
   option tcpka
   option httpchk

server db01 192.168.15.118:3306 weight 1 inter 1s rise 1 fall 1
server db02 192.168.15.119:3306 weight 1 inter 1s rise 1 fall 1

每次更新都連接一次這一事實意味著每個連接都有一點成本。這麼多更新加起來有很多連接。如果可以,請嘗試批量更新。或者,因為它是主/主節點,所以只需選擇一個節點並將更新推送到那裡。

引用自:https://serverfault.com/questions/402146