54
Ivan Zoratti MaxScale MySQL Meetup - EffectiveMySQL V1401.01

MaxScale for Effective MySQL Meetup NYC - 14.01.21

Embed Size (px)

DESCRIPTION

These are the slides that I presented at the Effective MySQL Meetup in NYC on Jan 21 2014

Citation preview

Page 1: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Ivan  Zoratti  

MaxScaleMySQL Meetup - EffectiveMySQL

V1401.01

Page 2: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Agenda

•Architecture  

•Jargon  

•Installation  

•Configuration  

•Use  Cases  

•Documentation  and  More  Material

�2

Page 3: MaxScale for Effective MySQL Meetup NYC - 14.01.21

MaxScale  Architecture

Page 4: MaxScale for Effective MySQL Meetup NYC - 14.01.21

MaxScale  -­‐  Objectives

•Highly  Scalable  

•Lightweight,  with  small  footprint  

•Minimum  possible  latency  

•Highly  available  

!

•Extendible  

•Must  provide  authentication  

•Must  be  transparent  to  the  application

�4

Page 5: MaxScale for Effective MySQL Meetup NYC - 14.01.21

MaxScale  Core•Event  driven  network  I/O  processor  

•Polling,  event  driven  mechanism  that  is  responsible  for  dispatching  events  to  the  various  modules  that  make  up  the  MaxScale  application  

•Events  in  MaxScale  =  Network  requests,  such  as:  •Handling  an  incoming  connection  on  a  listener  socket  •Incoming  data  for  a  client  connection  •Data  arriving  on  a  connection  from  a  backend  database  server  •A  socket  error  on  one  of  the  client  or  database  connections  •A  socket  closure  •The  availability  of  connections  to  receive  more  data

�5

Page 6: MaxScale for Effective MySQL Meetup NYC - 14.01.21

MaxScale  Polling

•Linux  epoll  mechanism  to  poll  for  activity  on  the  file  descriptors  

•The  epoll  mechanism  allows  a  file  descriptor  to  be  registered  along  with  some  user  data  •MaxScale  makes  use  of  this  user  data  to  register  a  descriptor  control  block  for  each  descriptor

�6

Page 7: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Descriptor  Control  Block  -­‐  DCB•The  main  source  of  state  information  that  is  used  within  the  event  processing  core  of  MaxScale.  

•On  an  event  occurring  for  a  descriptor  the  corresponding  DCB  is  used  to  determine  how  that  event  should  be  handled.  

•DCB  Members:  •State  -­‐  used  to  determine  where  in  its  lifecycle  the  DCB  currently  is.  

•Func  -­‐  set  of  function  pointers  for  routines  that  are  called  when  particular  events  occur  or  when  MaxScale  wishes  to  perform  certain  operations.  It  allows  MaxScale  to  be  extended  to  support  new  protocols  without  the  need  to  alter  the  MaxScale  core  itself.  •Session  -­‐  a  pointer  to  the  session  to  which  this  connection  belongs.  •Service  -­‐  the  service  that  this  connection  belongs  to.  •Writeq  -­‐  a  pointer  to  a  chain  of  GWBUF  structures  that  contain  data  waiting  to  be  written.  •Delayq  -­‐  similar  to  writeq,  it  buffer  data  that  has  to  be  held  due  to  some  other  activity.

�7

Page 8: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Descriptor  Control  Block  -­‐  DCB

�8

!gw_dcb_state2string (int state) {!! switch(state) {!! ! case DCB_STATE_ALLOC:!! ! ! return "DCB Allocated";!! ! case DCB_STATE_POLLING:!! ! ! return "DCB in the polling loop";!! ! case DCB_STATE_LISTENING:!! ! ! return "DCB for listening socket";!! ! case DCB_STATE_DISCONNECTED:!! ! ! return "DCB socket closed";!! ! case DCB_STATE_FREED:!! ! ! return "DCB memory could be freed";!! ! case DCB_STATE_ZOMBIE:!! ! ! return "DCB Zombie";!! ! default:!! ! ! return "DCB (unknown)";!! }!}

Port: 3307(gdb)

Modules

MaxScale  makes  significant  use  of  moules,  shared  objects,  that  are  loaded  on  demand  basedon  the  configuration.  A  routine  exists  that  will  print  the  currently  loaded  modules.

(gdb)  call  printModules()Module  Name          |  Module  Type  |  Version-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­telnetd                  |  Protocol        |  V1.0.0MySQLClient          |  Protocol        |  V1.0.0testroute              |  Router            |  V1.0.0debugcli                |  Router            |  V1.0.0readconnroute      |  Router            |  V1.0.0(gdb)

Descriptor Control Blocks

The  Descriptor  Control  Block  (DCB)  is  an  important  concept  within  MaxScale  since  it  is  thisblock  that  is  passed  to  the  polling  system,  when  an  event  occurs  it  is  that  structure  that  isavailable  and  from  this  structure  it  must  be  possible  to  navigate  to  all  other  structures  thatcontain  state  regarding  the  session  and  protocol  in  use.

Similar  print  routines  exist  for  the  DCB(gdb)  call  printAllDCBs()DCB:  0x60ead0

DCB  state: DCB  for  listening  socketQueued  write  data: 0Statistics:

Page 9: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Descriptor  Control  Block  -­‐  DCB

�9

!DCB: 0xfb1650!! DCB state: DCB for listening socket!! Service: RW Split Router!! Statistics:!! ! No. of Reads: 0!! ! No. of Writes: 0!! ! No. of Buffered Writes: 0!! ! No. of Accepts: 1324!DCB: 0x1050bc0!! DCB state: DCB for listening socket!! Service: HTTPD Router!! Statistics:!! ! No. of Reads: 0!! ! No. of Writes: 0!! ! No. of Buffered Writes: 0!! ! No. of Accepts: 0!DCB: 0xfae370!! DCB state: DCB for listening socket!! Service: Debug Interface!! Statistics:!! ! No. of Reads: 0!! ! No. of Writes: 0!! ! No. of Buffered Writes: 0!! ! No. of Accepts: 1!DCB: 0x107ff50!! DCB state: DCB in the polling loop!! Service: RW Split Router!! Connected to: 192.168.0.20!! Statistics:!! ! No. of Reads: 3!! ! No. of Writes: 3!! ! No. of Buffered Writes: 0!! ! No. of Accepts: 0

!DCB: 0x10ed970!! DCB state: DCB in the polling loop!! Service: RW Split Router!! Statistics:!! ! No. of Reads: 4!! ! No. of Writes: 3!! ! No. of Buffered Writes: 0!! ! No. of Accepts: 0!DCB: 0x10a0640!! DCB state: DCB in the polling loop!! Service: RW Split Router!! Statistics:!! ! No. of Reads: 3!! ! No. of Writes: 2!! ! No. of Buffered Writes: 0!! ! No. of Accepts: 0!DCB: 0x10a6e40!! DCB state: DCB in the polling loop!! Service: Debug Interface!! Connected to: 127.0.0.1!! Statistics:!! ! No. of Reads: 12!! ! No. of Writes: 205!! ! No. of Buffered Writes: 0!! ! No. of Accepts: 0!

Page 10: MaxScale for Effective MySQL Meetup NYC - 14.01.21

MaxScale  Jargon

Page 11: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Backend  Database

•A  database  that  sits  behind  MaxScale  and  is  accessed  by  applications  via  MaxScale

�11

Page 12: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Module

•A  separate  code  entity  that  may  be  loaded  dynamically  into  MaxScale  to  increase  the  available  functionality.  

•Modules  are  implemented  as  run-­‐time  loadable  shared  objects

�12

!MaxScale> show modules!!Module Name | Module Type | Version!----------------+-------------+---------!MySQLBackend | Protocol | V2.0.0!telnetd | Protocol | V1.0.1!HTTPD | Protocol | V1.0.1!MySQLClient | Protocol | V1.0.0!mysqlmon | Monitor | V1.0.0!readwritesplit | Router | V1.0.2!testroute | Router | V1.0.0!debugcli | Router | V1.0.1

Page 13: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Server

•An  individual  database  server  to  which  a  client  can  be  connected  via  MaxScale

�13

!MaxScale> show servers!Server 0xfae860!! Server: 192.168.0.21!! Status: Master, Running!! Protocol:! ! MySQLBackend!! Port:! ! ! 3306!! Number of connections: 1320!! Current no. of connections:!1!Server 0xfb15c0!! Server: 192.168.0.22!! Status: Slave, Running!! Protocol: MySQLBackend!! Port: 3306!! Number of connections: 298!! Current no. of connections:!0!Server 0xfb1530!! Server: 192.168.0.23!! Status: Slave, Running!! Protocol: MySQLBackend!! Port: 3306!! Number of connections: 365!! Current no. of connections:!0!Server 0xfb14a0!! Server: 192.168.0.24!! Status: Slave, Running!! Protocol: MySQLBackend!! Port: 3306!! Number of connections: 365!! Current no. of connections:!0!Server 0xfb1410!! Server: 192.168.0.25!! Status: Slave, Running!! Protocol: MySQLBackend!! Port: 3306!! Number of connections: 292!! Current no. of connections:!1!MaxScale>

Page 14: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Monitor

•A  module  that  can  be  executed  within  MaxScale  to  monitor  the  state  of  a  set  of  database.  

•The  use  of  an  internal  monitor  is  optional,  monitoring  may  be  performed  externally  to  MaxScale.

�14

!MaxScale> show monitors!Monitor: 0x104ddc0!! Name:! ! MariaDB10 Monitor!! Monitor running!! Monitored servers:!192.168.0.21:3306, 192.168.0.22:3306, 192.168.0.23:3306, 192.168.0.24:3306, 192.168.0.25:3306

Page 15: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Router

•A  module  within  MaxScale  that  will  route  client  request  to  the  various  database  server  which  MaxScale  provides  a  service  interface  to

�15

Page 16: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Connection  Routing

•A  method  of  handling  requests  in  which  MaxScale  will  accept  connections  from  a  client  and  route  data  on  that  connection  to  a  single  database  using  a  single  connection.  

•Connection  based  routing  sets  the  connection  to  a  database  and  it  does  not  examine  requests  on  the  connection.  

•Once  the  connection  with  a  database  is  established,  it  cannot  be  moved.

�16

Page 17: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Statement  Routing

•A  method  of  handling  requests  in  which  each  request  within  a  connection  will  be  handled  individually.  

•Requests  may  be  sent  to  one  or  more  servers  and  connections  may  be  dynamically  added  or  removed  from  the  session.

�17

Page 18: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Protocol

•A  software  module  that  is  used  to  communicate  with  another  software  entity  within  the  system.  

•MaxScale  supports  the  dynamic  loading  of  protocol  modules.

�18

Page 19: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Listener

•The  network  endpoint  that  is  used  to  listen  for  connections  to  MaxScale  from  the  client  applications.  

•A  listener  is  associated  to  a  single  service,  however  a  service  may  have  many  listeners.

�19

Page 20: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Service•MaxScale  offers  a  set  of  services  to  the  clients  

•Each  service  is  a  protocol/port  pair  +  a  query  routing  module  +  backends  •The  protocol  that  should  be  used  •The  port  on  which  to  listen  for  incoming  client  requests  •The  query  routing  module  defines  the  choice  of  backed  server  used  to  execute  the  statement  received  from  the  client  •The  backends  are  the  servers  that  statements  may  be  sent  to  as  part  of  this  service  

•A  service  may  have  more  than  one  protocol/port  associated  with  it

�20

!MaxScale> show services!Service 0x104cd40!! Service:! ! RW Split Router!! Router:! ! ! readwritesplit (0x7ff2a1921d40)!! Number of router sessions: ! 1320!! Current no. of router sessions: ! 1!! Number of queries forwarded: !34308!! Number of queries forwarded to master:!26691!! Number of queries forwarded to slave: !6189!! Number of queries forwarded to all: !1428!! Started:! ! Wed Jan 1 11:15:17 2014!! Backend databases!! ! 192.168.0.25:3306 Protocol: MySQLBackend!! ! 192.168.0.24:3306 Protocol: MySQLBackend!! ! 192.168.0.23:3306 Protocol: MySQLBackend!! ! 192.168.0.22:3306 Protocol: MySQLBackend!! ! 192.168.0.21:3306 Protocol: MySQLBackend!! Users data: ! 0x104dd00!! Total connections:! 1321!! Currently connected:!2!Service 0xfaf380!! Service:! ! HTTPD Router!! Router:! ! ! testroute (0x7ff2a1b277c0)!! Started:! ! Wed Jan 1 11:15:17 2014!! Backend databases!! ! 192.168.0.25:3306 Protocol: MySQLBackend!! ! 192.168.0.24:3306 Protocol: MySQLBackend!! ! 192.168.0.23:3306 Protocol: MySQLBackend!! ! 192.168.0.22:3306 Protocol: MySQLBackend!! ! 192.168.0.21:3306 Protocol: MySQLBackend!! Users data: ! 0xfaf740!! Total connections:! 1!! Currently connected:!1!Service 0xfae8f0!! Service:! ! Debug Interface!! Router:! ! ! debugcli (0x7ff2a1d31500)!! Started:! ! Wed Jan 1 11:15:17 2014!! Backend databases!! Users data: ! 0xfaf1b0!! Total connections:! 2!! Currently connected:!2

Page 21: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Connection  Failover

•When  a  connection  currently  being  used  between  MaxScale  and  the  database  server  fails  a  replacement  will  be  automatically  created  to  another  server  by  MaxScale  without  client  intervention

�21

Page 22: MaxScale for Effective MySQL Meetup NYC - 14.01.21

MaxScale  Installation

Page 23: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Download  &  Unpack

�23

![root@Sky6 ~]# cd![root@Sky6 ~]# curl ftp://ftp.skysql.com/downloads/Dev/maxscale.preview.0.4.tar.gz > maxscale.preview.0.4.tar.gz![root@Sky6 ~]# cd /usr/local![root@Sky6 local]# mkdir skysql![root@Sky6 local]# cd skysql![root@Sky6 skysql]# tar xzvf ~/maxscale.preview.0.4.tar.gz!…![root@Sky6 skysql]# ls -l!…!drwxr-xr-x 6 10045 2000 4096 Dec 16 18:14 maxscale!…![root@Sky6 skysql]# ls -l maxscale!total 48!drwxr-xr-x 2 10045 2000 4096 Dec 16 15:18 bin!-rw-r--r-- 1 10045 2000 754 Dec 16 17:56 COPYRIGHT!drwxr-xr-x 2 10045 2000 4096 Dec 16 16:43 Documentation!drwxr-xr-x 2 10045 2000 4096 Dec 16 16:24 lib!-rw-r--r-- 1 10045 2000 18011 Dec 16 17:56 LICENSE!drwxr-xr-x 6 10045 2000 4096 Dec 16 16:38 MaxScale!-rw-r--r-- 1 10045 2000 30 Dec 16 16:26 my.cnf!-rw-r--r-- 1 10045 2000 1542 Dec 16 18:13 SETUP

CheckMaxScale  Configuraeon  And  Usage  Scenarios.pdf

Page 24: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Start  MaxScale

�24

![root@Sky6 ~]# /usr/local/skysql/maxscale/bin/maxscale -h!!SkySQL MaxScale! Tue Dec 31 17:34:59 2013!------------------------------------------------------!*!* Usage : maxscale [-h] | [-d] [-c <home directory>] [-f <config file name>]!* where:!* -h help!* -d enable running in terminal process (default:disabled)!* -c relative|absolute MaxScale home directory!* -f relative|absolute pathname of MaxScale configuration file (default:MAXSCALE_HOME/etc/MaxScale.cnf)!*

Page 25: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Set  the  Environment  Variables  and  Start  MaxScale

�25

![root@Sky6 ~]# MAXSCALE_HOME=/usr/local/skysql/maxscale/MaxScale![root@Sky6 ~]# LD_LIBRARY_PATH=/usr/local/skysql/maxscale/lib![root@Sky6 ~]# /usr/local/skysql/maxscale/bin/maxscale!!!SkySQL MaxScale! Tue Dec 31 14:59:16 2013!------------------------------------------------------!Info : MaxScale will be run in a daemon process.!! See the log from the following log files :!!Error log :! /usr/local/skysql/maxscale/MaxScale/log/skygw_err1.log!Message log :! /usr/local/skysql/maxscale/MaxScale/log/skygw_msg1.log!Trace log :! /usr/local/skysql/maxscale/MaxScale/log/skygw_trace1.log!Debug log :! /usr/local/skysql/maxscale/MaxScale/log/skygw_debug1.log!!Listening MySQL connections at 0.0.0.0:4004!Listening http connections at 0.0.0.0:6444!Listening telnet connections at 0.0.0.0:4444

…or  create  a  3  lines  script

Page 26: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Checking  MaxScale

�26

![root@Sky6 ~]# telnet localhost 4444!Trying ::1...!telnet: connect to address ::1: Connection refused!Trying 127.0.0.1...!Connected to localhost.!Escape character is '^]'.!Welcome the SkySQL MaxScale Debug Interface (V1.0.1).!Type help for a list of available commands.!!MaxScale login: admin!Password:!!MaxScale>

UID/PWD:  admin  /  skysql

!MaxScale> help!Available commands:! add user! clear server! remove user! restart monitor! restart service! set server! show dcbs! show dcb! show dbusers! show epoll! show modules! show monitors! show server! show servers! show services! show session! show sessions! show users! shutdown maxscale! shutdown monitor! shutdown service! reload config! reload dbusers! enable log! disable log

Page 27: MaxScale for Effective MySQL Meetup NYC - 14.01.21

MaxScale  Configuration

Page 28: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Configuration  Template

�28

![root@Sky6 etc]# cat MaxScale_template.cnf!#!# Example MaxScale.cnf configuration file!#!# Number of server threads!# Valid options are:!# !threads=<number of threads>!![maxscale]!threads=1!…!![Monitor Module]!…!![R/W Split Module]!…!![Read Connection Router]!…!![HTTPD Router]!…!![Debug Interface]!…

!# Listener definitions for the services!#!# Valid options are:!#!# !service=<name of service defined elsewhere>!# !protocol=<name of protocol module with which to listen>!# !port=<Listening port>!![RW Split Listener]!…!![Read Connection Listener]!…!![Debug Listener]!…!![HTTPD Listener]!…!!# Definition of the servers!![server1]!…!![serverN]!…

Page 29: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Database  Settings

•Create  a  valid  MaxScale  user  •Allow  access  from  the  MaxScale  node

�29

!MariaDB [test]> create user maxuser identified by 'maxpwd';!Query OK, 0 rows affected (0.01 sec)!!MariaDB [test]> grant all on *.* to maxuser@‘192.168.0.26’;!Query OK, 0 rows affected (0.00 sec)

Page 30: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Global  Settings

•Settings  used  to  configure  the  core  of  MaxScale  

•Options:  •threads  -­‐  number  of  user  threads  that  poll  for  network  traffic  •Start  with  the  smallest  number  and  try  to  increase  to  check  the  impact  on  high  workload  

•This  parameter  does  not  include  the  number  of  “internal  threads”  

�30

![maxscale]!threads=1!

Page 31: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Server  Settings

•Settings  used  to  configure  the  backend  •type  -­‐  the  server  type  

•Options:  •address  -­‐  The  IP  address  used  by  MaxScale  to  connect  to  the  server  •port  -­‐  The  TCP  port  used  by  MaxScale  to  connect  to  the  server  •Protocol  -­‐  The  DB  protocol.  

•MySQLBackend  is  the  native  MySQL  protocol  •MonitorUser  -­‐  The  DB  user  used  by  MaxScale  to  connect  with  the  Monitoring  module  •When  MonitorUser  is  not  present,  MaxScale  uses  the  credentials  set  in  the  Monitor  section  

•MonitorPW  -­‐  The  DB  user  password

�31

![max1]!type=server!address=192.168.0.21!port=3006!protocol=MySQLBackend!![max2]!type=server!address=192.168.0.22!port=3006!protocol=MySQLBackend!!…!![max5]!type=server!address=192.168.0.25!port=3006!protocol=MySQLBackend

Page 32: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Monitor  Settings

•Settings  used  to  configure  the  monitor  module  for  MySQL/MariaDB  •type  -­‐  the  monitor  type  

•Options:  •module  -­‐  The  loadable  module,  mysqlmon  for  MySQL/MariaDB  •servers  -­‐  Comma  separated  list  of  the  servers  to  monitor  

•Servers  must  be  of  the  same  type  (e.g.  MySQL/MariaDB  servers)  •user  -­‐  DB  user  used  to  connect  to  the  server  

•Used  when  the  credentials  are  not  available  in  the  server  section  •passwd  -­‐  DB  user  password

�32

![MariaDB10 Monitor]!type=monitor!module=mysqlmon!servers=max1,! max2,! max3,! max4,! max5!user=maxuser!passwd=maxpwd

Page 33: MaxScale for Effective MySQL Meetup NYC - 14.01.21

SLB  with  Read/Write  Split  Service  Settings

•Settings  used  to  configure  the  service  module  for  statement-­‐based  load  balancing  (with  read/write  splitting)  •type  -­‐  the  service  type  

•Options:  •router  -­‐  The  loadable  module,  readwritesplit  for  MySQL/MariaDB  R/W  splitting  with  MySQL  Replication  •servers  -­‐  Comma  separated  list  of  the  servers  to  monitor  •user  -­‐  DB  user  used  to  connect  to  the  server  to  extract  the  list  of  the  database  users  to  allow  local  authentication  •passwd  -­‐  DB  user  password

�33

![RW Split Router]!type=service!router=readwritesplit!servers=max1,! max2,! max3,! max4,! max5 !user=maxuser!passwd=maxpwd

Page 34: MaxScale for Effective MySQL Meetup NYC - 14.01.21

CLB  Service  Settings•Settings  used  to  configure  the  service  module  for  statement-­‐based  load  balancing  (with  read/write  splitting)  •type  -­‐  the  service  type  

•Options:  •router  -­‐  The  loadable  module,  readconnroute  for  connection  load  balancing  with  MySQL  Replication  •router_options  -­‐  options  passed  to  the  module.  

•slave  means  that  the  load  balancing  is  applied  only  to  the  slave  servers  •master,slave  means  that  the  load  balancing  is  applied  master  and  slave  servers  

•servers  -­‐  Comma  separated  list  of  the  servers  to  monitor  •user  -­‐  DB  user  used  to  connect  to  the  server  to  extract  the  list  of  the  database  users  to  allow  local  authentication  •passwd  -­‐  DB  user  password

�34

![Read Connection Router]!type=service!router=readconnroute!router_options=slave!servers=max1,! max2,! max3,! max4,! max5!user=maxuser!passwd=maxpwd

Page 35: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Listener  Settings  -­‐  SLB

•Set  the  Protocol  and  Service  pair.  This  is  used  to  offer  the  SLB  with  Read/Write  Splitting  •type  -­‐  the  listener  type  

•Options:  •service  -­‐  The  service  associated  to  the  listener  (e.g.  RW  Split  Router)  •protocol  -­‐  The  protocol  paired  to  the  service  (e.g.  MySQLClient)  •port  -­‐  The  TCP  port  used  to  listen  to  the  client  requests

�35

![RW Split Listener]!type=listener!service=RW Split Router!protocol=MySQLClient!port=4006!

Page 36: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Listener  Settings  -­‐  Debug  &  HTTP

•These  listeners  are  used  to  offer  a  debug  and  a  HTTP  interface  to  MaxScale  •type  -­‐  the  listener  type  

•Options:  •service  -­‐  DBAs  can  connect  to  MaxScale  using  telnet  or  via  a  restful  API  •protocol  -­‐  The  protocol  paired  to  the  service  (e.g.  telnetd  and  httpd  )  •port  -­‐  The  TCP  port  used  to  listen  to  the  client  requests

�36

![Debug Listener]!type=listener!service=Debug Interface!protocol=telnetd!port=4444!![HTTPD Listener]!type=listener!service=HTTPD Router!protocol=HTTPD!port=6444

Page 37: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Final  Configuration

�37

![root@Sky6 etc]# cat MaxScale.cnf!#!# Number of server threads!# Valid options are:!# !threads=<number of threads>![maxscale]!threads=1!!#!# Define a monitor that can be used to determine the state!# and role of the servers.!#!# Valid options are:!#!# !module=<name of module to load>!# !servers=<server name>,<server name>,...!# !user =<user name - must have slave replication and!# slave client privileges>!# !passwd=<password of the above user, # plain text currently>![MariaDB10 Monitor]!type=monitor!module=mysqlmon!servers=max1,max2,max3,max4,max5!user=maxuser!passwd=maxpwd

!#!# A series of service definition!#!# Valid options are:!#!# !router=<name of router module>!# !servers=<server name>,<server name>,...!# !user=<User to fetch password inforamtion with>!# !passwd=<Password of the user, plain text currently>!#!# Valid router modules currently are:!# !readwritesplit, readconnroute and debugcli![RW Split Router]!type=service!router=readwritesplit!servers=max1,max2,max3,max4,max5!user=maxuser!passwd=maxpwd!![HTTPD Router]!type=service!router=testroute!servers=max1,max2,max3,max4,max5!![Debug Interface]!type=service!router=debugcli

Page 38: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Final  Configuration

�38

!#!# Listener definitions for the services!#!# Valid options are:!#!# !service=<name of service defined elsewhere>!# !protocol=<name of protocol module with which to listen>!# !port=<Listening port>![RW Split Listener]!type=listener!service=RW Split Router!protocol=MySQLClient!port=4004!![Debug Listener]!type=listener!service=Debug Interface!protocol=telnetd!port=4444!![HTTPD Listener]!type=listener!service=HTTPD Router!protocol=HTTPD!port=6444!

!# Servers Definition![max1]!type=server!address=192.168.0.21!port=3306!protocol=MySQLBackend!![max2]!type=server!address=192.168.0.22!port=3306!protocol=MySQLBackend!![max3]!type=server!address=192.168.0.23!port=3306!protocol=MySQLBackend!![max4]!type=server!address=192.168.0.24!port=3306!protocol=MySQLBackend!![max5]!type=server!address=192.168.0.25!port=3306!protocol=MySQLBackend

Page 39: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Password  Encryption

•Used  to  remove  plain  password  from  the  config  file  

•Passwords  are  stored  in  a  readonly  file  (default  $MAXSCALE_HOME/etc/.secrets)  

•Plain  passwords  in  the  config  file  can  be  replaced  with  the  encrypted  password

�39

![root@Sky6 ~]# /usr/local/skysql/maxscale/bin/maxkeys /usr/local/skysql/maxscale/MaxScale/etc/.secrets!![root@Sky6 ~]# MAXSCALE_HOME=/usr/local/skysql/maxscale/MaxScale![root@Sky6 ~]# /usr/local/skysql/maxscale/bin/maxpasswd maxpwd!14AE17C29AE7E6DB94EA5E6068D9833D!![root@Sky6 ~]# vi /usr/local/skysql/maxscale/MaxScale/etc/MaxScale.cnf!!…![MariaDB10 Monitor]!type=monitor!module=mysqlmon!servers=max1,max2,max3,max4,max5!user=maxuser!passwd=14AE17C29AE7E6DB94EA5E6068D9833D!…

Page 40: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Checking  MaxScale

�40

!MaxScale> show services!Service 0x8e1d40!! Service:! ! RW Split Router!! Router:! ! ! readwritesplit (0x7ff7dd4d0d40)!! Number of router sessions: ! 0!! Current no. of router sessions: ! 0!! Number of queries forwarded: ! 0!! Number of queries forwarded to master:! 0!! Number of queries forwarded to slave: ! 0!! Number of queries forwarded to all: ! 0!! Started:! ! Tue Dec 31 17:36:13 2013!! Backend databases!! ! 192.168.0.25:3006 Protocol: MySQLBackend!! ! 192.168.0.24:3006 Protocol: MySQLBackend!! ! 192.168.0.23:3006 Protocol: MySQLBackend!! ! 192.168.0.22:3006 Protocol: MySQLBackend!! ! 192.168.0.21:3006 Protocol: MySQLBackend!! Users data: !0x8e2d00!! Total connections:! 1!! Currently connected:! 1!Service 0x844380!! Service:! ! HTTPD Router!! Router:! ! ! testroute (0x7ff7dd6d67c0)!! Started:! ! Tue Dec 31 17:36:13 2013!! Backend databases!! ! 192.168.0.25:3006 Protocol: MySQLBackend!! ! 192.168.0.24:3006 Protocol: MySQLBackend!! ! 192.168.0.23:3006 Protocol: MySQLBackend!! ! 192.168.0.22:3006 Protocol: MySQLBackend!! ! 192.168.0.21:3006 Protocol: MySQLBackend!! Users data: !0x844740!! Total connections:! 1!! Currently connected:! 1!Service 0x8438f0!! Service:! ! Debug Interface!! Router:! ! ! debugcli (0x7ff7dd8e0500)!! Started:! ! Tue Dec 31 17:36:13 2013!! Backend databases!! Users data: !0x8441b0!! Total connections:! 2!! Currently connected:! 2

SLB  R/W  Splimer  (for  the  users)

RESTful  API  (under  development)

Telnet  Interface  (for  debugging  and  DBAs)

Page 41: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Troubleshooting

�41

!2013 12/31 17:47:24 Error : access for secrets file [/usr/local/skysql/maxscale/MaxScale/etc/.secrets] failed. Error 2, No such file or directory.

MaxScale  cannot  fine  the  encrypted  password  file

![root@Sky6 bin]# /usr/local/skysql/maxscale/MaxScale/bin/maxkeys /usr/local/skysql/maxscale/MaxScale/etc/.secrets!

Page 42: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Troubleshooting

�42

![root@Sky0 ~]# mysql -uroot -h 192.168.0.26 -P4004 -p!Enter password:!ERROR 1045 (2800): Authorization failed![root@Sky0 ~]#

!<<<< User [root] was not found!<<< CLIENT AUTH FAILED for user [root]!

root  is  not  loaded  to  the  available  users  to  connect  via  MaxScale

![root@Sky0 ~]# mysql -umaxuser -h 192.168.0.26 -P4004 -pmaxpwd!Welcome to the MariaDB monitor. Commands end with ; or \g.!Your MySQL connection id is 1535!Server version: 5.5.22-SKYSQL-0.1.0 MariaDB Server!!Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.!!Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.!!MySQL [(none)]>

Careful  with  this!

Page 43: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Troubleshooting

�43

!MySQL [(none)]> show processlist;!+-----+---------+-------------------+------+-------------+-------+----------------------------------------+------------------+----------+!| Id | User | Host | db | Command | Time | State | Info | Progress |!+-----+---------+-------------------+------+-------------+-------+----------------------------------------+------------------+----------+!| 5 | root | skycluster3:33830 | NULL | Binlog Dump | 82453 | Master has sent all binlog to slave; … | NULL | 0.000 |!| 6 | root | skycluster4:43403 | NULL | Binlog Dump | 82389 | Master has sent all binlog to slave; … | NULL | 0.000 |!| 7 | root | skycluster5:46878 | NULL | Binlog Dump | 82382 | Master has sent all binlog to slave; … | NULL | 0.000 |!| 8 | root | skycluster2:54912 | NULL | Binlog Dump | 82376 | Master has sent all binlog to slave; … | NULL | 0.000 |!| 100 | root | skycluster0:41977 | NULL | Sleep | 0 | | NULL | 0.000 |!| 101 | root | skycluster0:41997 | NULL | Sleep | 60 | | NULL | 0.000 |!| 129 | maxuser | skycluster6:55557 | NULL | Sleep | 5 | | NULL | 0.000 |!| 132 | maxuser | skycluster6:55565 | NULL | Query | 0 | init | show processlist | 0.000 |!| 135 | maxuser | skycluster6:55571 | NULL | Sleep | 41 | | NULL | 0.000 |!+-----+---------+-------------------+------+-------------+-------+----------------------------------------+------------------+----------+!9 rows in set (0.00 sec)

!MariaDB [(none)]> show processlist;!+----+-------------+-------------------+------+---------+-------+----------------------------------+------------------+----------+!| Id | User | Host | db | Command | Time | State | Info | Progress |!+----+-------------+-------------------+------+---------+-------+----------------------------------+------------------+----------+!| 4 | system user | | NULL | Connect | 82804 | Waiting for master to send event | NULL | 0.000 |!| 5 | system user | | NULL | Connect | 73387 | Slave has read all relay log; wa…| NULL | 0.000 |!| 14 | root | skycluster0:35933 | NULL | Sleep | 0 | | NULL | 0.000 |!| 15 | root | skycluster0:35936 | NULL | Sleep | 216 | | NULL | 0.000 |!| 44 | maxuser | skycluster6:46518 | NULL | Sleep | 3 | | NULL | 0.000 |!| 46 | root | localhost | NULL | Query | 0 | init | show processlist | 0.000 |!+----+-------------+-------------------+------+---------+-------+----------------------------------+------------------+----------+!6 rows in set (0.00 sec)

From  MaxScaleYou  see  the  Max1  process  list

This  is  directly  from  Max2

Page 44: MaxScale for Effective MySQL Meetup NYC - 14.01.21

MaxScale  Use  Caseswith  the  current  version

Page 45: MaxScale for Effective MySQL Meetup NYC - 14.01.21

MaxScale  with  MySQL  Replicationusing  Connection  Load  Balancing

�45

DatabaseDatabase Database Database Database

MaxScale Each  applicaeon  server  uses  2  conneceon:1  Read/Write,  1  Read/Only

For  applicaLons  that  are  “ReplicaLon  aware”,  i.e.  they  can  use  2  connecLons,  one  for  the  master  and  one  for  the  slave  servers

MaxScale  connects  the  R/W  client  conneceon  to  the  master  and  it  load  balances  the  R/O  client  conneceon  to  

one  of  the  slaves

Conneceon  load  balancing  is  fast,  lightweight  and  it  provides  high  availability

MHA  provides  the  automaec  failover  in  case  of  fault  of  the  master

Page 46: MaxScale for Effective MySQL Meetup NYC - 14.01.21

MaxScale  with  MySQL  Replicationusing  Connection  Load  Balancing

�46

DatabaseDatabase Database Database Database

MaxScale

[Read Service] type=service router=readconnroute router_options=slave servers=s1,s2,s3,s4,s5 user=maxuser auth=maxpwd

[Read Listener] type=listener service=Read Service protocol=MySQLClient port=4006

[Write Listener] type=listener service=Write Service protocol=MySQLClient port=4007

[Write Service] type=service router=readconnroute router_options=master servers=s1,s2,s3,s4,s5 user=maxuser auth=maxpwd

Page 47: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Database Database Database

MaxScale

MaxScale  with  Galerausing  Connection  Load  Balancing

�47

For  applicaLons  that  can  use  the“all-­‐master”  capabiliLes  of  Galera

MaxScale  load  balances  the  client  conneceons  to  the  Galera  nodes

MaxScale  monitors  the  state  of  each  Galera  Cluster  and  it  applies  load  balancing  only  on  synced    nodes

Each  applicaeon  server  uses  only  1  conneceon

Page 48: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Database Database Database

MaxScale

MaxScale  with  Galerausing  Connection  Load  Balancing

�48

[Read Listener] type=listener service=Read Service protocol=MySQLClient port=4006

[Galera Service] type=service router=readconnroute router_options=synced servers=s1,s2,s3,s4,s5 user=maxuser auth=maxpwd

Page 49: MaxScale for Effective MySQL Meetup NYC - 14.01.21

DatabaseDatabase Database Database Database

MaxScale

MaxScale  with  MySQL  Replicationusing  Read/Write  Splitting

�49

For  applicaLons  that  have  been  designed  to  work  with  a  single  server  

and  require  read  scalability

MaxScale  creates  2  conneceons,  one  for  R/W  on  the  master  node  and  one  R/O  load  balanced  on  the  slave    nodes

MaxScale  monitors  the  state  of  each  node  and  it  applies  load  balancing  

only  on  the  available  slaves

Each  applicaeon  server  uses  only  1  conneceon

Page 50: MaxScale for Effective MySQL Meetup NYC - 14.01.21

How  does  MaxScale  compare  to…

•HA  Proxy  

•MySQL  Proxy  

•Sharding  solutions  -­‐  ScaleBase,  DBShards,  Parelastic,  etc.

�50

Page 51: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Strictly  Confidential    -­‐  SkySQL  Internal  Use  Only

JSON  over  http  and  BSON

�51

Page 52: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Strictly  Confidential    -­‐  SkySQL  Internal  Use  Only

NDB  API

�52

Page 53: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Where  To  Find  More  Material

�53

GitHub  Project h"ps://github.com/skysql/MaxScale

Tarball h"ps://downloads.skysql.com/files/SkySQL/MaxScale

Documentaeon h"ps://github.com/skysql/MaxScale/tree/master/DocumentaAon

Page 54: MaxScale for Effective MySQL Meetup NYC - 14.01.21

Thank  You!

www.skysql.com