%3CLINGO-SUB%20id%3D%22lingo-sub-1279842%22%20slang%3D%22en-US%22%3EConnecting%20efficiently%20to%20Azure%20Database%20for%20MySQL%20with%20ProxySQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1279842%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--1381096561%22%20id%3D%22toc-hId--1381096561%22%3EIntroduction%3C%2FH2%3E%0A%3CP%3EA%20main%20cause%20of%20slow%20application%20performance%20is%20inefficient%20interaction%20in%20the%20connection%20between%20the%20database%20and%20the%20application.%20Connection%20management%2C%20including%20connection%20pooling%2C%20retry%20logic%2C%20etc.%2C%20can%20significantly%20improve%20your%20database%20performance.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.proxysql.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EProxySQL%3C%2FA%3E%2C%20a%20high-performance%20MySQL%20proxy%2C%20provides%20out-of-box%20connection%20management%20for%20Azure%20Database%20for%20MySQL.%20Using%20ProxySQL%20offers%20several%20benefits%2C%20including%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIntelligent%20load%20balancing%20across%20different%20databases%3C%2FLI%3E%0A%3CLI%3ETransparent%20Read%2FWrite%20split%2C%20which%20can%20determine%20if%20a%20database%20instance%20is%20running%20so%20that%20read%20traffic%20can%20be%20redirected%20accordingly%3C%2FLI%3E%0A%3CLI%3EOut-of-box%20connection%20pooling%3C%2FLI%3E%0A%3CLI%3EIn-built%20retry%20logic%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3ENote%3A%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EProxySQL%20is%20an%20open%20source%20community%20tool.%20It%20is%20supported%20by%20Microsoft%20on%20a%20best%20effort%20basis.%20In%20order%20to%20get%20production%20support%20with%20authoritative%20guidance%2C%20you%20can%20evaluate%20and%20reach%20out%20to%20-ERR%3AREF-NOT-FOUND-ProxySQL%20Product%20support.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImportant%3C%2FSTRONG%3E%3A%20Azure%20Database%20for%20MySQL%20currently%20supports%20ProxySQL%20version%202.0.6%20and%20later.%3C%2FP%3E%0A%3CP%3EThis%20blog%20post%20shows%20how%20you%20can%20boost%20your%20Azure%20Database%20for%20MySQL%20server%20performance%20using%20ProxySQL%20by%20setting%20efficient%20connection%20management%20through%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EConnection%20pooling%3C%2FLI%3E%0A%3CLI%3ERetry%20logic%3C%2FLI%3E%0A%3CLI%3EDNS-like%20functionality%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId-1106416272%22%20id%3D%22toc-hId-1106416272%22%3E%3CSPAN%3EConnection%20pooling%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EEstablishing%20new%20connections%20in%20MySQL%20is%20an%20expensive%20operation%20because%20of%20authentication%20and%20SSL%20negotiation%2C%20which%20causes%20significant%20overhead.%20The%20common%20recommendation%20for%20efficiently%20managing%20connections%20is%20to%20use%20connection%20pooling.%20A%20-ERR%3AREF-NOT-FOUND-connection%20pool%20is%20a%20cache%20of%20connections%20that%20are%20reused%20to%20accommodate%20future%20requests.%20As%20a%20result%2C%20if%20a%20new%20request%20be%20made%2C%20the%20application%20server%20will%20already%20have%20a%20connection%20available%20and%20prioritize%20the%20allocation%20of%20existing%20idle%20database%20connections.%3C%2FP%3E%0A%3CP%3EYou%20can%20use%20ProxySQL%E2%80%99s%20-ERR%3AREF-NOT-FOUND-built-in%20connection%20pooling%20with%20Azure%20Database%20for%20MySQL.%20Refer%20to%20the%20appropriate%20article%20below%20for%20detailed%20steps%20on%20setting%20up%20ProxySQL%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-mysql%2Fload-balance-read-replicas-using-proxysql-in-azure-database-for%2Fba-p%2F880042%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EProxySQL%20on%20Ubuntu%20VM%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-mysql%2Fdeploy-proxysql-as-a-service-on-kubernetes-using-azure-database%2Fba-p%2F1105959%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EProxySQL%20as%20a%20service%20in%20Kubernetes%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EBecause%20every%20workload%20is%20different%2C%20you%20may%20need%20to%20configure%20the%20number%20of%20open%20idle%20connections%20in%20the%20pool%20to%20address%20the%20needs%20of%20your%20workload.%20In%20ProxySQL%2C%20you%20use%20the%20-ERR%3AREF-NOT-FOUND-mysql-free_connections_pct%20variable%20to%20control%20the%20percentage%20of%20open%20idle%20connections%20in%20the%20pool%20out%20of%20the%20total%20number%20of%20connections%20for%20a%20specific%20server%20in%20a%20hostgroup.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENote%3C%2FSTRONG%3E%3A%20If%20your%20application%20frequently%20establishes%20new%20connections%2C%20then%20we%20recommend%20increasing%20the%20value%20of%20mysql-free_connections_pct%20from%20the%20default%20of%2010%25%20to%20a%20value%20of%20between%2050-60%25%20%2C%20which%20will%20increase%20the%20number%20of%20open%20idle%20connections%20in%20the%20connection%20pool%20and%20improve%20the%20performance%20significantly.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImportant%3A%26nbsp%3B%3C%2FSTRONG%3E%3CSTRONG%3Ewait_timeout%20%3C%2FSTRONG%3Eis%20the%20number%20of%20seconds%20the%20server%20waits%20for%20activity%20on%20a%20noninteractive%20connection%20before%20closing%20it.%26nbsp%3BThe%20pooled%20connection%20will%20get%20terminated%20after%20the%20value%20of%20wait_timeout%20is%20reached.%20Please%20make%20sure%20to%20increase%20the%20value%20of%20%3CSTRONG%3Ewait_timeout%20%3C%2FSTRONG%3Eaccording%20to%20your%20workload%20to%20maintain%20the%20idle%20connection%20in%20the%20connection%20pool.%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--701038191%22%20id%3D%22toc-hId--701038191%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId-1786474642%22%20id%3D%22toc-hId-1786474642%22%3E%3CSPAN%3ERetry%20logic%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EProxySQL%20provides%20out-of-the-box%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fsysown%2Fproxysql%2Fwiki%2FGlobal-variables%23mysql-free_connections_pct%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eretry%20logic%3C%2FA%3E%2C%20which%20is%20recommended%20for%20handling%20-ERR%3AREF-NOT-FOUND-transient%20errors%20that%20can%20occur%20(e.g.%20as%20a%20result%20of%20hardware%20or%20network%20failure).%20Transient%20errors%20typically%20manifest%20as%20dropped%20connections%20to%20a%20database%20server%20or%20an%20inability%20to%20open%20new%20connections%20to%20a%20server.%20These%20types%20of%20errors%20ultimately%20resolve%20themselves%2C%20and%20most%20are%20automatically%20mitigated%20by%20the%20system%20in%20under%2060%20seconds.%3C%2FP%3E%0A%3CP%3EIn%20ProxySQL%2C%20configure%20the%20-ERR%3AREF-NOT-FOUND-mysql-query_retries_on_failure%20parameter%20to%20specify%20the%20number%20of%20times%20a%20query%20will%20be%20retried.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1817931180%22%20id%3D%22toc-hId--1817931180%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH2%20id%3D%22toc-hId--1828434284%22%20id%3D%22toc-hId--1828434284%22%3E%3CSPAN%3EConfiguring%20DNS%20alias%20like%20functionality%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EWhile%20connecting%20to%20your%20database%20server%2C%20you%20may%20want%20to%20configure%20an%20alias%20for%20multiple%20reasons%2C%20including%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EDuring%20initial%20development%2C%20your%20alias%20can%20refer%20to%20a%20test%20MySQL%20database%20server.%20When%20the%20application%20goes%20live%2C%20you%20can%20modify%20the%20alias%20to%20refer%20to%20the%20production%20server.%20The%20transition%20from%20test%20to%20production%20requires%20no%20modification%20to%20the%20configuration%20of%20several%20clients%20that%20connect%20to%20the%20database%20server.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%20style%3D%22font-family%3A%20inherit%3B%22%3ENote%3C%2FSTRONG%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%3A%20If%20you%20are%20using%20ProxySQL%20for%20the%20above%20functionality%2C%20then%20you%20have%20to%20create%20a%20database%20user%20in%20your%20production%20server%20to%20allow%20ProxySQL%20to%20connect%20to%20it.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EDuring%20a%20regional%20outage%20you%20use%20geo-restore%20to%20recover%20your%20server%20in%20a%20different%20server%20and%20region.%20You%20can%20modify%20your%20existing%20alias%20to%20point%20to%20the%20new%20server%20so%20that%20the%20existing%20client%20application%20could%20re-connect%20to%20it%20without%20changing%20configurations%20on%20several%20clients.%3C%2FLI%3E%0A%3CLI%3EWhen%20you%20are%20using%20point-in-time%20restore%20to%20restore%20your%20Azure%20Database%20for%20MySQL%2C%20which%20will%20create%20a%20new%20server%20and%20do%20not%20want%20to%20update%20the%20connection%20properties%20on%20several%20clients.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EYou%20can%20use%20ProxySQL%20to%20achieve%20the%20DNS%20alias%20like%20functionality%20for%20Azure%20Database%20for%20MySQL.%20To%20better%20illustrate%20how%20you%20can%20achieve%20DNS%20alias%20like%20functionality%2C%20consider%20the%20example%20of%20-ERR%3AREF-NOT-FOUND-point-in-time%20restore.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAssume%20that%20you%20have%20an%20Azure%20Database%20for%20MySQL%20server%20(%3CSTRONG%3E%3CEM%3E%3CFONT%20color%3D%22%233366FF%22%3Emydemoserver.mysql.database.azure.com%3C%2FFONT%3E%3C%2FEM%3E%3C%2FSTRONG%3E)%20and%20ProxySQL%20is%20set%20up%20to%20connect%20to%20this%20server.%20You%20can%20learn%20more%20about%20this%20set%20up%20in%20my%20blog%20post%20-ERR%3AREF-NOT-FOUND-here.%20Now%2C%20you%20want%20to%20restore%20%E2%80%9C%3CFONT%20color%3D%22%233366FF%22%3E%3CEM%3E%3CSTRONG%3E%3CFONT%20color%3D%22%233366FF%22%3E%3CEM%3E%3CSTRONG%3Emydemoserver%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FFONT%3E%E2%80%9D%20using%20point-in-time%20restore%2C%20which%20will%20create%20a%20new%20server%20(%3CEM%3E%3CSTRONG%3E%3CFONT%20color%3D%22%233366FF%22%3E%3CEM%3E%3CSTRONG%3E%3CFONT%20color%3D%22%233366FF%22%3Emydemoserver%3CFONT%20color%3D%22%23800000%22%3E%3CFONT%20color%3D%22%23800000%22%3Enew%3C%2FFONT%3E%3C%2FFONT%3E.mysql.database.azure.com%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FEM%3E).%20With%20ProxySQL%2C%20you%20just%20have%20to%20log%20in%20to%20the%3C%2FP%3E%0A%3CP%3EProxySQL%20admin%20console%20and%20update%20the%20connection%20properties%20in%20the%20%3CFONT%20color%3D%22%230000FF%22%3E%3CEM%3E%3CSTRONG%3Emysql_servers%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FFONT%3E%20table%20with%20the%20new%20server%20name%20(%3CEM%3E%3CSTRONG%3E%3CFONT%20color%3D%22%230000FF%22%3Emydemoserver%3CFONT%20color%3D%22%23993366%22%3Enew%3C%2FFONT%3E.mysql.database.azure.com%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FEM%3E).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20didn%E2%80%99t%20have%20ProxySQL%20set%20up%20in%20the%20example%20scenario%20above%2C%20then%20you%E2%80%99d%20have%20to%20change%20the%20connection%20string%20in%20your%20application%2C%20which%20isn%E2%80%99t%20always%20feasible.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIf%20you%20have%20any%20questions%20or%20trouble%20setting%20up%20ProxySQL%20using%20Azure%20Database%20for%20MySQL%2C%20please%20contact%20the%20Azure%20Database%20for%20MySQL%20team%20at%20%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-AskAzureDBforMySQL%40service.microsoft.com%3CSPAN%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThank%20you!%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EAmol%20Bhatnagar%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EProgram%20Manager%20-%20Microsoft%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1279842%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20blog%20post%20shows%20how%20you%20can%20boost%20your%20Azure%20Database%20for%20MySQL%20server%20performance%20using%20ProxySQL%20by%20setting%20efficient%20connection%20management.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1279842%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EConnecting%20efficiently%20to%20Azure%20Database%20for%20MySQL%20with%20ProxySQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Introduction

A main cause of slow application performance is inefficient interaction in the connection between the database and the application. Connection management, including connection pooling, retry logic, etc., can significantly improve your database performance.

ProxySQL, a high-performance MySQL proxy, provides out-of-box connection management for Azure Database for MySQL. Using ProxySQL offers several benefits, including:

  • Intelligent load balancing across different databases
  • Transparent Read/Write split, which can determine if a database instance is running so that read traffic can be redirected accordingly
  • Out-of-box connection pooling
  • In-built retry logic

Note:

ProxySQL is an open source community tool. It is supported by Microsoft on a best effort basis. In order to get production support with authoritative guidance, you can evaluate and reach out to ProxySQL Product support.

 

Important: Azure Database for MySQL currently supports ProxySQL version 2.0.6 and later.

This blog post shows how you can boost your Azure Database for MySQL server performance using ProxySQL by setting efficient connection management through:

  • Connection pooling
  • Retry logic
  • DNS-like functionality

Connection pooling

Establishing new connections in MySQL is an expensive operation because of authentication and SSL negotiation, which causes significant overhead. The common recommendation for efficiently managing connections is to use connection pooling. A connection pool is a cache of connections that are reused to accommodate future requests. As a result, if a new request be made, the application server will already have a connection available and prioritize the allocation of existing idle database connections.

You can use ProxySQL’s built-in connection pooling with Azure Database for MySQL. Refer to the appropriate article below for detailed steps on setting up ProxySQL:

Because every workload is different, you may need to configure the number of open idle connections in the pool to address the needs of your workload. In ProxySQL, you use the mysql-free_connections_pct variable to control the percentage of open idle connections in the pool out of the total number of connections for a specific server in a hostgroup.

 

Note: If your application frequently establishes new connections, then we recommend increasing the value of mysql-free_connections_pct from the default of 10% to a value of between 50-60% , which will increase the number of open idle connections in the connection pool and improve the performance significantly.

Important: wait_timeout is the number of seconds the server waits for activity on a noninteractive connection before closing it. The pooled connection will get terminated after the value of wait_timeout is reached. Please make sure to increase the value of wait_timeout according to your workload to maintain the idle connection in the connection pool. 

 

Retry logic

ProxySQL provides out-of-the-box retry logic, which is recommended for handling transient errors that can occur (e.g. as a result of hardware or network failure). Transient errors typically manifest as dropped connections to a database server or an inability to open new connections to a server. These types of errors ultimately resolve themselves, and most are automatically mitigated by the system in under 60 seconds.

In ProxySQL, configure the mysql-query_retries_on_failure parameter to specify the number of times a query will be retried.

 

Configuring DNS alias like functionality

While connecting to your database server, you may want to configure an alias for multiple reasons, including:

  • During initial development, your alias can refer to a test MySQL database server. When the application goes live, you can modify the alias to refer to the production server. The transition from test to production requires no modification to the configuration of several clients that connect to the database server.

Note: If you are using ProxySQL for the above functionality, then you have to create a database user in your production server to allow ProxySQL to connect to it.

  • During a regional outage you use geo-restore to recover your server in a different server and region. You can modify your existing alias to point to the new server so that the existing client application could re-connect to it without changing configurations on several clients.
  • When you are using point-in-time restore to restore your Azure Database for MySQL, which will create a new server and do not want to update the connection properties on several clients.

You can use ProxySQL to achieve the DNS alias like functionality for Azure Database for MySQL. To better illustrate how you can achieve DNS alias like functionality, consider the example of point-in-time restore.

 

Assume that you have an Azure Database for MySQL server (mydemoserver.mysql.database.azure.com) and ProxySQL is set up to connect to this server. You can learn more about this set up in my blog post here. Now, you want to restore “mydemoserver” using point-in-time restore, which will create a new server (mydemoservernew.mysql.database.azure.com). With ProxySQL, you just have to log in to the

ProxySQL admin console and update the connection properties in the mysql_servers table with the new server name (mydemoservernew.mysql.database.azure.com).

 

If you didn’t have ProxySQL set up in the example scenario above, then you’d have to change the connection string in your application, which isn’t always feasible.

 

If you have any questions or trouble setting up ProxySQL using Azure Database for MySQL, please contact the Azure Database for MySQL team at AskAzureDBforMySQL@service.microsoft.com.

 

Thank you!

Amol Bhatnagar

Program Manager - Microsoft