proxysql tutorial
play

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


  1. ProxySQL Cluster - Config mysql> SHOW VARIABLES LIKE 'admin-cluster%'; mysql> SET admin-cluster_username='radmin'; +---------------------------------------------------+--------+ mysql> SET admin-cluster_password='radmin'; | Variable_name | Value | mysql> LOAD ADMIN VARIABLES TO RUNTIME; +---------------------------------------------------+--------+ | admin-cluster_username | radmin | mysql> SAVE ADMIN VARIABLES TO DISK; | admin-cluster_password | radmin | | admin-cluster_check_interval_ms | 1000 | mysql> INSERT INTO proxysql_servers (hostname) VALUES | admin-cluster_check_status_frequency | 10 | | admin-cluster_mysql_query_rules_diffs_before_sync | 3 | ('proxysql1'),('proxysql2'),('proxysql3'); | admin-cluster_mysql_servers_diffs_before_sync | 3 | mysql> LOAD PROXYSQL SERVERS TO RUNTIME; | admin-cluster_mysql_users_diffs_before_sync | 3 | mysql> SAVE PROXYSQL SERVERS TO DISK; | 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) 52

  2. ProxySQL Cluster - Monitoring Stats_proxysql_servers_checksums Stats_proxysql_servers_metrics 53

  3. ProxySQL Cluster DEMO

  4. MySQL Query rules

  5. Query rewriting overview Sql-aware Regex-based flexible 56

  6. Query rewriting examples read/write splitting Data masking Sharding 57

  7. Query rewriting flow 58

  8. Match Related Tables mysql_query_rules mysql_users • active • username • fast_forward(bypass) • schemaname • flagIN/OUT • client_addr • proxy_addr • proxy_port • digest • match_digest • match_pattern • negate_match_pattern

  9. Action related fields flagOUT active replace_pattern destination_hostgroup cache_ttl timeout retries delay mirror_flagOUT mirror_hostgroup OK_msg error_msg l og multiplex apply

  10. 3 layers for ProxySQL tables Disk Memory Runtime Runtime Memory Config Disk

  11. 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.

  12. Example - Simple R/W 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 63 2 rows in set (0.00 sec)

  13. Query Rewriting with ProxySQL DEMO Click to add text

  14. Mirroring with ProxySQL Click to add text

  15. What is mirroring? 66

  16. What is mirroring? 67

  17. Why mirror queries? Validate performance on a different server using different hostgroups. Validate performance of query rewrite or schema change Pre-fetch slave replication (Replication Booster) 68

  18. How to mirror 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, 69 * snip *)

  19. Mirroring flow 70

  20. Mirroring - example #1 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 71 mirror_flagOUT: NULL

  21. Mirroring - example #2 72

  22. Mirroring Demo Click to add text

  23. 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 74

  24. Failover with ProxySQL

  25. 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 76

  26. Failover scenario - without ProxySQL 77

  27. Failover scenario - without ProxySQL 78

  28. Failover scenario - with ProxySQL 79

  29. Failover scenario - with ProxySQL 80

  30. Failover scenario - with ProxySQL 81

  31. Failover scenario - with ProxySQL 82

  32. Failover without ProxySQL (10 minute outage) 83 https://www.nylas.com/blog/growing-up-with-mysql/

  33. Failover with ProxySQL (10 second outage) 84 https://www.nylas.com/blog/growing-up-with-mysql/

  34. 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) 85

  35. 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) 86

  36. ProxySQL Failover ProTIP ProxySQL does not handle promotion or re-slaving External process needed, such as MHA or Orchestrator 87

  37. Failover Demo Click to add text

  38. New Features Click to add text

  39. 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)

  40. ClickHouse Server

  41. ClickHouse Server

  42. 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

  43. You-Name-It Server What other service should become part of ProxySQL ?

  44. You-Name-It Server What other service should become part of ProxySQL ?

  45. 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+

  46. ProxSQL Read / Write Split 97

  47. ProxySQL Binlog Reader 98

  48. ProxySQL Binlog Reader 99

  49. 10 0

Recommend


More recommend