Followup: On IPs, hostnames, and MySQL
Back in April, I wrote On IPs, hostnames, and MySQL, which described the (sometimes surprising) ways in which MySQL deals with IP addresses, hostnames, and privileges, as well as some basics about the host cache itself. In a footnote to that post, I mentioned a patch I had written against MySQL 4.1 to give some more visibility into the host cache.
Over the past two days, I have worked on porting that patch to MySQL 5.01, 2, and making some fairly large improvements to it. The patch implements a few things:
- Configurable Size — Without the patch, the size of the cache is fixed at 128 entries, and can only be changed by changing a #define and recompiling. You may now tune the size of the host cache using SET GLOBAL host_cache_size=X.
- Metrics — You may now see how well the cache is performing using SHOW GLOBAL STATUS LIKE ‘Host%’. (See example below.)
- Display — You may now see the complete contents of the cache using SHOW HOST CACHE. (See example below.)
The above new features should give MySQL DBAs much better insight into what’s happening in their MySQL server, in an area where there has historically been very little information and a lot of misunderstandings.
Now, for the examples:
SHOW GLOBAL STATUS LIKE ‘Host%’
mysql> show status like 'host%'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | Host_cache_free | 127 | | Host_cache_hits | 2 | | Host_cache_inserts | 1 | | Host_cache_misses | 1 | | Host_cache_prunes | 0 | | Host_cache_used | 1 | +--------------------+-------+ 6 rows in set (0.01 sec)
SHOW HOST CACHE
mysql> show host cache; +-----------+----------+--------+------+ | IP | Hostname | Errors | Hits | +-----------+----------+--------+------+ | 10.0.0.22 | hiriko | 0 | 2 | +-----------+----------+--------+------+ 1 row in set (0.00 sec)
Enjoy!
1 Hopefully this will be accepted into MySQL 5.0. Brian?
2 The patch is against mysql-5.0.25-nightly-20060823 specifically.
September 27th, 2006 at 03:11:27
Cool!
September 27th, 2006 at 06:59:29
Nice work. Hopefully this gets into the mainline MySQL.
September 28th, 2006 at 00:59:20
Great Jeremy. For long host cache in MySQL was too much of the black box.
September 29th, 2006 at 03:53:59
Submitted this as a bug to MySQL to implement your patches. Bug #22821.
September 29th, 2006 at 04:01:04
Pretty cool Jeremy! We were just talking about this the other day as it happens!
One question - having the SHOW is great, but have you considered adding an INFORMATION_SCHEMA.HOSTS table as well? I’d love to see any new “SHOW” commands also have an INFORMATION_SCHEMA table along with them, especially >= 5.0.
Great work though!