Santa Clara, California | April 23th – 25th, 2018
ProxySQL Tutorial
High Performance & High Availability Proxy for MySQL
With a GPL license!
ProxySQL Tutorial High Performance & High Availability Proxy - - PowerPoint PPT Presentation
ProxySQL Tutorial High Performance & High Availability Proxy for MySQL With a GPL license! Santa Clara, California | April 23th 25th, 2018 Who we are Ren Canna ProxySQL Founder Derek Downey Director of OSDB, Pythian 2 Agenda
Santa Clara, California | April 23th – 25th, 2018
High Performance & High Availability Proxy for MySQL
With a GPL license!
2
ProxySQL Founder
Director of OSDB, Pythian
3
4
6
7
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 traffic on HG0 HG9 : mirror for traffic on HG1
HG0 HG2 HG1
HG0 HG2 HG1
DB DB DB
APP
DB PROXYSQL DB DB
APP
PROXYSQL
APP
PROXYSQL
APP
PROXYSQL PROXYSQL PROXYSQL DBMANAGER PROXYSQL
Clustered Proxy Layer
Tested with:
proxysqls (16k total)
connections each (150k total) Single ProxySQL was tested with up to 950k connections At today, ProxySQL is able to process up to 750k QPS
HG0 HG1
Queries cache Query Processor
Thread #1 Thread #2 Thread #3 Users Auth
Connection Pool Hostgroup Manager Admin Monitoring
HG0 HG1
Queries cache Query Processor
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
Based on Queries Rules Defines what to cache Defines the hostgroup target Timeout/delay Firewall Mirroring Rewrite queries
Complex rules to match incoming traffic:
Rules can be chained
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
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
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
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.0, support for Group Replication In ProxySQL 2.0, support for Galera
Allows runtime configuration Exports internal statuses It uses MySQL protocol Configuration possible from any client/tool using MySQL API Covered during the tutorial
Disk Memory Runtime
47
https://github.com/renecannao/ProxySQL-Tutorial-PLSC2018
New in 1.4.2 – experimental (not fully completed, subject to change) Support for MySQL Query Rules, MySQL Users, MySQL Servers and ProxySQL Servers 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)
Conflict resolution is timestamp based
No quorum (in the roadmap) Highly scalable: Core nodes vs satellite nodes
52
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_diffs_before_sync | 3 | | admin-cluster_mysql_servers_diffs_before_sync | 3 | | admin-cluster_mysql_users_diffs_before_sync | 3 | | admin-cluster_proxysql_servers_diffs_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)
53
Stats_proxysql_servers_checksums Stats_proxysql_servers_metrics
56
57
58
mysql_users
mysql_query_rules
flagOUT replace_pattern destination_hostgroup cache_ttl timeout retries delay mirror_flagOUT mirror_hostgroup OK_msg error_msg log multiplex apply
active
Disk Memory Runtime
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
test select query rules and rewrites on a slaves first test mutable rules on a mirror or other throw away db.
63
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)
Click to add text
Click to add text
66
67
68
69
mysql>SHOW CREATE TABLE mysql_query_rules\G *********************** 1. row ************************ table: mysql_query_rules Create Table: 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, flagIN INT NOT NULL DEFAULT 0, *snip* mirror_flagOUT INT UNSIGNED, mirror_hostgroup INT UNSIGNED, error_msg VARCHAR, *snip*)
70
71
mysql> SELECT username, destination_hostgroup, mirror_hostgroup, mirror_flagOUT FROM mysql_query_rules WHERE username='plam_mirror'\G ****************** 1. row ********************** username: pl_mirror destination_hostgroup: 3 mirror_hostgroup: 4 mirror_flagOUT: NULL
72
Click to add text
74
76
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
77
78
79
80
81
82
83
https://www.nylas.com/blog/growing-up-with-mysql/
84
https://www.nylas.com/blog/growing-up-with-mysql/
85
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)
86
mysql> SELECT * FROM mysql_replication_hostgroups\G *************************** 1. row *************************** writer_hostgroup: 0 reader_hostgroup: 1 comment: 1 row in set (0.00 sec)
87
Click to add text
Click to add text
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 SQLite3 : https://www.sqlite.org/ Fully transactional, in-memory Same users as MySQL backends A lot of features in the roadmap
What other service should become part of ProxySQL ?
What other service should become part of ProxySQL ?
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+
97
98
99
10
10 2