TheRobotLearns Platform · ProxySQL: from first install to production

Tuning DNS Cache and Monitoring Retention

  • about 15 min read

Learning objectives

  • Explain how DNS blocking latency affects connections and local caching reduces repeated queries.
  • Configure mysql-monitor_local_dns_cache_ttl, mysql-monitor_local_dns_cache_refresh_interval, and mysql-monitor_local_dns_resolver_queue_maxsize.
  • Explain default DNS cache values and how TTL or refresh interval 0 disables caching.
  • Explain when cached DNS records refresh and when mysql_servers or proxysql_servers updates trigger rechecks.
  • Explain how ProxySQL round-robin balances multiple resolved addresses during socket connection.
  • Adjust mysql-monitor_history to control MySQL monitoring record retention before automatic purging.

DNS lookups block connections

Since release 2.4.5 ProxySQL DNS caching is available.

Historically, whenever a client connection took place, a Domain Name System (DNS) lookup for each client connection was performed. DNS lookup or DNS querying is a blocking process and impacts performance if the DNS server is slow or misconfigured. By caching the results, the server avoids doing a DNS lookup for each client connection for a given host.

ProxySQL DNS caching allows storing DNS records locally and re-using them in future, eliminating the need for new DNS queries. Every DNS record has a time-to-live (TTL). TTL specifies the expiry time of the record and is managed using mysql-monitor_local_dns_cache_ttl. DNS records are checked after every interval, and expired records are refreshed by issuing a DNS query. The interval value is specified in mysql-monitor_local_dns_cache_refresh_interval. By default, DNS caching is enabled with mysql-monitor_local_dns_cache_ttl = 300000 (ms) and mysql-monitor_local_dns_cache_refresh_interval = 60000 (ms); setting either variable to '0' disables DNS caching. Other than that, cached records are checked when mysql_servers and proxysql_servers tables are updated. If the domain contains multiple mapped IPs, the load is balanced among them in a round-robin fashion on socket connection.

Takeaway: DNS caching stores and reuses DNS records; updates to mysql_servers and proxysql_servers also trigger checks.

Defaults and zero disables cache

By default, DNS caching is enabled. The following query lists the DNS cache variables and their default values from global_variables:

SELECT * FROM global_variables WHERE Variable_Name LIKE 'mysql-monitor_local_dns_%';

The output returns three rows:

  • mysql-monitor_local_dns_cache_ttl: 300000 milliseconds. This is the time-to-live for each DNS record.
  • mysql-monitor_local_dns_cache_refresh_interval: 60000 milliseconds. This is the refresh interval at which monitor DNS cache entries, mysql_servers, and proxysql_servers are re-checked for new records.
  • mysql-monitor_local_dns_resolver_queue_maxsize: 128. This determines how much the DNS resolver queue can grow before starting new monitoring helper threads, up to 32 threads.

Setting mysql-monitor_local_dns_cache_ttl or mysql-monitor_local_dns_cache_refresh_interval to '0' disables DNS caching.

DNS cache metrics are available through the stats table stats_mysql_global. Rows include:

  • MySQL_Monitor_dns_cache_queried: times the DNS cache has been queried.
  • MySQL_Monitor_dns_cache_lookup_success: times a DNS record was found in the DNS cache on lookup.
  • MySQL_Monitor_dns_cache_record_updated: times DNS records were updated (added, removed, or modified).

Takeaway: TTL, refresh interval, and queue max size define DNS cache behavior; setting TTL or refresh interval to '0' disables DNS caching.

Apply DNS cache changes

DNS caching stores DNS records locally and uses mysql-monitor_local_dns_cache_ttl to specify each record's expiry time. The refresh interval for checking records is managed by mysql-monitor_local_dns_cache_refresh_interval. DNS records are also checked when mysql_servers or proxysql_servers are updated.

You can inspect the DNS cache variables in global_variables:

SELECT * FROM global_variables WHERE Variable_Name LIKE 'mysql-monitor_local_dns_%';

For dynamic MySQL variables, apply changes by running LOAD MYSQL VARIABLES TO RUNTIME; then persist the configuration with SAVE MYSQL VARIABLES TO DISK.

After the change, query DNS cache metrics:

SELECT * FROM stats_mysql_global WHERE Variable_Name LIKE 'MySQL_Monitor_dns_cache_%';

The example query returns three rows. MySQL_Monitor_dns_cache_record_updated counts times DNS records were updated (added, removed, or modified).

Takeaway: LOAD MYSQL VARIABLES TO RUNTIME activates dynamic-variable changes, and SAVE MYSQL VARIABLES TO DISK persists them.

Tune monitor history retention

For dynamic MySQL variables, update the in-memory value and run LOAD MYSQL VARIABLES TO RUNTIME and SAVE MYSQL VARIABLES TO DISK to persist it. Unless the entry says otherwise, an invalid value is rejected during the load, and the current runtime value remains in use.

The DNS cache monitor variables can be viewed from global_variables with this query:

SELECT * FROM global_variables WHERE Variable_Name LIKE 'mysql-monitor_local_dns_%';

The query lists mysql-monitor_local_dns_cache_ttl, mysql-monitor_local_dns_cache_refresh_interval, and mysql-monitor_local_dns_resolver_queue_maxsize.

  • mysql-monitor_local_dns_cache_ttl manages the time-to-live per DNS record. TTL specifies the expiry time, and expired records are refreshed by issuing a DNS query.
  • mysql-monitor_local_dns_cache_refresh_interval is the refresh interval at which monitor DNS cache entries, mysql_servers, and proxysql_servers are rechecked for new records. The TTL and refresh interval values are shown in milliseconds.
  • mysql-monitor_local_dns_resolver_queue_maxsize determines how much the DNS resolver queue can grow before starting new monitoring helper threads, up to 32 threads.

Cached records are also checked when the mysql_servers or proxysql_servers tables are updated. If a domain has multiple mapped IPs, the load is balanced among them round-robin on socket connection.

Takeaway: Run LOAD MYSQL VARIABLES TO RUNTIME and SAVE MYSQL VARIABLES TO DISK for dynamic MySQL variables, and inspect DNS cache monitor variables through global_variables.

Disable DNS cache and check counters

SELECT * FROM global_variables
WHERE Variable_Name LIKE 'mysql-monitor_local_dns_%';

UPDATE global_variables
SET Variable_Value = '0'
WHERE Variable_Name = 'mysql-monitor_local_dns_cache_ttl';

LOAD MYSQL VARIABLES TO RUNTIME;
SAVE MYSQL VARIABLES TO DISK;

SELECT * FROM stats_mysql_global
WHERE Variable_Name LIKE 'MySQL_Monitor_dns_cache_%';

The first SELECT lists the DNS cache variables from global_variables. The UPDATE writes '0' to mysql-monitor_local_dns_cache_ttl, disabling DNS caching. LOAD MYSQL VARIABLES TO RUNTIME loads the edited value to RUNTIME. SAVE MYSQL VARIABLES TO DISK persists the configuration. The final SELECT reads DNS cache counters from stats_mysql_global.

Try it: config_layer_sim

Run SELECT * FROM global_variables WHERE Variable_Name LIKE 'mysql-monitor_local_dns_%'; and you see three default rows. Run UPDATE global_variables SET Variable_Value = '0' WHERE Variable_Name = 'mysql-monitor_local_dns_cache_ttl';. Run LOAD MYSQL VARIABLES TO RUNTIME; and SAVE MYSQL VARIABLES TO DISK;. Run the first SELECT again and you see mysql-monitor_local_dns_cache_ttl as '0'. Run SELECT * FROM stats_mysql_global WHERE Variable_Name LIKE 'MySQL_Monitor_dns_cache_%'; and you see three DNS cache metric rows.

Sources

Do more with an account

Tuning DNS Cache and Monitoring Retention — ProxySQL: from first install to production