ProxySQL Use Case
Scenarios
FOSDEM FEB 3 2017
Alkin Tezuysal
2
Who am I?
• Alkin Tezuysal
Sr. Technical Manager, Percona
@ask_dba
3
Top 5 reasons to use ProxySQL
• Improve database operations.
• Understand and solve performance issues.
• Create a proxy layer to shield the database.
• Add High-Availability to database topology.
• Empower the DBAs with great tool.
4
ProxySQL Highlights
Scalability High Availability
Advanced Query
Support
Manageability
5
Use case overview - Scalability
Connection Pooling
and Multiplexing
Add connection
pooling layer
Reduce
connection
thread overhead
Read / Write Split
More scalability
for any MySQL
topology
Must for any
heavy workloads
Read / Write
Sharding
Effortless
sharding
implementation
Without Dev.
support and cost
savings
6
Use case overview - High Availability
Seamless Failover
Gracef
ul failover
support
Query rerouting
Load Balancing
Allows easy
scaling
For better
utilization of
servers
Cluster Aware
Supports
PXC/Galera
implementations
Small footprint
for big gain
7
Use case overview - Advanced Queries
Query caching Cache frequently
used data
Adds another
cache layer
Query rewrite Add SQL
flexibility
Faster problem
solving
Query blocking Add database
aware firewall
Without App.
support
8
Use case overview - Advanced Queries
Query mirroring
Audit, Analyze,
Review, Cache
Warming
Allow
benchmarking on
live data
Query throttling
Set prioritization
for important
queries
Allows manual
intervention to
problem queries
Query timeout Add another
timeout layer
Flexible query
level timeout
9
Use case overview - Manageability
Admin Utility Authentication
support
Limit user access
to database pool
Runtime
reconfiguration
On the fly
modifications
Configure
database without
restart or
downtime
Monitoring Stats collection
and reporting
Investigate
database
workload
10
Scalability with ProxySQL -
Connection Pooling
• Any application without persistent connection to database
• PHP applications to be specific without built in connection pool
Application MySQLProxySQL
• Reduces number of new connections to the database
11
Scalability with ProxySQL –
Connection Multiplexing
• Any application with persistent connection to database
• Java applications to be specific with built in connection pools
Application
Pool
MySQL
• Reduce connections similar to Aurora
• Testing being performed for 300K database connections
Application
Pool
Application
Pool
ProxySQL
12
Scalability with ProxySQL - Read/Write
Split
• On the fly Read / Write implementation
• Use read_only flag to switch traffic
Application
MySQL Master
• Load balancing made easy
MySQL
Slave
Write
hostgroups
Read
hostgroups MySQL
Slave
13
Scalability with ProxySQL – User and
schema level sharding
• Granular sharding per username and schema
• Backend pooling based on user activity to specific schema
Application
User A
ProxySQL
• Use advanced sharding to parallelize queries
• Scale beyond the sharding per host limitations.
Application
User B
MySQL
Master
MySQL
Slave
MySQL
Master
MySQL
Slave
MySQL
Master
MySQL
Slave
14
MySQL SlaveMySQL Master
High Availability with ProxySQL –
Seamless failover
• Neither VIP setup nor service discovery needed
• Use read_only flag to switch traffic
Application
Pool
MySQL Master
• Integration with other HA Managers
Application
Pool
Application
Pool
ProxySQL
15
High Availability with ProxySQL –
Improve Multi DC implementation
• No connection pools latency on SSL connections.
• Costly delays across the water.
MySQL MasterProxySQL
MySQL Master
ProxySQL
Application
DC1
DC2
16
High Availability with ProxySQL –
Adoption to Clustering
• PXC / Galera / Group Replication
MySQL
ProxySQL
•
ProxySQL
Application
Node 1
Application
Application
MySQL
Node 2
MySQL
Node 3
17
Advanced Queries with ProxySQL –
Caching
• Improve performance on read intensive workloads
• Reduce slave provisioning
Application
A
ProxySQL
• Improved query cache over default implementation
• Query aware caching over general caching
Application
B
MySQL
Master
MySQL
Slave
MySQL
Slave
MySQL
Slave
Cache
MySQL
Slave
MySQL
Slave
18
Advanced Queries with ProxySQL –
Query Timeout
• Built in query killer a.k.a query sniper
• Adjustable threshold based on query rule
Application
A
ProxySQL
• No idle or long running queries
Application
B
MySQL
Master
MySQL
Slave
MySQL
Slave
MySQL
Slave
Query
Timeouts
MySQL
Slave
MySQL
Slave
19
Advanced Queries with ProxySQL –
Firewall
• Protect database from unwanted traffic
• Stop unwanted user, account , application (new code)
Application
A
ProxySQL
• Fast modification to database behavior
• Added protection for DDOS and other attacks.
Application
B
Query
Blocking
MySQL
Master
MySQL
Slave
MySQL
Master
MySQL
Slave
MySQL
Master
MySQL
Slave
20
Advanced Queries with ProxySQL –
Query rewrite engine
• Most wanted feature by DBAs
• Rewrite queries overloading the database on the fly.
Application
A
ProxySQL
• Simply buy time until application can be modified
Application
B
MySQL
Master
MySQL
Slave
MySQL
Slave
MySQL
Slave
Query
Rewriting
MySQL
Slave
MySQL
Slave
21
Advanced Queries with ProxySQL –
Query retry
• Server failures or maintenance do not loose a query.
• Fails over and resubmits the query to another host.
Application
A
ProxySQL
• Improved operation and new way of handling slaves.
Application
B
MySQL
Master
MySQL
Slave
MySQL
Slave
MySQL
Slave
Query
Retry
MySQL
Slave
MySQL
Slave
22
Advanced Queries with ProxySQL –
Query routing
• Selective routing based on importance.
• Use metrics based on stats_mysql_query_digest and decide
Application
A
ProxySQL
• Go beyond read/write split.
Application
B
MySQL
Master
MySQL
Slave
MySQL
Slave
MySQL
Slave
Query
Routing
MySQL
Slave
MySQL
Slave
23
Advanced Queries with ProxySQL –
Query mirroring
• Mirror incoming queries to different back ends
• Use it for audit, analytics, cache warming, benchmarking.
Application
A
ProxySQL
Application
B
Query
Mirroring
MySQL
Master
Host A
Host B
MySQL
Slave
MySQL
Master
MySQL
Slave
24
Advanced Queries with ProxySQL
Query caching Query Timeout
Query Retry
Query Blocking
Query Routing
and Mirroring
25
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)
• Up to 1M client connections
• 1600 backend servers
• 2000 query rules
• 100k distinct users
• up to 750k QPS
DATABASE
PERFORMANCE
MATTERS

Proxysql use case scenarios fosdem17

  • 1.
    ProxySQL Use Case Scenarios FOSDEMFEB 3 2017 Alkin Tezuysal
  • 2.
    2 Who am I? •Alkin Tezuysal Sr. Technical Manager, Percona @ask_dba
  • 3.
    3 Top 5 reasonsto use ProxySQL • Improve database operations. • Understand and solve performance issues. • Create a proxy layer to shield the database. • Add High-Availability to database topology. • Empower the DBAs with great tool.
  • 4.
    4 ProxySQL Highlights Scalability HighAvailability Advanced Query Support Manageability
  • 5.
    5 Use case overview- Scalability Connection Pooling and Multiplexing Add connection pooling layer Reduce connection thread overhead Read / Write Split More scalability for any MySQL topology Must for any heavy workloads Read / Write Sharding Effortless sharding implementation Without Dev. support and cost savings
  • 6.
    6 Use case overview- High Availability Seamless Failover Gracef ul failover support Query rerouting Load Balancing Allows easy scaling For better utilization of servers Cluster Aware Supports PXC/Galera implementations Small footprint for big gain
  • 7.
    7 Use case overview- Advanced Queries Query caching Cache frequently used data Adds another cache layer Query rewrite Add SQL flexibility Faster problem solving Query blocking Add database aware firewall Without App. support
  • 8.
    8 Use case overview- Advanced Queries Query mirroring Audit, Analyze, Review, Cache Warming Allow benchmarking on live data Query throttling Set prioritization for important queries Allows manual intervention to problem queries Query timeout Add another timeout layer Flexible query level timeout
  • 9.
    9 Use case overview- Manageability Admin Utility Authentication support Limit user access to database pool Runtime reconfiguration On the fly modifications Configure database without restart or downtime Monitoring Stats collection and reporting Investigate database workload
  • 10.
    10 Scalability with ProxySQL- Connection Pooling • Any application without persistent connection to database • PHP applications to be specific without built in connection pool Application MySQLProxySQL • Reduces number of new connections to the database
  • 11.
    11 Scalability with ProxySQL– Connection Multiplexing • Any application with persistent connection to database • Java applications to be specific with built in connection pools Application Pool MySQL • Reduce connections similar to Aurora • Testing being performed for 300K database connections Application Pool Application Pool ProxySQL
  • 12.
    12 Scalability with ProxySQL- Read/Write Split • On the fly Read / Write implementation • Use read_only flag to switch traffic Application MySQL Master • Load balancing made easy MySQL Slave Write hostgroups Read hostgroups MySQL Slave
  • 13.
    13 Scalability with ProxySQL– User and schema level sharding • Granular sharding per username and schema • Backend pooling based on user activity to specific schema Application User A ProxySQL • Use advanced sharding to parallelize queries • Scale beyond the sharding per host limitations. Application User B MySQL Master MySQL Slave MySQL Master MySQL Slave MySQL Master MySQL Slave
  • 14.
    14 MySQL SlaveMySQL Master HighAvailability with ProxySQL – Seamless failover • Neither VIP setup nor service discovery needed • Use read_only flag to switch traffic Application Pool MySQL Master • Integration with other HA Managers Application Pool Application Pool ProxySQL
  • 15.
    15 High Availability withProxySQL – Improve Multi DC implementation • No connection pools latency on SSL connections. • Costly delays across the water. MySQL MasterProxySQL MySQL Master ProxySQL Application DC1 DC2
  • 16.
    16 High Availability withProxySQL – Adoption to Clustering • PXC / Galera / Group Replication MySQL ProxySQL • ProxySQL Application Node 1 Application Application MySQL Node 2 MySQL Node 3
  • 17.
    17 Advanced Queries withProxySQL – Caching • Improve performance on read intensive workloads • Reduce slave provisioning Application A ProxySQL • Improved query cache over default implementation • Query aware caching over general caching Application B MySQL Master MySQL Slave MySQL Slave MySQL Slave Cache MySQL Slave MySQL Slave
  • 18.
    18 Advanced Queries withProxySQL – Query Timeout • Built in query killer a.k.a query sniper • Adjustable threshold based on query rule Application A ProxySQL • No idle or long running queries Application B MySQL Master MySQL Slave MySQL Slave MySQL Slave Query Timeouts MySQL Slave MySQL Slave
  • 19.
    19 Advanced Queries withProxySQL – Firewall • Protect database from unwanted traffic • Stop unwanted user, account , application (new code) Application A ProxySQL • Fast modification to database behavior • Added protection for DDOS and other attacks. Application B Query Blocking MySQL Master MySQL Slave MySQL Master MySQL Slave MySQL Master MySQL Slave
  • 20.
    20 Advanced Queries withProxySQL – Query rewrite engine • Most wanted feature by DBAs • Rewrite queries overloading the database on the fly. Application A ProxySQL • Simply buy time until application can be modified Application B MySQL Master MySQL Slave MySQL Slave MySQL Slave Query Rewriting MySQL Slave MySQL Slave
  • 21.
    21 Advanced Queries withProxySQL – Query retry • Server failures or maintenance do not loose a query. • Fails over and resubmits the query to another host. Application A ProxySQL • Improved operation and new way of handling slaves. Application B MySQL Master MySQL Slave MySQL Slave MySQL Slave Query Retry MySQL Slave MySQL Slave
  • 22.
    22 Advanced Queries withProxySQL – Query routing • Selective routing based on importance. • Use metrics based on stats_mysql_query_digest and decide Application A ProxySQL • Go beyond read/write split. Application B MySQL Master MySQL Slave MySQL Slave MySQL Slave Query Routing MySQL Slave MySQL Slave
  • 23.
    23 Advanced Queries withProxySQL – Query mirroring • Mirror incoming queries to different back ends • Use it for audit, analytics, cache warming, benchmarking. Application A ProxySQL Application B Query Mirroring MySQL Master Host A Host B MySQL Slave MySQL Master MySQL Slave
  • 24.
    24 Advanced Queries withProxySQL Query caching Query Timeout Query Retry Query Blocking Query Routing and Mirroring
  • 25.
    25 Clustered ProxySQL atscale 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) • Up to 1M client connections • 1600 backend servers • 2000 query rules • 100k distinct users • up to 750k QPS
  • 26.