Mysql-proxy Load Balancing doesn't work

Asked by Fendi

I tried mysql-proxy 0.8.2 epel6 on Centos 6.3.
There are 2 backend behind mysql-proxy and 1 webserver to test mysql-query with simple read php.

I want to use simple load balance read query on 2 backend. I tried default configuration without lua script.
When I use wireshark to analyze the traffic, all mysql query and connect only go to one backend.

The issue keep remain even I use balance.lua, all connection only go to one backend.

This is my running configuration.
mysql-proxy --plugins=proxy -P 192.168.1.2:3306 -b 192.168.1.3:3306 -b 192.168.1.4:3306 --log-file=/home/mysql-proxy/mysql-proxy.log --log-level=debug --proxy-lua-script=/home/mysql-proxy/balance.lua &

Any advice?

Thanks

Fendi

Question information

Language:
English Edit question
Status:
Answered
For:
MySQL Proxy Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Jason (zzs) said :
#1

Can you post the balance.lua and the log output.

Revision history for this message
Fendi (fendi-carter) said :
#2

Hi Jason

This is the log from /home/mysql-proxy/mysql-proxy.log

2013-02-25 11:31:47: (message) mysql-proxy 0.8.2 started
2013-02-25 11:31:47: (debug) max open file-descriptors = 1024
2013-02-25 11:31:47: (message) proxy listening on port 192.168.1.2:3306
2013-02-25 11:31:47: (message) added read/write backend: 192.168.1.3:3306
2013-02-25 11:31:47: (message) added read/write backend: 192.168.1.4:3306

This is the balance.lua that I copy from /usr/lib64/mysql-proxy/lua/proxy/balance.lua to /home/mysql-proxy/balance.lua

--[[ $%BEGINLICENSE%$
...
$%ENDLICENSE%$ --]]

module("proxy.balance", package.seeall)

function idle_failsafe_rw()
 local backend_ndx = 0

 for i = 1, #proxy.global.backends do
  local s = proxy.global.backends[i]
  local conns = s.pool.users[proxy.connection.client.username]

  if conns.cur_idle_connections > 0 and
     s.state ~= proxy.BACKEND_STATE_DOWN and
     s.type == proxy.BACKEND_TYPE_RW then
   backend_ndx = i
   break
  end
 end

 return backend_ndx
end

function idle_ro()
 local max_conns = -1
 local max_conns_ndx = 0

 for i = 1, #proxy.global.backends do
  local s = proxy.global.backends[i]
  local conns = s.pool.users[proxy.connection.client.username]

  -- pick a slave which has some idling connections
  if s.type == proxy.BACKEND_TYPE_RO and
     s.state ~= proxy.BACKEND_STATE_DOWN and
     conns.cur_idle_connections > 0 then
   if max_conns == -1 or
      s.connected_clients < max_conns then
    max_conns = s.connected_clients
    max_conns_ndx = i
   end
  end
 end

 return max_conns_ndx
end

Revision history for this message
Jason (zzs) said :
#3

Can you try to shutdown one backend to check if the connection goes to another backend.

Revision history for this message
Fendi (fendi-carter) said :
#4

I already tried it.
Yes it does the failover, the connection go to second backend.
But load balancing process never hapenned even after I boot the first backend, the connection now always go to the second backend.

Revision history for this message
Jason (zzs) said :
#5

Would you please paste the configuration of your mysql configuration, did you setup the replication for them.

Revision history for this message
Jason (zzs) said :
#6

Can you help with this problem?

Provide an answer of your own, or ask Fendi for more information if necessary.

To post a message you must log in.