SlideShare a Scribd company logo
Copyright 2017 Severalnines AB
Krzysztof Książek, Senior Support Engineer @Severalnines
krzysztof@severalnines.com
Presenter
MySQL Load Balancers - MaxScale,
ProxySQL, HAProxy, MySQL Router &
nginx - a close up look
April, 26th 2017
Copyright 2017 Severalnines AB
Why load balancers?
Types of load balancers
•Application connectors
•Reverse proxies
•SQL-aware proxies
Health checks used with proxies
Agenda
Copyright 2017 Severalnines AB
High availability
•Detect node health
•Route traffic away from failed nodes
Performance
•Scale out by routing traffic to multiple
nodes
•Minimize number of connections to
databases
Why load balancers?
Keep complexity away from the application
•Monitor node state
•Understand replication topology
•Failover client connections
Additional features
•Collect performance data from cluster
•Rewrite queries as they pass the proxy
•Route queries depending on some rules
(e.g. Read/write split)
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Application connectors
Copyright 2017 Severalnines AB
mysqlnd_ms
Native driver for MySQL in PHP
•Default since PHP 5.4
mysqlnd_ms adds option to implement
read/write split and load balancing to PHP
application
Supports failover handling
Supports query routing modifications
through SQL hints
Application connectors
MySQL Connector/J
Adds great deal of flexibility to Java
applications when it comes to database
layer handling
Failover handling
Live reconfiguration of replication topology
Advanced routing options
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Reverse proxies
Copyright 2017 Severalnines AB
Industry standard - thousands of
installations across the world
1.7 released in November, 2016
•1.7.5 released on April, 3rd, 2017
Reverse proxies - HAProxy
Reverse proxy
•Load balancing, scaling out, failover
•Lack of advanced internal support for

MySQL backends
Copyright 2017 Severalnines AB
Lack of ability to perform read/write split on
a single port
•Two backends on two different ports are
required
•Could be a blocker if an application can’t
split reads from writes
Reverse proxies - HAProxy
No understanding of MySQL state
•Only simple check on port 3306:
handshake or authentication
Workaround exists: clustercheck
•HTTP check, xinetd, external script to
monitor MySQL/Galera states
Copyright 2017 Severalnines AB
Reverse proxies - HAProxy
Copyright 2017 Severalnines AB
Designed to detect failed nodes and move VIP around
One single VIP for connections, no load balancing is possible
•Might be useful to build high availability if you connect only to a single node
Potential use cases:
•Galera cluster (for HA only)
•Master - standby replication
•pair of hosts connected through DRBD
Reverse proxies - Keepalived
Copyright 2017 Severalnines AB
Example config for Galera cluster of three
nodes
•Keepalived should be installed on all
hosts
•All hosts should be using this
configuration
Leverage mysqlchk script deployed by
ClusterControl
•Percona’s clustercheck can also be used
Can also be configured to use multicast
Reverse proxies - Keepalived
Copyright 2017 Severalnines AB
A HTTP server and a HTTP reverse proxy
Since 1.9 can be used as a TCP reverse proxy
Limited features in free (NGINX) version
•No configurable port for health checks
•Not possible to integrate with clustercheck
scripts
More features in paid (NGINX Plus) version
•Advanced health checks
•Custom port for checking the health of the
backend
Reverse proxies - NGINX
Copyright 2017 Severalnines AB
Functionality similar to HAProxy (with regards to
MySQL)
•Read/write split could be done using two ports
•Backup servers work differently though - all at once
•No understanding of MySQL and Galera states
Has to be used with clustercheck-iptables
Reverse proxies - NGINX
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
SQL-aware proxies - MaxScale
Copyright 2017 Severalnines AB
Created by MariaDB Corporation, currently
in version 2.0.5 (2.1 in beta)
Tool designed to solve load balancing
needs of DBA’s
•Handles read/write split
•Automatically tracks health of backend
nodes
•Understands MySQL and Galera states
•Master or slave? Synced or donor?
SQL-aware proxies - MaxScale
Copyright 2017 Severalnines AB
Support for SSL
Support for replication, Galera and MySQL
Cluster
Statement hinting
•Where to route
•Maximum replication lag
Nagios integration
Query mirroring
SQL-aware proxies - MaxScale
Caching mechanism (in 2.1)
Result set masking (in 2.1)
Result set limiting (in 2.1)
Consistent Critical Reads (in 2.1)
Copyright 2017 Severalnines AB
Several types of routers are available:
•readwritesplit - performs read/write split
•readconnroute - round-robin access
•dbfwfilter - filters queries based on regex
•schemarouter - implements schema-
based sharding
•binlogrouter - MaxScale as a binlog
server
•avrorouter - saves binlogs in Avro file
SQL-aware proxies - MaxScale
Design decisions
•Read queries are routed to master if
executed within a transaction
•Stored procedures, UDF’s, prepared
statements are sent to the master only
•Session variables and settings are sent to
all hosts
•No connection multiplexing
Copyright 2017 Severalnines AB
Lack of real-time traffic statistics (slightly
improved in 2.1)
No remote admin interface (available in
1.4.x, removed in 2.0)
Most of configuration settings require restart
(improved in 2.1)
Lack of more advanced routing
configuration
•Route to master or slave, using hints
•No regex-based routing
SQL-aware proxies - MaxScale
Serious scalability issues with more than 100
concurrent threads running
•Based on Vadim Tkachenko’s blog post from
May 12, 2016 who tested it on MaxScale 1.4.1
Performance regression when using more than 8
threads for MaxScale (from the blog post as
stated above)
 Non-GPL license starting from 2.0
•Up to two nodes free (more - paid)
•GPL fork of 1.3 branch - AirBnB MaxScale
Copyright 2017 Severalnines AB
SQL-aware proxies - MaxScale
Copyright 2017 Severalnines AB
SQL-aware proxies - MaxScale
Copyright 2017 Severalnines AB
SQL-aware proxies - MaxScale
Copyright 2017 Severalnines AB
320 connections:
SQL-aware proxies - MaxScale
16 connections:
200 connections:
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
SQL-aware proxies - ProxySQL
Copyright 2017 Severalnines AB
Created by René Cannaò, currently in
version 1.3.6 (1.4 announced as beta)
Designed to handle complex topologies
•Implements read write split
•Support for multiple hostgroups
•Tracks health of backends on per-query
basis
•Advanced routing based on query rules
SQL-aware proxies - ProxySQL
Copyright 2017 Severalnines AB
Admin interface uses SQL
•INSERT INTO mysql_servers …
•SET mysql-query_retries_on_failure=…;
Cisco-like configuration approach
•LOAD MYSQL QUERY RULES TO
RUNTIME;
•SAVE MYSQL USERS TO DISK;
Virtually every setting can be changed
dynamically
SQL-aware proxies - ProxySQL
Query rules mechanism for great flexibility
•Match queries using regex, digest hash,
user, schema, IP, port
•Route queries based on above
conditions
•Query rewrite and query mirroring
•Query caching - TTL and memory limit
Copyright 2017 Severalnines AB
Connection multiplexing - minimizes number of
connections to backends
Support for MySQL replication and Group
Replication (in 1.4)
Support for Galera Cluster using external scripts
•Example monitoring script is provided with the
ProxySQL
SQL-aware proxies - ProxySQL
Non-standard approach to backend health
monitoring
•Health check happens when traffic is sent
•Monitor module extends functionality
Detailed statistics about traffic handled by

the ProxySQL
Copyright 2017 Severalnines AB
No client side SSL support - in the roadmap
Lack of out-of-the-box support for explicit
transactions
•You have to either use SET autocommit=0
•Or enable persistent transactions for app
user
Session variables are tricky to support
•You have to make sure they are routed to
a single, writable node (i.e. replication
master)
SQL-aware proxies - ProxySQL
Lack of direct nagios integration
Lack of internal support for Galera
•Although support via external script gives
you more options for customization
No advanced logging options (JSON,
Kafka)
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
SQL-aware proxies - MySQL Router
Copyright 2017 Severalnines AB
Created by Oracle, currently in version
2.1.3
Designed to provide high availability and
scalability to your MySQL backends
Supports external plugins using MySQL
Harness
Integrates well with MySQL Fabric for high
availability setups
Used as a part of MySQL InnoDB Cluster
SQL-aware proxies - MySQL Router
Copyright 2017 Severalnines AB
Two modes for routing
•read-only - read-only connections routed
in round-robin fashion
•read-write - read-write connections
routed to the first working node from the
list
Support for MySQL Fabric:
•Can route traffic to given HA group
•Topology detection via Fabric
SQL-aware proxies - MySQL Router
Copyright 2017 Severalnines AB
Support for MySQL InnoDB Cluster - a solution based on MySQL group replication
•Deployable via MySQL Shell
•Provides a support for InnoDB Cluster Metadata Schema
•Caches metadata of the InnoDB Cluster and improves high availability
SQL-aware proxies - MySQL Router
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Health checks used with proxies
Copyright 2017 Severalnines AB
HTTP check for HAProxy
•Will work with any other proxy which
supports http checks on custom port
Script itself is a bash script which checks
MySQL status
•Designed for Galera but can be easily
modified to use with replication
•Checks wsrep_local_state for Galera
states
•Configurable Donor/Desync state handling
Health checks used with proxies - clustercheck
Script returns HTTP codes
•HTTP/1.1 200 OK - if node is available
•HTTP/1.1 503 Service Unavailable -
otherwise
Clustercheck should be installed on all
databases nodes
•It’s executed by xinetd, listening on
custom port (9200 by default)
•Make sure to configure it in /etc/services
Copyright 2017 Severalnines AB
By default, script is executed directly from
xinetd
•Could become a problem if it’s executed
too often
Numerous forks are available out there
•One of nice modifications was to execute
script via cron and store result in shared
memory
•xinetd executes another script which reads
the status - minimizing impact on MySQL
Health checks used with proxies - clustercheck
Copyright 2017 Severalnines AB
Derived from Percona’s clustercheck
Created by Severalnines’ Ashraf Sharif
Designed to work with proxies which can
do only simple check on port used for
service
•For example, NGINX
Idea is simple - use iptables to open or
close port, depending on node’s state
Health checks used with proxies - clustercheck-iptables
Run script in a background, as a daemon
Setup redirection from port 3308 to port
3306 in PREROUTING chain
Every second checks the state of a node
•If node is deemed unhealthy, remove
redirection rule from PREROUTING chain
Similar approach to health detection as in
Percona’s clustercheck
•Checks wsrep_local_state for Galera
states
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Summary
Copyright 2017 Severalnines AB
Great deal of options to pick from
•Everyone can choose a suitable solution
Do you use NGINX in your setup? Why not to
leverage your knowledge of it and use it for
databases too?
•You’d need clustercheck-iptables or NGINX
Plus, though
Do you want to build all database handling logic in
your application?
•PHP and Java give you great opportunities for
that
Summary
Or maybe you prefer to move complexity of
database layer from the application?
•MaxScale or ProxySQL is there for you
Maybe you want to use advanced features
like query rewriting or sharding?
•Again, ProxySQL or MaxScale will work
great for you
Do you work with MySQL Fabric or MySQL
InnoDB Cluster and want some integration?
•MySQL Router could be a great choice
Copyright 2012 Severalnines AB
Thank You!
Contact: krzysztof@severalnines.com
Q&A

More Related Content

PDF
ProxySQL High Avalability and Configuration Management Overview
René Cannaò
 
PPTX
ProxySQL for MySQL
Mydbops
 
PDF
Galera cluster for high availability
Mydbops
 
PDF
HandsOn ProxySQL Tutorial - PLSC18
Derek Downey
 
PDF
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
Kenny Gryp
 
PPTX
MySQL8.0_performance_schema.pptx
NeoClova
 
PDF
MySQL/MariaDB Proxy Software Test
I Goo Lee
 
PDF
MariaDB Performance Tuning and Optimization
MariaDB plc
 
ProxySQL High Avalability and Configuration Management Overview
René Cannaò
 
ProxySQL for MySQL
Mydbops
 
Galera cluster for high availability
Mydbops
 
HandsOn ProxySQL Tutorial - PLSC18
Derek Downey
 
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
Kenny Gryp
 
MySQL8.0_performance_schema.pptx
NeoClova
 
MySQL/MariaDB Proxy Software Test
I Goo Lee
 
MariaDB Performance Tuning and Optimization
MariaDB plc
 

What's hot (20)

PPTX
Introduction to Redis
Maarten Smeets
 
PPTX
Maria db 이중화구성_고민하기
NeoClova
 
PPTX
Query logging with proxysql
YoungHeon (Roy) Kim
 
PPTX
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
Amit Aggarwal
 
PDF
M|18 Architectural Overview: MariaDB MaxScale
MariaDB plc
 
PDF
RocksDB Performance and Reliability Practices
Yoshinori Matsunobu
 
PDF
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
Altinity Ltd
 
PPTX
Introduction to Redis
Arnab Mitra
 
PPTX
How to build a streaming Lakehouse with Flink, Kafka, and Hudi
Flink Forward
 
PDF
Planning for Disaster Recovery (DR) with Galera Cluster
Codership Oy - Creators of Galera Cluster
 
PDF
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
Jean-François Gagné
 
PDF
eBPF - Observability In Deep
Mydbops
 
PDF
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
Kenny Gryp
 
PDF
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Mydbops
 
PDF
Cassandra Introduction & Features
DataStax Academy
 
PDF
MySQL Shell for DBAs
Frederic Descamps
 
PDF
MySQL Administrator 2021 - 네오클로바
NeoClova
 
PPTX
Introduction to Kafka Cruise Control
Jiangjie Qin
 
PPTX
Kafka at Peak Performance
Todd Palino
 
PDF
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
Jesmar Cannao'
 
Introduction to Redis
Maarten Smeets
 
Maria db 이중화구성_고민하기
NeoClova
 
Query logging with proxysql
YoungHeon (Roy) Kim
 
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
Amit Aggarwal
 
M|18 Architectural Overview: MariaDB MaxScale
MariaDB plc
 
RocksDB Performance and Reliability Practices
Yoshinori Matsunobu
 
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
Altinity Ltd
 
Introduction to Redis
Arnab Mitra
 
How to build a streaming Lakehouse with Flink, Kafka, and Hudi
Flink Forward
 
Planning for Disaster Recovery (DR) with Galera Cluster
Codership Oy - Creators of Galera Cluster
 
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
Jean-François Gagné
 
eBPF - Observability In Deep
Mydbops
 
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
Kenny Gryp
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Mydbops
 
Cassandra Introduction & Features
DataStax Academy
 
MySQL Shell for DBAs
Frederic Descamps
 
MySQL Administrator 2021 - 네오클로바
NeoClova
 
Introduction to Kafka Cruise Control
Jiangjie Qin
 
Kafka at Peak Performance
Todd Palino
 
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
Jesmar Cannao'
 
Ad

Similar to MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A Close Up Look (20)

PDF
MySQL Load Balancers - MaxScale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
Severalnines
 
PDF
Webinar slides: How to deploy and manage HAProxy, MaxScale or ProxySQL with C...
Severalnines
 
PPTX
Proxysql use case scenarios hl++ 2017
Alkin Tezuysal
 
PPTX
ProxySQL Use Case Scenarios / Alkin Tezuysal (Percona)
Ontico
 
PPTX
Proxysql use case scenarios plam 2016
Alkin Tezuysal
 
PPTX
Proxysql use case scenarios fosdem17
Alkin Tezuysal
 
PPTX
MySQL Options in OpenStack
Tesora
 
PDF
OpenStack Days East -- MySQL Options in OpenStack
Matt Lord
 
PDF
MySQL & Oracle Linux Keynote at Open Source India 2014
Sanjay Manwani
 
PDF
The Proxy Wars - MySQL Router, ProxySQL, MariaDB MaxScale
Colin Charles
 
PPTX
Tech-Spark: SQL Server on Linux
Ralph Attard
 
PDF
MySQL 5.7 what's new
Ricky Setyawan
 
PDF
MySQL :What's New #GIDS16
Sanjay Manwani
 
PDF
MySQL 5.7 InnoDB Cluster (Jan 2018)
Olivier DASINI
 
PDF
Why MySQL High Availability Matters
Matt Lord
 
PDF
MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris
Olivier DASINI
 
PDF
Kubernetes operator for MySQL
Mydbops
 
PPTX
Mysql ecosystem in 2018
Alkin Tezuysal
 
PPTX
Getting started with postgresql
botsplash.com
 
PPT
Megha_Osi my sql productroadmap
OpenSourceIndia
 
MySQL Load Balancers - MaxScale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
Severalnines
 
Webinar slides: How to deploy and manage HAProxy, MaxScale or ProxySQL with C...
Severalnines
 
Proxysql use case scenarios hl++ 2017
Alkin Tezuysal
 
ProxySQL Use Case Scenarios / Alkin Tezuysal (Percona)
Ontico
 
Proxysql use case scenarios plam 2016
Alkin Tezuysal
 
Proxysql use case scenarios fosdem17
Alkin Tezuysal
 
MySQL Options in OpenStack
Tesora
 
OpenStack Days East -- MySQL Options in OpenStack
Matt Lord
 
MySQL & Oracle Linux Keynote at Open Source India 2014
Sanjay Manwani
 
The Proxy Wars - MySQL Router, ProxySQL, MariaDB MaxScale
Colin Charles
 
Tech-Spark: SQL Server on Linux
Ralph Attard
 
MySQL 5.7 what's new
Ricky Setyawan
 
MySQL :What's New #GIDS16
Sanjay Manwani
 
MySQL 5.7 InnoDB Cluster (Jan 2018)
Olivier DASINI
 
Why MySQL High Availability Matters
Matt Lord
 
MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris
Olivier DASINI
 
Kubernetes operator for MySQL
Mydbops
 
Mysql ecosystem in 2018
Alkin Tezuysal
 
Getting started with postgresql
botsplash.com
 
Megha_Osi my sql productroadmap
OpenSourceIndia
 
Ad

More from Severalnines (20)

PDF
The Long Term Cost of Managed DBaaS vs Sovereign DBaaS
Severalnines
 
PPTX
Sovereign DBaaS_ A Practical Vision for Self-Implementation of DBaaS.pptx
Severalnines
 
PDF
PostgreSQL on AWS Aurora/Azure Cosmos VS EC2/Azure VMs
Severalnines
 
PDF
Localhost Conference 2024_ Building a Flexible and Scalable Database Strategy...
Severalnines
 
PDF
SREDAY London 2024 | Cloud Native Technologies: The Building Blocks of Modern...
Severalnines
 
PDF
Building a Sovereign DBaaS on K8s OpenInfra Summit Asia 2024.pdf
Severalnines
 
PDF
S-DBaaS Community Call | Introduction to Sovereign DBaaS: The why, what and how
Severalnines
 
PDF
WEBINAR SLIDES: CCX for Cloud Service Providers
Severalnines
 
PPTX
LIVE DEMO: CCX for CSPs, a drop-in DBaaS solution
Severalnines
 
PDF
Kubernetes at Scale: Going Multi-Cluster with Istio
Severalnines
 
PDF
DIY DBaaS: A guide to building your own full-featured DBaaS
Severalnines
 
PDF
Cloud's future runs through Sovereign DBaaS
Severalnines
 
PPTX
Tips to drive maria db cluster performance for nextcloud
Severalnines
 
PPTX
Working with the Moodle Database: The Basics
Severalnines
 
PPTX
SysAdmin Working from Home? Tips to Automate MySQL, MariaDB, Postgres & MongoDB
Severalnines
 
PDF
(slides) Polyglot persistence: utilizing open source databases as a Swiss poc...
Severalnines
 
PDF
Webinar slides: How to Migrate from Oracle DB to MariaDB
Severalnines
 
PDF
Webinar slides: How to Automate & Manage PostgreSQL with ClusterControl
Severalnines
 
PDF
Webinar slides: How to Manage Replication Failover Processes for MySQL, Maria...
Severalnines
 
PDF
Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...
Severalnines
 
The Long Term Cost of Managed DBaaS vs Sovereign DBaaS
Severalnines
 
Sovereign DBaaS_ A Practical Vision for Self-Implementation of DBaaS.pptx
Severalnines
 
PostgreSQL on AWS Aurora/Azure Cosmos VS EC2/Azure VMs
Severalnines
 
Localhost Conference 2024_ Building a Flexible and Scalable Database Strategy...
Severalnines
 
SREDAY London 2024 | Cloud Native Technologies: The Building Blocks of Modern...
Severalnines
 
Building a Sovereign DBaaS on K8s OpenInfra Summit Asia 2024.pdf
Severalnines
 
S-DBaaS Community Call | Introduction to Sovereign DBaaS: The why, what and how
Severalnines
 
WEBINAR SLIDES: CCX for Cloud Service Providers
Severalnines
 
LIVE DEMO: CCX for CSPs, a drop-in DBaaS solution
Severalnines
 
Kubernetes at Scale: Going Multi-Cluster with Istio
Severalnines
 
DIY DBaaS: A guide to building your own full-featured DBaaS
Severalnines
 
Cloud's future runs through Sovereign DBaaS
Severalnines
 
Tips to drive maria db cluster performance for nextcloud
Severalnines
 
Working with the Moodle Database: The Basics
Severalnines
 
SysAdmin Working from Home? Tips to Automate MySQL, MariaDB, Postgres & MongoDB
Severalnines
 
(slides) Polyglot persistence: utilizing open source databases as a Swiss poc...
Severalnines
 
Webinar slides: How to Migrate from Oracle DB to MariaDB
Severalnines
 
Webinar slides: How to Automate & Manage PostgreSQL with ClusterControl
Severalnines
 
Webinar slides: How to Manage Replication Failover Processes for MySQL, Maria...
Severalnines
 
Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...
Severalnines
 

Recently uploaded (20)

PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
Software Development Methodologies in 2025
KodekX
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Software Development Methodologies in 2025
KodekX
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Software Development Company | KodekX
KodekX
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 

MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A Close Up Look

  • 1. Copyright 2017 Severalnines AB Krzysztof Książek, Senior Support Engineer @Severalnines [email protected] Presenter MySQL Load Balancers - MaxScale, ProxySQL, HAProxy, MySQL Router & nginx - a close up look April, 26th 2017
  • 2. Copyright 2017 Severalnines AB Why load balancers? Types of load balancers •Application connectors •Reverse proxies •SQL-aware proxies Health checks used with proxies Agenda
  • 3. Copyright 2017 Severalnines AB High availability •Detect node health •Route traffic away from failed nodes Performance •Scale out by routing traffic to multiple nodes •Minimize number of connections to databases Why load balancers? Keep complexity away from the application •Monitor node state •Understand replication topology •Failover client connections Additional features •Collect performance data from cluster •Rewrite queries as they pass the proxy •Route queries depending on some rules (e.g. Read/write split)
  • 4. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB Application connectors
  • 5. Copyright 2017 Severalnines AB mysqlnd_ms Native driver for MySQL in PHP •Default since PHP 5.4 mysqlnd_ms adds option to implement read/write split and load balancing to PHP application Supports failover handling Supports query routing modifications through SQL hints Application connectors MySQL Connector/J Adds great deal of flexibility to Java applications when it comes to database layer handling Failover handling Live reconfiguration of replication topology Advanced routing options
  • 6. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB Reverse proxies
  • 7. Copyright 2017 Severalnines AB Industry standard - thousands of installations across the world 1.7 released in November, 2016 •1.7.5 released on April, 3rd, 2017 Reverse proxies - HAProxy Reverse proxy •Load balancing, scaling out, failover •Lack of advanced internal support for
 MySQL backends
  • 8. Copyright 2017 Severalnines AB Lack of ability to perform read/write split on a single port •Two backends on two different ports are required •Could be a blocker if an application can’t split reads from writes Reverse proxies - HAProxy No understanding of MySQL state •Only simple check on port 3306: handshake or authentication Workaround exists: clustercheck •HTTP check, xinetd, external script to monitor MySQL/Galera states
  • 9. Copyright 2017 Severalnines AB Reverse proxies - HAProxy
  • 10. Copyright 2017 Severalnines AB Designed to detect failed nodes and move VIP around One single VIP for connections, no load balancing is possible •Might be useful to build high availability if you connect only to a single node Potential use cases: •Galera cluster (for HA only) •Master - standby replication •pair of hosts connected through DRBD Reverse proxies - Keepalived
  • 11. Copyright 2017 Severalnines AB Example config for Galera cluster of three nodes •Keepalived should be installed on all hosts •All hosts should be using this configuration Leverage mysqlchk script deployed by ClusterControl •Percona’s clustercheck can also be used Can also be configured to use multicast Reverse proxies - Keepalived
  • 12. Copyright 2017 Severalnines AB A HTTP server and a HTTP reverse proxy Since 1.9 can be used as a TCP reverse proxy Limited features in free (NGINX) version •No configurable port for health checks •Not possible to integrate with clustercheck scripts More features in paid (NGINX Plus) version •Advanced health checks •Custom port for checking the health of the backend Reverse proxies - NGINX
  • 13. Copyright 2017 Severalnines AB Functionality similar to HAProxy (with regards to MySQL) •Read/write split could be done using two ports •Backup servers work differently though - all at once •No understanding of MySQL and Galera states Has to be used with clustercheck-iptables Reverse proxies - NGINX
  • 14. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB SQL-aware proxies - MaxScale
  • 15. Copyright 2017 Severalnines AB Created by MariaDB Corporation, currently in version 2.0.5 (2.1 in beta) Tool designed to solve load balancing needs of DBA’s •Handles read/write split •Automatically tracks health of backend nodes •Understands MySQL and Galera states •Master or slave? Synced or donor? SQL-aware proxies - MaxScale
  • 16. Copyright 2017 Severalnines AB Support for SSL Support for replication, Galera and MySQL Cluster Statement hinting •Where to route •Maximum replication lag Nagios integration Query mirroring SQL-aware proxies - MaxScale Caching mechanism (in 2.1) Result set masking (in 2.1) Result set limiting (in 2.1) Consistent Critical Reads (in 2.1)
  • 17. Copyright 2017 Severalnines AB Several types of routers are available: •readwritesplit - performs read/write split •readconnroute - round-robin access •dbfwfilter - filters queries based on regex •schemarouter - implements schema- based sharding •binlogrouter - MaxScale as a binlog server •avrorouter - saves binlogs in Avro file SQL-aware proxies - MaxScale Design decisions •Read queries are routed to master if executed within a transaction •Stored procedures, UDF’s, prepared statements are sent to the master only •Session variables and settings are sent to all hosts •No connection multiplexing
  • 18. Copyright 2017 Severalnines AB Lack of real-time traffic statistics (slightly improved in 2.1) No remote admin interface (available in 1.4.x, removed in 2.0) Most of configuration settings require restart (improved in 2.1) Lack of more advanced routing configuration •Route to master or slave, using hints •No regex-based routing SQL-aware proxies - MaxScale Serious scalability issues with more than 100 concurrent threads running •Based on Vadim Tkachenko’s blog post from May 12, 2016 who tested it on MaxScale 1.4.1 Performance regression when using more than 8 threads for MaxScale (from the blog post as stated above)  Non-GPL license starting from 2.0 •Up to two nodes free (more - paid) •GPL fork of 1.3 branch - AirBnB MaxScale
  • 19. Copyright 2017 Severalnines AB SQL-aware proxies - MaxScale
  • 20. Copyright 2017 Severalnines AB SQL-aware proxies - MaxScale
  • 21. Copyright 2017 Severalnines AB SQL-aware proxies - MaxScale
  • 22. Copyright 2017 Severalnines AB 320 connections: SQL-aware proxies - MaxScale 16 connections: 200 connections:
  • 23. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB SQL-aware proxies - ProxySQL
  • 24. Copyright 2017 Severalnines AB Created by René Cannaò, currently in version 1.3.6 (1.4 announced as beta) Designed to handle complex topologies •Implements read write split •Support for multiple hostgroups •Tracks health of backends on per-query basis •Advanced routing based on query rules SQL-aware proxies - ProxySQL
  • 25. Copyright 2017 Severalnines AB Admin interface uses SQL •INSERT INTO mysql_servers … •SET mysql-query_retries_on_failure=…; Cisco-like configuration approach •LOAD MYSQL QUERY RULES TO RUNTIME; •SAVE MYSQL USERS TO DISK; Virtually every setting can be changed dynamically SQL-aware proxies - ProxySQL Query rules mechanism for great flexibility •Match queries using regex, digest hash, user, schema, IP, port •Route queries based on above conditions •Query rewrite and query mirroring •Query caching - TTL and memory limit
  • 26. Copyright 2017 Severalnines AB Connection multiplexing - minimizes number of connections to backends Support for MySQL replication and Group Replication (in 1.4) Support for Galera Cluster using external scripts •Example monitoring script is provided with the ProxySQL SQL-aware proxies - ProxySQL Non-standard approach to backend health monitoring •Health check happens when traffic is sent •Monitor module extends functionality Detailed statistics about traffic handled by
 the ProxySQL
  • 27. Copyright 2017 Severalnines AB No client side SSL support - in the roadmap Lack of out-of-the-box support for explicit transactions •You have to either use SET autocommit=0 •Or enable persistent transactions for app user Session variables are tricky to support •You have to make sure they are routed to a single, writable node (i.e. replication master) SQL-aware proxies - ProxySQL Lack of direct nagios integration Lack of internal support for Galera •Although support via external script gives you more options for customization No advanced logging options (JSON, Kafka)
  • 28. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB SQL-aware proxies - MySQL Router
  • 29. Copyright 2017 Severalnines AB Created by Oracle, currently in version 2.1.3 Designed to provide high availability and scalability to your MySQL backends Supports external plugins using MySQL Harness Integrates well with MySQL Fabric for high availability setups Used as a part of MySQL InnoDB Cluster SQL-aware proxies - MySQL Router
  • 30. Copyright 2017 Severalnines AB Two modes for routing •read-only - read-only connections routed in round-robin fashion •read-write - read-write connections routed to the first working node from the list Support for MySQL Fabric: •Can route traffic to given HA group •Topology detection via Fabric SQL-aware proxies - MySQL Router
  • 31. Copyright 2017 Severalnines AB Support for MySQL InnoDB Cluster - a solution based on MySQL group replication •Deployable via MySQL Shell •Provides a support for InnoDB Cluster Metadata Schema •Caches metadata of the InnoDB Cluster and improves high availability SQL-aware proxies - MySQL Router
  • 32. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB Health checks used with proxies
  • 33. Copyright 2017 Severalnines AB HTTP check for HAProxy •Will work with any other proxy which supports http checks on custom port Script itself is a bash script which checks MySQL status •Designed for Galera but can be easily modified to use with replication •Checks wsrep_local_state for Galera states •Configurable Donor/Desync state handling Health checks used with proxies - clustercheck Script returns HTTP codes •HTTP/1.1 200 OK - if node is available •HTTP/1.1 503 Service Unavailable - otherwise Clustercheck should be installed on all databases nodes •It’s executed by xinetd, listening on custom port (9200 by default) •Make sure to configure it in /etc/services
  • 34. Copyright 2017 Severalnines AB By default, script is executed directly from xinetd •Could become a problem if it’s executed too often Numerous forks are available out there •One of nice modifications was to execute script via cron and store result in shared memory •xinetd executes another script which reads the status - minimizing impact on MySQL Health checks used with proxies - clustercheck
  • 35. Copyright 2017 Severalnines AB Derived from Percona’s clustercheck Created by Severalnines’ Ashraf Sharif Designed to work with proxies which can do only simple check on port used for service •For example, NGINX Idea is simple - use iptables to open or close port, depending on node’s state Health checks used with proxies - clustercheck-iptables Run script in a background, as a daemon Setup redirection from port 3308 to port 3306 in PREROUTING chain Every second checks the state of a node •If node is deemed unhealthy, remove redirection rule from PREROUTING chain Similar approach to health detection as in Percona’s clustercheck •Checks wsrep_local_state for Galera states
  • 36. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB Summary
  • 37. Copyright 2017 Severalnines AB Great deal of options to pick from •Everyone can choose a suitable solution Do you use NGINX in your setup? Why not to leverage your knowledge of it and use it for databases too? •You’d need clustercheck-iptables or NGINX Plus, though Do you want to build all database handling logic in your application? •PHP and Java give you great opportunities for that Summary Or maybe you prefer to move complexity of database layer from the application? •MaxScale or ProxySQL is there for you Maybe you want to use advanced features like query rewriting or sharding? •Again, ProxySQL or MaxScale will work great for you Do you work with MySQL Fabric or MySQL InnoDB Cluster and want some integration? •MySQL Router could be a great choice
  • 38. Copyright 2012 Severalnines AB Thank You! Contact: [email protected] Q&A