Mafiree logo
  • About
  • Services
  • Blogs
  • Careers
  • Products
    • orbit logo Orbit
    • streamer logo Xstreami
  • Contact
Schedule a Call
Menu
  • About
  • Services
  • Blogs
  • Careers
  • Products
    • orbit logo Orbit
    • streamer logo Xstreami
  • Contact
  • Schedule a Call
Database
Database Database Managed Services
MySQL MySQL
MySQL Consulting Services
MySQL Migration Services
MySQL Optimization & Query Tuning
MySQL Database Administration
MySQL Backup & Recovery
MySQL Security & Maintenance
MySQL Cloud Services (AWS RDS, Aurora, Google Cloud SQL, Azure)
MySQL for Ecommerce
MySQL High Availability & Replication
MongoDB MongoDB
MongoDB Consulting Services
MongoDB Migration Services
MongoDB Optimization & Query Tuning
MongoDB Database Administration
MongoDB Backup & Recovery
MongoDB Security & Maintenance
MongoDB Cloud (Atlas)
MongoDB Solutions by Industry
MongoDB High Availability & Replication
PostgreSQL PostgreSQL
PostgreSQL Consulting
PostgreSQL Migration & Upgrades
Performance Tuning & Query Optimization
PostgreSQL Administration & Managed Services
High Availability, Clustering & Replication
PostgreSQL Backup, Recovery & Disaster Planning
PostgreSQL Security, Compliance & Auditing
PostgreSQL for Analytics & Data Warehousing
PostgreSQL on Cloud & Containers
PostgreSQL Extensions & Open-Source Integrations
PostgreSQL for Every Industry
SQL Server MSSQL
MSSQL Consulting Services
MSSQL Migration Services
MSSQL Optimization & Query Tuning Services
MSSQL Database Administration Services
MSSQL Backup & Recovery Services
MSSQL High Availability & Replication Services
MSSQL Security & Compliance Services
MSSQL Performance Monitoring & Health Checks
MSSQL Solutions by Industry
Aerospike Aerospike
Aerospike Consulting Services
Aerospike Migration Services
Aerospike Performance Optimization & Tuning
Aerospike Database Administration
Aerospike Backup & Recovery
Aerospike High Availability
Aerospike Cloud & Hybrid Deployments
Aerospike for Real-Time Applications (AdTech, FinTech, Retail, IoT)
Analytics DB
Analytics DB Analytics DB Services
Clickhouse Clickhouse
ClickHouse Consulting Services
ClickHouse Migration Services
ClickHouse Optimization & Query Tuning
ClickHouse Database Administration
ClickHouse Backup & Recovery
ClickHouse Security & Maintenance
ClickHouse Cloud Services (ClickHouse Cloud, AWS, GCP, Azure)
ClickHouse Solutions by Industry
ClickHouse High Availability & Replication
TiDB TiDB
TiDB Consulting & Architecture Planning
TiDB Administration & Maintenance
TiDB Security and Privacy Maintenance
TiDB Performance & Query Optimization
TiDB Migration Services
TiDB Backup & Disaster Recovery
TiDB High Availability Solutions
TiDB Solutions by Industry
TiDB Cloud Services
ScyllaDB ScyllaDB
ScyllaDB Consulting & Architecture Planning
ScyllaDB Administration & Maintenance
ScyllaDB Security and Privacy Maintenance
ScyllaDB Performance & Query Optimization
ScyllaDB Migration Services
ScyllaDB Backup & Disaster Recovery
ScyllaDB High Availability Solutions
ScyllaDB Solutions by Industry
ScyllaDB Cloud Services
DevOps
DevOps DevOps Services
Version Control Version Control
Kubernetes Kubernetes
Infrastructure Infrastructure Management
Web Servers Web Servers
Networking
Networking Networking Services
Basic Basic
Advanced Advanced
MySQL MySQL
MongoDB MongoDB
PostgreSQL PostgreSQL
MSSQL MSSQL
Aerospike Aerospike
Clickhouse Clickhouse
TiDB TiDB
ScyllaDB ScyllaDB
Version Control Version Control
Kubernetes Kubernetes
Infrastructure Infrastructure Management
Web Servers Web Servers
Basic Basic
Advanced Advanced
MySQL Consulting Services
MySQL Migration Services
MySQL Optimization & Query Tuning
MySQL Database Administration
MySQL Backup & Recovery
MySQL Security & Maintenance
MySQL Cloud Services (AWS RDS, Aurora, Google Cloud SQL, Azure)
MySQL for Ecommerce
MySQL High Availability & Replication
MongoDB Consulting Services
MongoDB Migration Services
MongoDB Optimization & Query Tuning
MongoDB Database Administration
MongoDB Backup & Recovery
MongoDB Security & Maintenance
MongoDB Cloud (Atlas)
MongoDB Solutions by Industry
MongoDB High Availability & Replication
PostgreSQL Consulting
PostgreSQL Migration & Upgrades
Performance Tuning & Query Optimization
PostgreSQL Administration & Managed Services
High Availability, Clustering & Replication
PostgreSQL Backup, Recovery & Disaster Planning
PostgreSQL Security, Compliance & Auditing
PostgreSQL for Analytics & Data Warehousing
PostgreSQL on Cloud & Containers
PostgreSQL Extensions & Open-Source Integrations
PostgreSQL for Every Industry
MSSQL Consulting Services
MSSQL Migration Services
MSSQL Optimization & Query Tuning Services
MSSQL Database Administration Services
MSSQL Backup & Recovery Services
MSSQL High Availability & Replication Services
MSSQL Security & Compliance Services
MSSQL Performance Monitoring & Health Checks
MSSQL Solutions by Industry
Aerospike Consulting Services
Aerospike Migration Services
Aerospike Performance Optimization & Tuning
Aerospike Database Administration
Aerospike Backup & Recovery
Aerospike High Availability
Aerospike Cloud & Hybrid Deployments
Aerospike for Real-Time Applications (AdTech, FinTech, Retail, IoT)
ClickHouse Consulting Services
ClickHouse Migration Services
ClickHouse Optimization & Query Tuning
ClickHouse Database Administration
ClickHouse Backup & Recovery
ClickHouse Security & Maintenance
ClickHouse Cloud Services (ClickHouse Cloud, AWS, GCP, Azure)
ClickHouse Solutions by Industry
ClickHouse High Availability & Replication
TiDB Consulting & Architecture Planning
TiDB Administration & Maintenance
TiDB Security and Privacy Maintenance
TiDB Performance & Query Optimization
TiDB Migration Services
TiDB Backup & Disaster Recovery
TiDB High Availability Solutions
TiDB Solutions by Industry
TiDB Cloud Services
ScyllaDB Consulting & Architecture Planning
ScyllaDB Administration & Maintenance
ScyllaDB Security and Privacy Maintenance
ScyllaDB Performance & Query Optimization
ScyllaDB Migration Services
ScyllaDB Backup & Disaster Recovery
ScyllaDB High Availability Solutions
ScyllaDB Solutions by Industry
ScyllaDB Cloud Services
  1. Home
  2. > Blogs
  3. > Proxysql
  4. > Dynamic query routing with ProxySQL

Dynamic query routing with ProxySQL

How ProxySQL helps in achieving query routing without making a application changes.

Sabareesh March 15, 2021

Subscribe for email updates

Load balancers are becoming an integral part in the database world. Load balancer is an intermediate service that understands the application traffic and distributes its across available database instances.

ProxySQL is one of the advanced load balancers used in the MySQL database environment.

Here are some of the benefits of ProxySQL in the DB layer.

  • Provides intelligent load balancing between applications to multiple databases.
  • It understands database topology and monitors the health of the instances, whether the instances are up or down.
  • ProxySQL can understand the traffic that passes through it, and can split reads and writes. This is very useful in a replica setup.
  • It provides administrators with a lot of control mechanisms like query cache in the proxysql layer for quick access, Query re-routing, re-written bad queries and graceful switchover.
  • Overall, it empowers the administrator to maintain efficient operations of the entire infrastructure.

For more information, please visit our blog

This blog is about a use case, how ProxySQL helps in resolving one of the major issues we have experienced in the database.

Our setup is with Master and Replica running MySQL 5.7 version, with ProxySQL serving both reads and writes to the master DB. Replica is used for failover and backup.

 


 


Database is optimized with all the slow queries tuned, fair to say that CPU usage never crossed more than 10%. Suddenly we are noticing severe performance issues in the application, immediately we can see that CPU usage hit 100%.

On troubleshooting this, we can see that QPS tripled as can be reflected in the below chart.

This was confirmed by the application team that a new release was done, upon troubleshooting the slow query logs we are able to see one query which doesn’t have the index hitting the database very frequently. Unfortunately this is one of the biggest tables that we can’t afford to have the index right away. Apart from that, the application team was worried about rolling back the release due to business implications.

DBA has to add the index to solve the problem but that would be costly in this point which has live traffic and table size. Thankfully we have a load balancer sitting on top of database servers, we have used ProxySQL to route the query to replica and reduced the load on the master DB.

Attaching the same query:

  1. select id, user_id, product_name from product where created_on between '2020-01-01 00:00:00' and '2020-09-14 23:59:59'

It scans almost ~15 Lakhs records everytime and the occurrence of the query is very high.

As mentioned earlier, ProxySQL has provision for query re-routing and we decided to move the specified query to the slave server. Query digest / pattern needs to be identified and can be configured in ProxySQL for query-rerouting.

  1.              rule_id: 10
  2.                active: 1
  3.                digest: 0xCFF0EF06A44DA55E
  4. destination_hostgroup: 11
  5.                 apply: 1

Once these changes are done, immediately queries are moved to the replica and master DB breaths normal.

Following chart is the indication of CPU usage in master and replica after moving out the culprit queries to the replica.

After Making the changes:

 


 


Key Takeaways

 

  • Optimize the queries with DBA before every release cycle.
  • Use Load balancers, especially the one which is SQL aware.
  • Queries can be re-routed, replaced or even blocked from the database without making any application changes.

Leave a Comment

Related Blogs

ProxySQL 3.0 is Here: Top Features for MySQL & PostgreSQL Users

ProxySQL 3.0 introduces powerful capabilities like dynamic query routing, caching, multiplexing, and now PostgreSQL support. This blog explains how ProxySQL improves database performance, enables intelligent load balancing, and helps scale MySQL and PostgreSQL environments without application changes. Backed by real-world use cases from Mafiree, it provides practical insights into when and how to use ProxySQL effectively in production.

  9 views
Whats new in ProxySQL 2.0

Features of ProxySQL 2.0 Version

  2482 views
What is ProxySQL

ProxySQL is one of the advanced software load balancer that we have in market. ProxySQL has an in-built abilty to identify the reads,writes and route the write traffic to master and read traffic between the available slaves. One occurence of a Replication delay or server crash or replication breakag

  3427 views
ProxySQL Features

Query Caching - Query Routing - Mirroring - Query Rewrite - Data Masking

  2161 views

Subscribe for email updates

Get in touch with us

Highlights

More than 6000 Servers Monitored

Happy Clients

Certified DBAs

24 x 7 x 365 Support

PCI

Database Services

MySQL MongoDB PostgreSQL SQL Server Aerospike Clickhouse TiDB MariaDB Columnstore

Quick Links

Careers Blog Contact Privacy Policy Disclaimer Policy

Contacts

Linkedin Mafiree Facebook Mafiree Twitter Mafiree

Nagercoil Office

Miru IT Park, Vallankumaranvillai,

Nagercoil, Tamilnadu - 629 002.

Bangalore Office

Unit 303, Vanguard Rise,

5th Main, Konena Agrahara,

Old Airport Road, Bangalore - 560 017.

Call: +91 6383016411

Email: sales@mafiree.com


Copyright © - All Rights Reserved - Mafiree