ProxySQL hand-on Ren Canna Ren Canna ProxySQL ProxySQL Frankfurt, - - PowerPoint PPT Presentation

proxysql hand on
SMART_READER_LITE
LIVE PREVIEW

ProxySQL hand-on Ren Canna Ren Canna ProxySQL ProxySQL Frankfurt, - - PowerPoint PPT Presentation

ProxySQL hand-on Ren Canna Ren Canna ProxySQL ProxySQL Frankfurt, 5 th Nov 2018 Frankfurt, 5 th Nov 2018 A bit about ProxySQL LLC We provide services to help build, support We provide services to help build, support as well as


slide-1
SLIDE 1

ProxySQL hand-on

René Cannaò ProxySQL

Frankfurt, 5th Nov 2018

René Cannaò ProxySQL

Frankfurt, 5th Nov 2018

slide-2
SLIDE 2

2

A bit about ProxySQL LLC

We provide services to help build, support as well as improve the performance & reliability of your Cloud-Based or On- Premise MySQL infrastructure:

  • ProxySQL Development
  • Remote Consulting
  • ProxySQL Support Services
  • ProxySQL Training

We provide services to help build, support as well as improve the performance & reliability of your Cloud-Based or On- Premise MySQL infrastructure:

  • ProxySQL Development
  • Remote Consulting
  • ProxySQL Support Services
  • ProxySQL Training
slide-3
SLIDE 3

3

A bit about me…

Rene Cannao

  • Founder of ProxySQL
  • MySQL DBA

Rene Cannao

  • Founder of ProxySQL
  • MySQL DBA
slide-4
SLIDE 4

4

Agenda

  • What is ProxySQL?
  • Features
  • Fundamentals
  • What is new?
  • Internals
  • Admin
  • Clustering
  • Rules
  • Mirroring
  • Failover
  • New protocols
  • GTID casual reads
  • What is ProxySQL?
  • Features
  • Fundamentals
  • What is new?
  • Internals
  • Admin
  • Clustering
  • Rules
  • Mirroring
  • Failover
  • New protocols
  • GTID casual reads
slide-5
SLIDE 5

5

Other sessions

HA and clustering solution: ProxySQL as an intelligent router for Galera and Group Replication Wednesday 7th November , 2018 @11:20AM ProxySQL Adaptive query routing based on GTID tracking Wednesday 7th November, 2018 @4:30PM HA and clustering solution: ProxySQL as an intelligent router for Galera and Group Replication Wednesday 7th November , 2018 @11:20AM ProxySQL Adaptive query routing based on GTID tracking Wednesday 7th November, 2018 @4:30PM

slide-6
SLIDE 6

Overview of ProxySQL

slide-7
SLIDE 7

7

What is ProxySQL

The MySQL data stargate The MySQL data stargate

slide-8
SLIDE 8

8

ProxySQL Architecture Overview

Data gateway Clients connect to ProxySQL Requests are evaluated Actions are performed

slide-9
SLIDE 9

9

Main motivations

empower the DBAs improve operation understand and improve performance create a proxy layer to shield the database High performance and High Availability

slide-10
SLIDE 10

1

Some of the most interesting features:

  • n-the-fly rewrite of queries
  • caching reads outside the database server
  • connection pooling and multiplexing
  • complex query routing and read/write split
  • load balancing
  • real time statistics
  • monitoring
  • data masking
  • multiple instances on same ports
slide-11
SLIDE 11

1 1

Some of the most interesting features:

  • high availability and scalability
  • seamless failover
  • firewall
  • query throttling
  • query timeout
  • query mirroring
  • runtime reconfiguration
  • scheduler
  • support for Galera/PXC and Group Replication
slide-12
SLIDE 12

1 2

Some of the most interesting features:

  • support for millions of users
  • support for tens of thousands of database servers
  • native ProxySQL Clustering solution
  • support for ClickHouse as a backend
  • support for Aurora
  • SSL support for frontend
  • SSLv1.2
  • native Support for Galera
  • causal reads using GTID
slide-13
SLIDE 13

1 3

slide-14
SLIDE 14

1 4

Hostgroups and Query Routing

All backends are grouped into hostgroups Hostgroups have logical functionalities All backends are grouped into hostgroups Hostgroups have logical functionalities

slide-15
SLIDE 15

1 5

Hostgroups example #1

HostGroup0 (HG0): Write masters HostGroup1( HG1): Read slaves Read/Write split

slide-16
SLIDE 16

1 6

Hostgroups example #2

HG0: main write masters HG1: main read slaves HG2: reporting slaves HG3: ad-hoc queries slaves HG4: data warehouse write masters HG5: data warehouse read slaves HG6: remote site servers HG7: test servers HG8 : mirror for traffjc on HG0 HG9 : mirror for traffjc on HG1 HG0: main write masters HG1: main read slaves HG2: reporting slaves HG3: ad-hoc queries slaves HG4: data warehouse write masters HG5: data warehouse read slaves HG6: remote site servers HG7: test servers HG8 : mirror for traffjc on HG0 HG9 : mirror for traffjc on HG1

slide-17
SLIDE 17

1 7

Basic design

HG0 HG2 HG1

ProxySQL APP1 APP2 APP3

slide-18
SLIDE 18

1 8

Basic design

HG0 HG2 HG1

APP APP ProxySQL Very low latency using Unix Domain Socket (?)

slide-19
SLIDE 19

1 9

One ProxySQL per host

slide-20
SLIDE 20

2

One ProxySQL per host

The most common setup It scales to hundreds or thousands of node Try this solution before anything else!

slide-21
SLIDE 21

2 1

Silos approach

slide-22
SLIDE 22

2 2

Clustered ProxySQL Architecture

DB DB DB

APP

DB PROXYSQL DB DB

APP

PROXYSQL

APP

PROXYSQL

APP

PROXYSQL PROXYSQL PROXYSQL DBMANAGER PROXYSQL

Clustered Proxy Layer

slide-23
SLIDE 23

2 3

Clustered ProxySQL at scale

Tested with:

  • 8 app servers with 3k clients’ connections each (24k total)
  • 4 middle layer proxysqls processing 4k connections each from local

proxysqls (16k total)

  • 256 backends/shard (meaning 256 routing rules) processing 600

connections each (150k total) Single ProxySQL was tested with up to 950k connections ProxySQL 1.4 is able to process up to 750k QPS

Tested with:

  • 8 app servers with 3k clients’ connections each (24k total)
  • 4 middle layer proxysqls processing 4k connections each from local

proxysqls (16k total)

  • 256 backends/shard (meaning 256 routing rules) processing 600

connections each (150k total) Single ProxySQL was tested with up to 950k connections ProxySQL 1.4 is able to process up to 750k QPS

slide-24
SLIDE 24

2 4

ProxySQL at scale

Real setups: Over 1000 proxysql instances in a single network Over 100 mysql servers configured on a single proxysql instances Over 2 millions unique users Routing with over 100 thousands shards Real setups: Over 1000 proxysql instances in a single network Over 100 mysql servers configured on a single proxysql instances Over 2 millions unique users Routing with over 100 thousands shards

slide-25
SLIDE 25

ProxySQL Internals

slide-26
SLIDE 26

2 6

ProxySQL Modules in 1.3.x

HG0 HG1

APP1 ProxySQL

Queries cache Query Processor

APP2 APP3

Thread #1 Thread #2 Thread #3 Users Auth

Connection Pool Hostgroup Manager Admin Monitoring

slide-27
SLIDE 27

2 7

ProxySQL Modules in 1.4.x

HG0 HG1

APP1 ProxySQL

Queries cache Query Processor

APP2 APP3

Thread #1 Thread #2 Thread #3 Users Auth

Connection Pool Hostgroup Manager Admin Monitoring ClickHouse Server

ClickHouse Auth

Cluster SQLite3 Server

Thread #3 idles Thread #2 idles Thread #1 idles

Purge Thread

slide-28
SLIDE 28

2 8

Thread pool in MySQL

Threads in ProxySQL are known as "MySQL Threads" Fixed number of worker threads (confjgurable) All threads listen on the same port(s) Client connections are not shared between threads All threads perform their own network I/O Uses "poll()"... (does it scale?)

slide-29
SLIDE 29

2 9

Threads never share client connections

Pros: Thread contention is reduced No need for synchronization Each thread calls "poll()" Cons: Possibly imbalanced load Thread 1 Thread 2 Thread 3

slide-30
SLIDE 30

3

poll() vs. epoll()

"poll()" is O(N) "epoll()" is O(1) "epoll()" scales better than "poll()" Why does ProxySQL use "poll()"? It is faster than "epoll()" for fewer connections (~1000) Performance degrades when there are a lot of connections

slide-31
SLIDE 31

3 1

ProxySQL Auxiliary Threads

Each worker thread has an auxiliary thread Worker thread uses "poll()" Auxiliary thread uses "epoll()" Worker thread passes idle connections to auxiliary thread When a connections becomes active auxiliary thread passes connection to the worker thread Solution scales to almost 1 million connections Thread 1 Aux 1 Thread 2 Aux 2 Thread 3 Aux 3

slide-32
SLIDE 32

3 2

MySQL Thread Overview

MySQL Session MySQL Session MySQL Session MySQL Session

MySQL Thread

MySQL Session MySQL Session

All other Modules:

  • Query Processor
  • Query Cache
  • Hostgroups Manager
  • Authentication
  • Others

For low contention, threads independently: Track internal metrics Store values for mysql-XXX variables Store a copy of the defjned query rules

slide-33
SLIDE 33

3 3

Queries Processor

Based on Queries Rules Defjnes what to cache Defjnes the hostgroup target Timeout/delay Firewall Mirroring Rewrite queries Based on Queries Rules Defjnes what to cache Defjnes the hostgroup target Timeout/delay Firewall Mirroring Rewrite queries

slide-34
SLIDE 34

3 4

Queries rules

Complex rules to match incoming traffjc:

  • regex on query
  • regex on digest text
  • username
  • schemaname
  • Source IP address
  • Bind IP address/port
  • digest

Rules can be chained Complex rules to match incoming traffjc:

  • regex on query
  • regex on digest text
  • username
  • schemaname
  • Source IP address
  • Bind IP address/port
  • digest

Rules can be chained

slide-35
SLIDE 35

3 5

Queries Cache and Rewrite

Caching on the wire Internal key/value storage In memory only Pattern based Expired by timeout Rewrite on the wire Regex match/replace on query on digest text Optionally cached or mirrored Caching on the wire Internal key/value storage In memory only Pattern based Expired by timeout Rewrite on the wire Regex match/replace on query on digest text Optionally cached or mirrored

slide-36
SLIDE 36

3 6

Users Authentication

Credentials stored in the proxy User login always possible (even without backends) Max connections Login credentials are encrypted Extremely scalable, up to millions of users: https://www.percona.com/live/e17/sessions/scaling-million- databases-000webhost-lt Credentials stored in the proxy User login always possible (even without backends) Max connections Login credentials are encrypted Extremely scalable, up to millions of users: https://www.percona.com/live/e17/sessions/scaling-million- databases-000webhost-lt

slide-37
SLIDE 37

3 7

Hostgroups Manager

Management of servers T rack servers status Manages the connections pool Management of servers T rack servers status Manages the connections pool

slide-38
SLIDE 38

3 8

Connections Pool

Reduced the overhead of creating new connections, and are recycled when not in use One to many connections Multiplexing & maximum connections Auto-reconnect and automatic re-execution of queries Failover management Reduced the overhead of creating new connections, and are recycled when not in use One to many connections Multiplexing & maximum connections Auto-reconnect and automatic re-execution of queries Failover management

slide-39
SLIDE 39

3 9

Connections Pool

slide-40
SLIDE 40

4

Connections Pool

slide-41
SLIDE 41

4 1

Connection Pool

Replies to ping. From hundreds of millions of ping per day, to 0:

https://www.percona.com/blog/2017/09/01/life360-used-proxysql-lower-database-load/

Replies to ping. From hundreds of millions of ping per day, to 0:

https://www.percona.com/blog/2017/09/01/life360-used-proxysql-lower-database-load/

slide-42
SLIDE 42

4 2

Purge Thread

Unsafe connections are reset instead of being dropped Drastically reduce the need to establish new connections In ProxySQL 2.0 : each worker thread performs most of the reset Unsafe connections are reset instead of being dropped Drastically reduce the need to establish new connections In ProxySQL 2.0 : each worker thread performs most of the reset

slide-43
SLIDE 43

4 3

Auto-reconnect and re-execution

Automatic detection of failures Graceful handling Auto-reconnect when possible Pause until a backend becomes available Re-execution of queries Automatic detection of failures Graceful handling Auto-reconnect when possible Pause until a backend becomes available Re-execution of queries

slide-44
SLIDE 44

4 4

Multiplexing

Reduce the number of connections against mysqld (confjgurable) Many clients connections (tens of thousands) can use few backend connections (few hundreds) T racks connection status (transactions, user variables, temporary tables, etc) Order by waiting time Reduce the number of connections against mysqld (confjgurable) Many clients connections (tens of thousands) can use few backend connections (few hundreds) T racks connection status (transactions, user variables, temporary tables, etc) Order by waiting time

slide-45
SLIDE 45

4 5

No ProxySQL: ProxySQL:

slide-46
SLIDE 46

4 6

No ProxySQL: ProxySQL:

slide-47
SLIDE 47

4 7

ProxySQL: No ProxySQL:

slide-48
SLIDE 48

4 8

slide-49
SLIDE 49

4 9

Multiplexing

https://www.percona.com/blog/2017/09/01/life360-used-proxysql-lower-database-load/ https://www.percona.com/blog/2017/09/01/life360-used-proxysql-lower-database-load/

slide-50
SLIDE 50

5

MySQL Threads and Connection Pool

MyHGM is a shared resource so it can cause contention when accessed by MySQL Threads

MySQL_Thread MySQL_Thread

MyHGM

slide-51
SLIDE 51

5 1

Thread Connection Cache

MySQL_Thread MySQL_Thread

MyHGM

Connections Cache Connections Cache

slide-52
SLIDE 52

ProxySQL Web UI

slide-53
SLIDE 53

5 3

Multiplexing (see it in web UI)

slide-54
SLIDE 54

5 4

Multiplexing (see it in web)

slide-55
SLIDE 55

5 5

More metrics on web UI

slide-56
SLIDE 56

5 6

More metrics on web UI

slide-57
SLIDE 57

5 7

More metrics on web UI

slide-58
SLIDE 58

5 8

Monitoring Module

It monitors backends and collects metrics Monitors replication lag and shun hosts Monitors read_only (and super_read_only and innodb_read_only in 2.0) variables (replication hostgroups) Ping and terminates unresponsive nodes It monitors backends and collects metrics Monitors replication lag and shun hosts Monitors read_only (and super_read_only and innodb_read_only in 2.0) variables (replication hostgroups) Ping and terminates unresponsive nodes

slide-59
SLIDE 59

5 9

Monitoring Module

Built in support for asynchronous replication: second behind master and pt-heartbeat Support for any type of clustering solution via external scripts (Galera/PXC , and any heterogeneous replication setup) In ProxySQL 1.4, support for Group Replication In ProxySQL 2.0, support for Galera Built in support for asynchronous replication: second behind master and pt-heartbeat Support for any type of clustering solution via external scripts (Galera/PXC , and any heterogeneous replication setup) In ProxySQL 1.4, support for Group Replication In ProxySQL 2.0, support for Galera

slide-60
SLIDE 60

Admin Module

slide-61
SLIDE 61

6 1

Admin Interface

Allows runtime confjguration Exports internal statuses It uses MySQL protocol Confjguration possible from any client/tool using MySQL API Covered during the tutorial Allows runtime confjguration Exports internal statuses It uses MySQL protocol Confjguration possible from any client/tool using MySQL API Covered during the tutorial

slide-62
SLIDE 62

6 2

Admin Interface

Disk Memory Runtime Disk Memory Runtime

Runtime Memory Disk Config

slide-63
SLIDE 63

6 3

Try it!

Source code on GitHub: https://github.com/sysown/proxysql/ Forum: https://groups.google.com/forum/#!forum/proxysql T utorials on: http://www.proxysql.com Source code on GitHub: https://github.com/sysown/proxysql/ Forum: https://groups.google.com/forum/#!forum/proxysql T utorials on: http://www.proxysql.com

slide-64
SLIDE 64

Demo Environment

slide-65
SLIDE 65

6 5

Demo

Code on GitHub:

https://github.com/renecannao/ProxySQL-Tutorial-PLSC2018

Some hosts provided: Username: plsc Passwords: proxysql Code on GitHub:

https://github.com/renecannao/ProxySQL-Tutorial-PLSC2018

Some hosts provided: Username: plsc Passwords: proxysql

slide-66
SLIDE 66

ProxySQL Cluster

slide-67
SLIDE 67

6 7

ProxySQL Cluster

Introduced in 1.4.2 Support for MySQL Query Rules, MySQL Users, MySQL Servers and ProxySQL Servers (no Global Variables, no Scheduler) A group of instances constantly check each other for changes in configuration A configuration change applied in a proxy is pulled by the other proxies Allow to keep multiple ProxySQL instances with the same configuration(s) Introduced in 1.4.2 Support for MySQL Query Rules, MySQL Users, MySQL Servers and ProxySQL Servers (no Global Variables, no Scheduler) A group of instances constantly check each other for changes in configuration A configuration change applied in a proxy is pulled by the other proxies Allow to keep multiple ProxySQL instances with the same configuration(s)

slide-68
SLIDE 68

6 8

ProxySQL Cluster

  • Core Nodes
  • Satellite Nodes

Largest setup we know: 1) 3 core nodes 2) 900 satellite nodes

slide-69
SLIDE 69

6 9

ProxySQL Cluster

Conflict resolution is timestamp based

  • No order
  • Last win

No quorum (in the roadmap) Highly scalable: Core nodes vs satellite nodes Conflict resolution is timestamp based

  • No order
  • Last win

No quorum (in the roadmap) Highly scalable: Core nodes vs satellite nodes

slide-70
SLIDE 70

7

ProxySQL Cluster - Confjg

mysql> SET admin-cluster_username='radmin'; mysql> SET admin-cluster_password='radmin'; mysql> LOAD ADMIN VARIABLES TO RUNTIME; mysql> SAVE ADMIN VARIABLES TO DISK; mysql> INSERT INTO proxysql_servers (hostname) VALUES ('proxysql1'),('proxysql2'), ('proxysql3'); mysql> LOAD PROXYSQL SERVERS TO RUNTIME; mysql> SAVE PROXYSQL SERVERS TO DISK; mysql> SET admin-cluster_username='radmin'; mysql> SET admin-cluster_password='radmin'; mysql> LOAD ADMIN VARIABLES TO RUNTIME; mysql> SAVE ADMIN VARIABLES TO DISK; mysql> INSERT INTO proxysql_servers (hostname) VALUES ('proxysql1'),('proxysql2'), ('proxysql3'); mysql> LOAD PROXYSQL SERVERS TO RUNTIME; mysql> SAVE PROXYSQL SERVERS TO DISK;

mysql> SHOW VARIABLES LIKE 'admin-cluster%'; +---------------------------------------------------+--------+ | Variable_name | Value | +---------------------------------------------------+--------+ | admin-cluster_username | radmin | | admin-cluster_password | radmin | | admin-cluster_check_interval_ms | 1000 | | admin-cluster_check_status_frequency | 10 | | admin-cluster_mysql_query_rules_difgs_before_sync | 3 | | admin-cluster_mysql_servers_difgs_before_sync | 3 | | admin-cluster_mysql_users_difgs_before_sync | 3 | | admin-cluster_proxysql_servers_difgs_before_sync | 3 | | admin-cluster_mysql_query_rules_save_to_disk | true | | admin-cluster_mysql_servers_save_to_disk | true | | admin-cluster_mysql_users_save_to_disk | true | | admin-cluster_proxysql_servers_save_to_disk | true | +---------------------------------------------------+--------+ 12 rows in set (0.00 sec) mysql> SHOW VARIABLES LIKE 'admin-cluster%'; +---------------------------------------------------+--------+ | Variable_name | Value | +---------------------------------------------------+--------+ | admin-cluster_username | radmin | | admin-cluster_password | radmin | | admin-cluster_check_interval_ms | 1000 | | admin-cluster_check_status_frequency | 10 | | admin-cluster_mysql_query_rules_difgs_before_sync | 3 | | admin-cluster_mysql_servers_difgs_before_sync | 3 | | admin-cluster_mysql_users_difgs_before_sync | 3 | | admin-cluster_proxysql_servers_difgs_before_sync | 3 | | admin-cluster_mysql_query_rules_save_to_disk | true | | admin-cluster_mysql_servers_save_to_disk | true | | admin-cluster_mysql_users_save_to_disk | true | | admin-cluster_proxysql_servers_save_to_disk | true | +---------------------------------------------------+--------+ 12 rows in set (0.00 sec)

slide-71
SLIDE 71

7 1

ProxySQL Cluster - Monitoring

stats_proxysql_servers_checksums stats_proxysql_servers_metrics stats_proxysql_servers_checksums stats_proxysql_servers_metrics

slide-72
SLIDE 72

ProxySQL Cluster DEMO

slide-73
SLIDE 73

MySQL Query rules

slide-74
SLIDE 74

7 4

Query rewriting overview

SQL-aware Regex-based fmexible SQL-aware Regex-based fmexible

slide-75
SLIDE 75

7 5

Query rewriting examples

read/write splitting Data masking Sharding read/write splitting Data masking Sharding

slide-76
SLIDE 76

7 6

Query rewriting fmow

slide-77
SLIDE 77

7 7

Match Related T ables

mysql_users

  • active
  • fast_forward(bypass)

mysql_users

  • active
  • fast_forward(bypass)

mysql_query_rules

  • username
  • schemaname
  • flagIN/OUT
  • client_addr
  • proxy_addr
  • proxy_port
  • digest
  • match_digest
  • match_pattern
  • negate_match_pattern

mysql_query_rules

  • username
  • schemaname
  • flagIN/OUT
  • client_addr
  • proxy_addr
  • proxy_port
  • digest
  • match_digest
  • match_pattern
  • negate_match_pattern
slide-78
SLIDE 78

7 8

Action related fjelds

flagOUT replace_pattern destination_hostgroup cache_ttl timeout retries delay mirror_flagOUT mirror_hostgroup OK_msg error_msg log multiplex apply flagOUT replace_pattern destination_hostgroup cache_ttl timeout retries delay mirror_flagOUT mirror_hostgroup OK_msg error_msg log multiplex apply

active New in 2.0 : gtid_from_hostgroup cache_empty_result cache_timeout active New in 2.0 : gtid_from_hostgroup cache_empty_result cache_timeout

slide-79
SLIDE 79

7 9

3 layers for ProxySQL tables

Disk Memory Runtime Disk Memory Runtime

Runtime Memory Disk Config

slide-80
SLIDE 80

8

Precautions

Confirm the query hits with stats_mysql_query_rules double check rules and rewrite results hold off on writing rules to disk until you're sure they are working as expected have a rollback plan

  • load from disk,
  • then load from memory to runtime

test select query rules and rewrites on a slaves first test mutable rules on a mirror or other throw away db. Confirm the query hits with stats_mysql_query_rules double check rules and rewrite results hold off on writing rules to disk until you're sure they are working as expected have a rollback plan

  • load from disk,
  • then load from memory to runtime

test select query rules and rewrites on a slaves first test mutable rules on a mirror or other throw away db.

slide-81
SLIDE 81

8 1 mysql> SELECT username, default_hostgroup FROM mysql_users\G *************************** 1. row *************************** username: root default_hostgroup: 0 1 row in set (0.00 sec) mysql> SELECT match_digest, destination_hostgroup FROM mysql_query_rules\G *************************** 1. row *************************** match_digest: ^SELECT.*FOR UPDATE destination_hostgroup: 0 *************************** 2. row *************************** match_digest: ^SELECT destination_hostgroup: 1 2 rows in set (0.00 sec) mysql> SELECT username, default_hostgroup FROM mysql_users\G *************************** 1. row *************************** username: root default_hostgroup: 0 1 row in set (0.00 sec) mysql> SELECT match_digest, destination_hostgroup FROM mysql_query_rules\G *************************** 1. row *************************** match_digest: ^SELECT.*FOR UPDATE destination_hostgroup: 0 *************************** 2. row *************************** match_digest: ^SELECT destination_hostgroup: 1 2 rows in set (0.00 sec)

Example - Simple R/W

This example is a simple one, NOT for production use

For production configuration guide, see: https://proxysql.com/blog/configure-read-write-split

slide-82
SLIDE 82

Query Rewriting with ProxySQL DEMO

Click to add text Click to add text

slide-83
SLIDE 83

ProxySQL Upgrade with zero downtime

slide-84
SLIDE 84

8 4

Multiple instances running on the same port

Requires Linux Kernel 3.9 Use different datadir (optionally different config file) Close the listener for a process Drain connections from one node Wait all the connections to pass over Requires Linux Kernel 3.9 Use different datadir (optionally different config file) Close the listener for a process Drain connections from one node Wait all the connections to pass over

slide-85
SLIDE 85

Mirroring with ProxySQL

Click to add text Click to add text

slide-86
SLIDE 86

8 6

What is mirroring?

slide-87
SLIDE 87

8 7

What is mirroring?

slide-88
SLIDE 88

8 8

Why mirror queries?

Validate performance on a difgerent server using difgerent hostgroups. Validate performance of query rewrite or schema change Pre-fetch slave replication (Replication Booster) Validate performance on a difgerent server using difgerent hostgroups. Validate performance of query rewrite or schema change Pre-fetch slave replication (Replication Booster)

slide-89
SLIDE 89

8 9

How to mirror

mysql>SHOW CREATE TABLE mysql_query_rules\G *********************** 1. row ************************ table: mysql_query_rules Create T able: CREATE TABLE mysql_query_rules ( rule_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 0, username VARCHAR, schemaname VARCHAR, fmagIN INT NOT NULL DEFAULT 0, *snip* mirror_fmagOUT INT UNSIGNED, mirror_hostgroup INT UNSIGNED, error_msg VARCHAR, *snip*) mysql>SHOW CREATE TABLE mysql_query_rules\G *********************** 1. row ************************ table: mysql_query_rules Create T able: CREATE TABLE mysql_query_rules ( rule_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 0, username VARCHAR, schemaname VARCHAR, fmagIN INT NOT NULL DEFAULT 0, *snip* mirror_fmagOUT INT UNSIGNED, mirror_hostgroup INT UNSIGNED, error_msg VARCHAR, *snip*)

slide-90
SLIDE 90

9

Mirroring fmow

slide-91
SLIDE 91

9 1

Mirroring - example #1

mysql> SELECT username, destination_hostgroup, mirror_hostgroup, mirror_fmagOUT FROM mysql_query_rules WHERE username='plam_mirror'\G ****************** 1. row ********************** username: pl_mirror destination_hostgroup: 3 mirror_hostgroup: 4 mirror_fmagOUT: NULL mysql> SELECT username, destination_hostgroup, mirror_hostgroup, mirror_fmagOUT FROM mysql_query_rules WHERE username='plam_mirror'\G ****************** 1. row ********************** username: pl_mirror destination_hostgroup: 3 mirror_hostgroup: 4 mirror_fmagOUT: NULL

slide-92
SLIDE 92

9 2

Mirroring - example #2

slide-93
SLIDE 93

Mirroring Demo

Click to add text Click to add text

slide-94
SLIDE 94

9 4

Mirroring caveats

Can be dropped: mysql-mirror_max_concurrency, mysql-mirror_max_queue_length Can be executed out of order No error handling of failed queries Can be dropped: mysql-mirror_max_concurrency, mysql-mirror_max_queue_length Can be executed out of order No error handling of failed queries

slide-95
SLIDE 95

Failover with ProxySQL

slide-96
SLIDE 96

9 6

Failover highlights

improve failover time as perceived by the application prevent errors sent to the application perform transparent database failovers: gracefully redirecting traffic without the application knowing existing applications do not have to be rewritten to autoreconnect since connections are not lost from failovers improve failover time as perceived by the application prevent errors sent to the application perform transparent database failovers: gracefully redirecting traffic without the application knowing existing applications do not have to be rewritten to autoreconnect since connections are not lost from failovers

slide-97
SLIDE 97

9 7

Failover scenario - without ProxySQL

slide-98
SLIDE 98

9 8

Failover scenario - without ProxySQL

slide-99
SLIDE 99

9 9

Failover scenario - with ProxySQL

slide-100
SLIDE 100

1

Failover scenario - with ProxySQL

slide-101
SLIDE 101

1 1

Failover scenario - with ProxySQL

slide-102
SLIDE 102

1 2

Failover scenario - with ProxySQL

slide-103
SLIDE 103

1 3

Failover without ProxySQL (10 minute outage)

https://www.nylas.com/blog/growing-up-with-mysql/

slide-104
SLIDE 104

1 4

Failover with ProxySQL (10 second outage)

https://www.nylas.com/blog/growing-up-with-mysql/

slide-105
SLIDE 105

1 5

Failover - MySQL Servers

mysql> SELECT hostgroup_id, hostname, status FROM mysql_servers WHERE hostname IN ('mysql1, 'mysql2’)\G *************************** 1. row *************************** hostgroup_id: 0 hostname: mysql1 status: ONLINE *************************** 2. row *************************** hostgroup_id: 1 hostname: mysql2 status: ONLINE 2 rows in set (0.00 sec) mysql> SELECT hostgroup_id, hostname, status FROM mysql_servers WHERE hostname IN ('mysql1, 'mysql2’)\G *************************** 1. row *************************** hostgroup_id: 0 hostname: mysql1 status: ONLINE *************************** 2. row *************************** hostgroup_id: 1 hostname: mysql2 status: ONLINE 2 rows in set (0.00 sec)

slide-106
SLIDE 106

1 6

Failover - Replication Hostgroups

mysql> SELECT * FROM mysql_replication_hostgroups\G *************************** 1. row *************************** writer_hostgroup: 0 reader_hostgroup: 1 comment: 1 row in set (0.00 sec) mysql> SELECT * FROM mysql_replication_hostgroups\G *************************** 1. row *************************** writer_hostgroup: 0 reader_hostgroup: 1 comment: 1 row in set (0.00 sec)

slide-107
SLIDE 107

1 7

ProxySQL Failover ProTIP

ProxySQL does not handle promotion or re-slaving External process needed, such as MHA or Orchestrator ProxySQL does not handle promotion or re-slaving External process needed, such as MHA or Orchestrator

slide-108
SLIDE 108

Failover Demo

Click to add text Click to add text

slide-109
SLIDE 109

Some New Features

Click to add text Click to add text

slide-110
SLIDE 110

1 1

ClickHouse Server

New in 1.4.3 – experimental (not fully completed, subject to change) Support for ClickHouse: https://clickhouse.yandex/ Fast, really fast data analytics using MySQL client Users management Supports only one backend Supports only DDL and SELECT (no INSERT) New in 1.4.3 – experimental (not fully completed, subject to change) Support for ClickHouse: https://clickhouse.yandex/ Fast, really fast data analytics using MySQL client Users management Supports only one backend Supports only DDL and SELECT (no INSERT)

slide-111
SLIDE 111

1 1 1

ClickHouse Server

slide-112
SLIDE 112

1 1 2

ClickHouse Server

slide-113
SLIDE 113

1 1 3

SQLite3 Server

New in 1.4.3 – experimental (not fully completed, subject to change) Support for SQLite3 : https://www.sqlite.org/ Fully transactional, in-memory Same users as MySQL backends A lot of features in the roadmap New in 1.4.3 – experimental (not fully completed, subject to change) Support for SQLite3 : https://www.sqlite.org/ Fully transactional, in-memory Same users as MySQL backends A lot of features in the roadmap

slide-114
SLIDE 114

1 1 4

You-Name-It Server

What other service should become part of ProxySQL ? What other service should become part of ProxySQL ?

slide-115
SLIDE 115

1 1 5

Causal read with GTID

Feature introduced in 2.0 Ensures that reads sent to slave returns what the client has written on master Requires GTID and MySQL 5.7+ Feature introduced in 2.0 Ensures that reads sent to slave returns what the client has written on master Requires GTID and MySQL 5.7+

slide-116
SLIDE 116

1 1 6

11 6

ProxSQL Read / Write Split

slide-117
SLIDE 117

1 1 7

11 7

ProxySQL Binlog Reader

slide-118
SLIDE 118

1 1 8

11 8

ProxySQL Binlog Reader

slide-119
SLIDE 119

1 1 9

Hundreds of thousands of shards

Feature introduced in 1.4.7 Simpler version of mysql_query_rules Used as a hash table

mysql> SELECT username,schemaname,flagIN, destination_hostgroup dest FROM mysql_query_rules_fast_routing; +----------+------------+--------+------+ | username | schemaname | flagIN | dest | +----------+------------+--------+------+ | userA | shard1 | 0 | 1 | | userA | shard2 | 0 | 1 | | userA | shard3 | 0 | 1 | | userA | shard4 | 0 | 1 | | userA | shard5 | 0 | 2 | | userA | shard6 | 0 | 2 | | userA | shard7 | 0 | 2 | +----------+------------+--------+------+

Feature introduced in 1.4.7 Simpler version of mysql_query_rules Used as a hash table

mysql> SELECT username,schemaname,flagIN, destination_hostgroup dest FROM mysql_query_rules_fast_routing; +----------+------------+--------+------+ | username | schemaname | flagIN | dest | +----------+------------+--------+------+ | userA | shard1 | 0 | 1 | | userA | shard2 | 0 | 1 | | userA | shard3 | 0 | 1 | | userA | shard4 | 0 | 1 | | userA | shard5 | 0 | 2 | | userA | shard6 | 0 | 2 | | userA | shard7 | 0 | 2 | +----------+------------+--------+------+

slide-120
SLIDE 120

1 2

Rate My Session

slide-121
SLIDE 121

1 2 1

Thank you!

  • Please remember to report feature requests and bug reports:

https://github.com/sysown/proxysql/

  • Community support can be found on our forum:

https://groups.google.com/forum/#!forum/proxysql

  • Useful blog articles are available at our site: http://proxysql.com/blog
  • Visit us at http://proxysql.com/support for subscription and support options
  • Please remember to report feature requests and bug reports:

https://github.com/sysown/proxysql/

  • Community support can be found on our forum:

https://groups.google.com/forum/#!forum/proxysql

  • Useful blog articles are available at our site: http://proxysql.com/blog
  • Visit us at http://proxysql.com/support for subscription and support options