...even surpassing it's theorically maximum possible allocation.
[OK] Maximum possible memory usage: 7.3G (46% of installed RAM)
There is not actually a way to calculate maximum possible memory usage for MySQL, because there is no cap on the memory it can request from the system.
The calculation done by mysqltuner.pl is only an estimate, based on a formula that doesn't take into account all possible variables, because if all possible variables were taken into account, the answer would always be "infinite." It's unfortunate that it's labeled this way.
Here is my theory on what's contributing to your excessive memory usage:
thread_cache_size = 128
Given that your max_connections
is set to 200, the value of 128 for thread_cache_size
seems far too high. Here's what makes me think this might be contributing to your problem:
When a thread is no longer needed, the memory allocated to it is released and returned to the system unless the thread goes back into the thread cache. In that case, the memory remains allocated.
http://dev.mysql.com/doc/refman/5.6/en/memory-use.html
If your workload causes even an occasional client thread to require a large amount of memory, those threads may be holding onto that memory, then going back to the pool and sitting around, continuing to hold on to memory they don't technically "need" any more, on the premise that holding on to the memory is less costly than releasing it if you're likely to need it again.
I think it's worth a try to do the following, after first making a note of how much memory MySQL is using at the moment.
Note how many threads are currently cached:
mysql> show status like 'Threads_cached';
+----------------+-------+
| Variable_name | Value |
+----------------+-------+
| Threads_cached | 9 |
+----------------+-------+
1 row in set (0.00 sec)
Next, disable the thread cache.
mysql> SET GLOBAL thread_cache_size = 0;
This disables the thread cache, but the cached threads will stay in the pool until they're used one more time. Disconnect from the server, then reconnect and repeat.
mysql> show status like 'Threads_cached';
Continue disconnecting, reconnecting, and checking until the counter reaches 0.
Then, see how much memory MySQL is holding.
You may see a decrease, possibly significant, and then again you may not. I tested this on one of my systems, which had 9 threads in the cache. Once those threads had all been cleared out of the cache, the total memory held by MySQL did decrease... not by much, but it does illustrate that threads in the cache do release at least some memory when they are destroyed.
If you see a significant decrease, you may have found your problem. If you don't, then there's one more thing that needs to happen, and how quickly it can happen depends on your environment.
If the theory holds that the other threads -- the ones currently servicing active client connections -- have significant memory allocated to them, either because of recent work in their current client session or because of work requiring a lot of memory that was done by another connection prior to them languishing in the pool, then you won't see all of the potential reduction in memory consumption until those threads are allowed to die and be destroyed. Presumably your application doesn't hold them forever, but how long it will take to know for sure whether there's a difference will depend on whether you have the option of cycling your application (dropping and reconnecting the client threads) or if you'll have to just wait for them to be dropped and reconnected over time on their own.
But... it seems like a worthwhile test. You should not see a substantial performance penalty by setting thread_cache_size
to 0. Fortunately, thread_cache_size
is a dynamic variable, so you can freely change it with the server running.
Key Buffer Size
SELECT variable_value INTO @KBS
FROM information_schema.global_variables WHERE variable_name='key_buffer_size';
SELECT @KBS KeyBufferSize;
This should be the same number as
SHOW VARIABLES LIKE 'key_buffer_size';
Key Buffer in Use
SELECT variable_value INTO @KBUSED
FROM information_schema.global_status WHERE variable_name='Key_blocks_used';
SELECT variable_value INTO @KCBSIZ
FROM information_schema.global_variables WHERE variable_name='key_cache_block_size';
SET @KBINUSE = @KBUSED * @KCBSIZ;
SELECT @KBUSED KeyBlocksUsed,@KCBSIZ KeyCacheBlockSize,@KBINUSE KeyBlocksInUse;
Key Read and Write Ratios, Query Cache HitRate (based on @SECONDS_TO_TEST
)
SET @SECONDS_TO_TEST = 30;
SELECT variable_value INTO @KRDS1
FROM information_schema.global_status WHERE variable_name='Key_reads';
SELECT variable_value INTO @KRQS1
FROM information_schema.global_status WHERE variable_name='Key_read_requests';
SELECT variable_value INTO @KWRT1
FROM information_schema.global_status WHERE variable_name='Key_writes';
SELECT variable_value INTO @KWRQ1
FROM information_schema.global_status WHERE variable_name='Key_write_requests';
SELECT variable_value INTO @QCHITS1
FROM information_schema.global_status WHERE variable_name='Qcache_hits';
SELECT variable_value INTO @QCNSRT1
FROM information_schema.global_status WHERE variable_name='Qcache_inserts';
SELECT variable_value INTO @QCNC1
FROM information_schema.global_status WHERE variable_name='Qcache_not_cached';
SELECT SLEEP(@SECONDS_TO_TEST);
SELECT variable_value INTO @KRDS2
FROM information_schema.global_status WHERE variable_name='Key_reads';
SELECT variable_value INTO @KRQS2
FROM information_schema.global_status WHERE variable_name='Key_read_requests';
SELECT variable_value INTO @KWRT2
FROM information_schema.global_status WHERE variable_name='Key_writes';
SELECT variable_value INTO @KWRQ2
FROM information_schema.global_status WHERE variable_name='Key_write_requests';
SELECT variable_value INTO @QCHITS2
FROM information_schema.global_status WHERE variable_name='Qcache_hits';
SELECT variable_value INTO @QCNSRT2
FROM information_schema.global_status WHERE variable_name='Qcache_inserts';
SELECT variable_value INTO @QCNC2
FROM information_schema.global_status WHERE variable_name='Qcache_not_cached';
SET @KRQS = @KRQS2 - @KRQS1; SET @KRDS = @KRDS2 - @KRDS1;
SET @KRR = 100 - ((100 * @KRDS) / @KRQS);
SET @KWRT = @KWRT2 - @KWRT1; SET @KWRQ = @KWRQ2 - @KWRQ1;
SET @KWR = 100 - ((100 * @KWRT) / @KWRQ);
SET @QCHITS = @QCHITS2 - @QCHITS1; SET @QCNSRT = @QCNSRT2 - @QCNSRT1;
SET @QCNC = @QCNC2 - @QCNC1; SET @QCHR = 100 * @QCHITS / (@QCHITS + @QCNSRT + @QCNC);
SELECT @KRDS KeyReads,@KRQS KeyReadRequests,IFNULL(@KRR,100) KeyReadRatio,
@KWRT KeyWrites,@KWRQ KeyWriteRequests,IFNULL(@KWR,100) KeyWriteRatio,
@QCHITS QueryCacheHits,@QCNSRT QueryCacheInserts,@QCNC QueryCacheNotCached,
IFNULL(@QCHR,0) QueryCacheHitRate;
Best Answer
You are still using MyISAM ??? OUCH !!!
All kidding aside, you need two status variables:
You want the ratio Key_writes/Key_write_requests to be as close to 1 (100%) as possible. I wrote a nice set of queries you can run to see such ratios. You can find it in my
Jun 17, 2013
answer to the post MyISAM key bufferPerhaps just running
FLUSH TABLES;
will clear away whatever index changes are lingering. If your system does not do heavy writes, this is probably all you need.I recommend converting everything you have to InnoDB so your database can survive a crash. After all, you do not want any changes to an index to linger.
Take a quick look at the InnoDB Plumbing (picture from Percona CTO Vadim Tkachenko)
See the InnoDB Buffer Pool on the Left ? It has an Insert Section responsible for index changes. InnoDB would automatically flush index changes for you. No such mechanism exists for MyISAM. So, please convert to InnoDB ASAP.
UPDATE 2017-08-07 15:25 EDT
If you must go on using MyISAM, you should look into using Dedicated MyISAM Key Caches. You can create a key buffer for specific set of MyISAM tables. In your case, you would create a dedicated key cache for the one table with the FULLTEXT indexes. You would have to judge how big or how small to make the cache.
Suppose your table with the FULLTEXT indexes is
mydb.myfull
.You could then run this to find the proper size rounded up to the nearest MB
Whatever number comes back for
index_length_rounded
is the size you use.Please look up my posts about how to create Dedicated MyISAM Key Caches.
I would not worry too much about this since the INSERTs and UPDATEs seems so rare.