Skip to content

Conversation

Peter-Sh
Copy link
Contributor

This pull request adds HITS column to QUERY_CACHE_INFO table of qc_info plugin.

Our case is that we plan to turn off query cache on our production server, because we believe it becomes a bottleneck in some situations.
Load testing shows that server becomes overloaded if query cache is turned off. It is because there are some queries that begin to kill server when not using query cache. The problem is to figure out what exactly are those queries.
Currently there is no way to figure out whether the query has used query cache or not. The query_cache_info plugin shows the contents of the query cache, but it does not show any usage statistics. Moreover there is no session stat variable that could help understand whether the last query result is taken directly from query cache or not.
One can save snapthots of query_cache_info table and try to make some guess by comparing this snapshots over time but this way is neither accurate nor convenient.

Another case is to use this hits statistics to tune query cache usage. The queries that have low or zero hits can be disabled with SQL_NO_CACHE hint thus increasing query cache efficiency, I think it’s pretty straightforward.

I've found an issue MDEV-4682 that is somewhat related and addresses this problem.

The issue has a pull request (which almost completely rewrites qc_info plugin) that has never been merged.
Inspired by that request I’ve made a patch which is a way smaller and adds just few lines to qc_info plugin and to sql_cache (to increment hits when query result are read from cache) and one additional column to query_cache_info table. The tests are updated accordingly.

We are using exactly this patch on MariaDb-10.1.24 at production server with almost 1TB of data, thousands of tables and about 15K tps, it is working without any problems.

I think HITS statistic for query cache should be useful for many real world cases. If you think so, please review this PR and let me know if it needs any updates.

Thanks!

Added hit_count field to Query_cache_query and methods to get and increment it.
The counter is incremented when query results are read from query cache.
Updated qc_info tests, added new test that checks HITS is incremented.
@svoj svoj self-assigned this Aug 28, 2017
@svoj svoj added this to the 10.3 milestone Aug 28, 2017
@svoj
Copy link
Contributor

svoj commented Aug 28, 2017

Hi Peter,

LGTM, thanks! I'll merge it after 10.3.1 release.

Similar to other open source projects, the MariaDB Foundation needs to have shared ownership of all code that is included in the MariaDB distribution. The easiest way to achieve this is by submitting your code under the BSD-new license.

The other alternative is to sign the code contribution agreement which can be found here: https://mariadb.com/kb/en/mariadb/mca/

Please indicate in a comment below that you are contributing your new code of the whole pull request, including one or several files that are either new files or modified ones, under the BSD-new license or that you have filled out the contribution agreement and sent it.

Thanks,
Sergey

@Peter-Sh
Copy link
Contributor Author

Hi, Sergey!

Thank you!

I confirm, that I am contributing all code of this pull request, including one or several files that are either new files or modified ones, under the BSD-new license.

I've also sent a signed copy of MCA to the email specified on mca page.

Regards,
Peter

@svoj svoj merged commit 41d89b7 into MariaDB:10.3 Aug 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants