JoyceBabu
12-12-2008, 02:13 AM
MySQL Query Cache
I enabled MySQL query cache for my server yesterday. This is the current status. I couldn't understand much from it. But from the values of Qcache_hits and Qcache_inserts, I guess query cache is not doing much good. Can anyone please tell me whether I should continue using it or not?
Quote:
Qcache_free_blocks - 6
Qcache_free_memory - 9492744
Qcache_hits - 22297
Qcache_inserts - 10800
Qcache_lowmem_prunes - 0
Qcache_not_cached - 39262
Qcache_queries_in_cache - 3157
Qcache_total_blocks - 6821
__________________
~JKBNumerology Compatibility Astrology
matthew90
12-12-2008, 04:59 PM
If you have a lot of selects, mysql caching will be great. If you are using multiple inserts and relatively not selecting as much it will cause more problems than help.
The Universes
12-12-2008, 05:28 PM
Show us the total queries executed.
Basically that says 22297 queries were able to take advantage of he qcache, but you also need to know how many queries in total were run.
I also suggest you run something like MySQL Tuner and Tuning Primer to get a better idea of the other variables of MySQL.
__________________The Universes - Server/VPS Management and PHP/MySQL Application Development
JoyceBabu
12-13-2008, 02:30 AM
Quote:
Originally Posted by matthew90
If you have a lot of selects, mysql caching will be great. If you are using multiple inserts and relatively not selecting as much it will cause more problems than help.
I have tables that are updated every half an hour to tables that are updated less than once a month.
Quote:
Originally Posted by The Universes
Show us the total queries executed.
Basically that says 22297 queries were able to take advantage of he qcache, but you also need to know how many queries in total were run.
I also suggest you run something like MySQL Tuner and Tuning Primer to get a better idea of the other variables of MySQL.
Both MySQL Tuner and Tuning Primer are saying that Query Cache is not enabled
Quote:
mysqld is alive
-- MYSQL PERFORMANCE TUNING PRIMER --
- By: Matthew Montgomery -
MySQL Version 5.0.45 i686
Uptime = 0 days 23 hrs 49 min 23 sec
Avg. qps = 6
Total Questions = 560486
Threads Connected = 19
Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations
To find out more information on how each of these
runtime variables effects performance visit:http://dev.mysql.com/doc/refman/5.0/...variables.html
Visit http://www.mysql.com/products/enterprise/advisors.html
for info about MySQL's Enterprise Monitoring and Advisory Service
SLOW QUERIES
The slow query log is NOT enabled.
Current long_query_time = 10 sec.
You have 0 out of 560507 that take longer than 10 sec. to complete
Your long_query_time may be too high, I typically set this under 5 sec.
BINARY UPDATE LOG
The binary update log is NOT enabled.
You will not be able to do point in time recovery
See http://dev.mysql.com/doc/refman/5.0/...-recovery.html
WORKER THREADS
Current thread_cache_size = 0
Current threads_cached = 0
Current threads_per_sec = 1
Historic threads_per_sec = 0
Your thread_cache_size is fine
MAX CONNECTIONS
Current max_connections = 100
Current threads_connected = 19
Historic max_used_connections = 40
The number of used connections is 40% of the configured maximum.
Your max_connections variable seems to be fine.
MEMORY USAGE
Max Memory Ever Allocated : 42 M
Configured Max Per-thread Buffers : 80 M
Configured Max Global Buffers : 10 M
Configured Max Memory Limit : 90 M
Physical Memory : 512.00 M
Max memory limit seem to be within acceptable norms
KEY BUFFER
Current MyISAM index space = 19 M
Current key_buffer_size = 16 K
Key cache miss rate is 1 : 81
Key buffer fill ratio = 73.00 %
Your key_buffer_size seems to be fine
QUERY CACHE
Query cache is supported but not enabled
Perhaps you should set the query_cache_size
SORT OPERATIONS
Current sort_buffer_size = 64 K
Current read_rnd_buffer_size = 252 K
Sort buffer seems to be fine
JOINS
Current join_buffer_size = 132.00 K
You have had 317 queries where a join could not use an index properly
You should enable "log-queries-not-using-indexes"
Then look for non indexed joins in the slow query log.
If you are unable to optimize your queries you may want to increase your
join_buffer_size to accommodate larger joins in one pass.
Note! This script will still suggest raising the join_buffer_size when
ANY joins not using indexes are found.
OPEN FILES LIMIT
Current open_files_limit = 1024 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine
TABLE CACHE
Current table_cache value = 4 tables
You have a total of 793 tables
You have 4 open tables.
Current table_cache hit rate is 0%, while 100% of your table cache is in use
You should probably increase your table_cache
TEMP TABLES
Current max_heap_table_size = 16 M
Current tmp_table_size = 32 M
Of 29760 temp tables, 37% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Perhaps you should increase your tmp_table_size and/or max_heap_table_size
to reduce the number of disk-based temporary tables
Note! BLOB and TEXT columns are not allow in memory tables.
If you are using these columns raising these values might not impact your
ratio of on disk temp tables.
TABLE SCANS
Current read_buffer_size = 252 K
Current table scan ratio = 439 : 1
read_buffer_size seems to be fine
TABLE LOCKING
Current Lock Wait ratio = 1 : 8542
Your table locking seems to be fine
Quote:
>> MySQLTuner 1.0.0 - Major Hayden <major@mhtx.net>
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.0.45
[OK] Operating on 32-bit architecture with less than 2GB RAM
-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[!!] InnoDB is enabled but isn't being used
Argument "" isn't numeric in numeric gt (>) at mysqltuner.pl line 495 (#1)
(W numeric) The indicated string was fed as an argument to an operator
that expected a numeric value instead. If you're fortunate the message
will identify which operator was so unfortunate.
[OK] Total fragmented tables:
-------- Performance Metrics -------------------------------------------------
[--] Up for: 23h 14m 50s (550K q [6.575 qps], 66K conn, TX: 1B, RX: 43M)
[--] Reads / Writes: 77% / 23%
[--] Total buffers: 26.0M global + 824.0K per thread (100 max threads)
[OK] Maximum possible memory usage: 106.5M (20% of installed RAM)
[OK] Slow queries: 0% (0/550K)
[OK] Highest usage of available connections: 40% (40/100)
Argument "" isn't numeric in numeric eq (==) at mysqltuner.pl line 679 (#1)
[!!] None of your MyISAM tables are indexed - add indexes immediately
[!!] Query cache is disabled
[!!] Sorts requiring temporary tables: 15% (5K temp sorts / 34K sorts)
[!!] Joins performed without indexes: 311
[!!] Temporary tables created on disk: 27% (10K on disk / 39K total)
[!!] Thread cache is disabled
[!!] Table cache hit rate: 0% (4 open / 81K opened)
[OK] Open file limit used: 0% (2/1K)
[OK] Table locks acquired immediately: 99% (268K immediate / 268K locks)
-------- Recommendations -----------------------------------------------------
General recommendations:
Add skip-innodb to MySQL configuration to disable InnoDB
MySQL started within last 24 hours - recommendations may be inaccurate
Enable the slow query log to troubleshoot bad queries
Adjust your join queries to always utilize indexes
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries without LIMIT clauses
Set thread_cache_size to 4 as a starting value
Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
query_cache_size (>= 8M)
sort_buffer_size (> 63K)
read_rnd_buffer_size (> 252K)
join_buffer_size (> 128.0K, or always use indexes with joins)
tmp_table_size (> 32M)
max_heap_table_size (> 16M)
thread_cache_size (start at 4)
table_cache (> 4)
__________________
~JKBNumerology Compatibility Astrology
JoyceBabu
12-13-2008, 02:41 AM
the value 'query_cache_size' was reset to zero after a server restart. I have set my server to automatically restart every day. Can someone tell me how to permanently enable Query Cache?
@The Universes
Can you plz tell me how to find out the total number of executed queries?
__________________
~JKBNumerology Compatibility Astrology
The Universes
12-13-2008, 04:45 AM
Put this in your my.cnf under "[mysqld]":
Quote:
query_cache_type=1
You should also have this set in your my.cnf:
Quote:
query_cache_limit=[value goes here]
query_cache_size=[value goes here]
Total queries:
Quote:
Total Questions = 560486
There should be no need to have the MySQL daemon restart daily.
__________________The Universes - Server/VPS Management and PHP/MySQL Application Development
JoyceBabu
12-13-2008, 06:06 AM
Quote:
Originally Posted by The Universes
Put this in your my.cnf under "[mysqld]":
You should also have this set in your my.cnf:
Total queries:
Thanks.
Quote:
Originally Posted by The Universes
There should be no need to have the MySQL daemon restart daily.
I am on a VPS and my RAM usage after restarting my server is around 200MB. But slowly it increases and at the end of the day, the server runs out of RAM. Hence I have created a cron job to restart the server every day.
__________________
~JKBNumerology Compatibility Astrology
JoyceBabu
12-13-2008, 09:10 AM
I don't understand. I have configured my development server and production server to use query caching. Unfortunately, the production server is not caching all queries.
Both my develpment and productions server is configured the same
Quote:
mysql> show variables like 'query%';
+------------------------------+----------+
| Variable_name | Value |
+------------------------------+----------+
| query_alloc_block_size | 8192 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 19999744 |
| query_cache_type | ON |
| query_cache_wlock_invalidate | OFF |
| query_prealloc_size | 8192 |
+------------------------------+----------+
7 rows in set (0.00 sec)
After that I benchmarked both servers.
ab -c 5 -n 100 http://myserver
Then I checked the query cache status.
For Local Server
Quote:
mysql> show status like 'qc%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 19814128 |
| Qcache_hits | 7229 |
| Qcache_inserts | 46 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 39 |
| Qcache_queries_in_cache | 34 |
| Qcache_total_blocks | 79 |
+-------------------------+----------+
8 rows in set (0.00 sec)
Response time decreased by about 1000 ms to 40 ms.
Production Server
Quote:
mysql> show status like 'qc%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 2 |
| Qcache_free_memory | 18494280 |
| Qcache_hits | 338 |
| Qcache_inserts | 411 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 2388 |
| Qcache_queries_in_cache | 240 |
| Qcache_total_blocks | 524 |
+-------------------------+----------+
8 rows in set (0.00 sec)
(This includes hits to other parts of my site, since it was performed on a live server).
There was no performance increase.
Can anyone please tell me where I went wrong?
__________________
~JKBNumerology Compatibility Astrology
Last edited by JoyceBabu : 12-13-2008 at 08:14 AM.
JoyceBabu
12-14-2008, 10:53 AM
I am still in the darkness. Query caching is not working as intended
__________________
~JKBNumerology Compatibility Astrology