<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Beware of MyISAM Key Cache mutex contention</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/</link>
	<description>Percona&#039;s MySQL &#38; InnoDB performance and scalability blog</description>
	<lastBuildDate>Sat, 11 Feb 2012 16:45:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Claudio</title>
		<link>http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/comment-page-1/#comment-708884</link>
		<dc:creator>Claudio</dc:creator>
		<pubDate>Tue, 12 Jan 2010 23:58:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=467#comment-708884</guid>
		<description>Peter,
you put an end to a 3 weeks long 24x7 research.

MySQL 5.0.81 on FreeBSD 7.0  4 quad core Xeon 16gb

I was just hired by a web company and they experienced mysql crazy cpu loads since more than one year which lead every now and then(once a week average) real deadlocks with up to 120 load average, mysql master restart needed and apache servers as well. At first I did standard tuning and query tuning but it seemed to make it worse! from once a week to once a day! (then I would discover that improving performance probably increased the concurrency!)
I put under monitoring all the parameters I could think of, and mysql processes showed in issue periods multiple copies of the same query, sometimes with also same parameters, and on OS side I was surprised to see exactly what you describe:
CPU context switches from 10k to 200k/300k so I observed the single mysql threads and I saw that many where stuck in [umtxn] state during issue. My first thought went to the FreeBSD scheduler, since it really looked a classic old style deadlock. Actually reserches revealed that FreeBSD is historically weak on multithreading. So I digged and digged but still I was very surprised that a 16cores monster could be put on its knees, how can the rest of the world use freebsd and be alive on web?
In the meantime the bedtime moved later and later and the investigation was moving on two tracks: FreeBSD bugs, MySQL bugs.
One of the nights I got your post: BINGO!
I immediately created 10 tailored Key Caches for each of the highest concurrency tables and after 48 hours it really seem I can confirm all you said.
Still, Still!
Sometimes we get 20/30 parallel identical queries at once that can raise the load to 8, and of course this is explained by the fact that they use the same key_cache and the table is used for fulltext search, so no InnoDB possible for now.
My question is, is it possible that it is only related to a MySQL &#039;bug&#039; ?
It really does not convince me, and I mean that even if 20 threads are locked on a resource is it possible that the scheduler of a modern operating system wastes 90% time in rounding-robin and cannot manage the concurrent access at a shared resource in a more efficient way?
I am still of the idea that FreeBSD has its responsibilities and not allow a software to put on its knees a monster 16 Xeon cores 16gb box. What is your opinion?
What do you think of Sphinx to substitute the fulltext search on MyISAM table?
Peter, I owe you a beer, big one.
Claudio</description>
		<content:encoded><![CDATA[<p>Peter,<br />
you put an end to a 3 weeks long 24&#215;7 research.</p>
<p>MySQL 5.0.81 on FreeBSD 7.0  4 quad core Xeon 16gb</p>
<p>I was just hired by a web company and they experienced mysql crazy cpu loads since more than one year which lead every now and then(once a week average) real deadlocks with up to 120 load average, mysql master restart needed and apache servers as well. At first I did standard tuning and query tuning but it seemed to make it worse! from once a week to once a day! (then I would discover that improving performance probably increased the concurrency!)<br />
I put under monitoring all the parameters I could think of, and mysql processes showed in issue periods multiple copies of the same query, sometimes with also same parameters, and on OS side I was surprised to see exactly what you describe:<br />
CPU context switches from 10k to 200k/300k so I observed the single mysql threads and I saw that many where stuck in [umtxn] state during issue. My first thought went to the FreeBSD scheduler, since it really looked a classic old style deadlock. Actually reserches revealed that FreeBSD is historically weak on multithreading. So I digged and digged but still I was very surprised that a 16cores monster could be put on its knees, how can the rest of the world use freebsd and be alive on web?<br />
In the meantime the bedtime moved later and later and the investigation was moving on two tracks: FreeBSD bugs, MySQL bugs.<br />
One of the nights I got your post: BINGO!<br />
I immediately created 10 tailored Key Caches for each of the highest concurrency tables and after 48 hours it really seem I can confirm all you said.<br />
Still, Still!<br />
Sometimes we get 20/30 parallel identical queries at once that can raise the load to 8, and of course this is explained by the fact that they use the same key_cache and the table is used for fulltext search, so no InnoDB possible for now.<br />
My question is, is it possible that it is only related to a MySQL &#8216;bug&#8217; ?<br />
It really does not convince me, and I mean that even if 20 threads are locked on a resource is it possible that the scheduler of a modern operating system wastes 90% time in rounding-robin and cannot manage the concurrent access at a shared resource in a more efficient way?<br />
I am still of the idea that FreeBSD has its responsibilities and not allow a software to put on its knees a monster 16 Xeon cores 16gb box. What is your opinion?<br />
What do you think of Sphinx to substitute the fulltext search on MyISAM table?<br />
Peter, I owe you a beer, big one.<br />
Claudio</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: huilingwei</title>
		<link>http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/comment-page-1/#comment-344894</link>
		<dc:creator>huilingwei</dc:creator>
		<pubDate>Fri, 15 Aug 2008 08:46:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=467#comment-344894</guid>
		<description>Hi Peter,
Thank you very much! 

My server memory is 1G, but the size of the data file for these ten small tables are 1.7G(ten files and each 170M), and the index files are about 400M (ten files and each 40M). From the mysql manual, mysql only cache index, and the data will use the OS cache. If there is any possible that the memory of my server is two low to cache all the DB data. So when I tried to query from multiple tables, the OS need switch between the data files, and cause the performance get worse. 

Today I also tested that reduce the data stored in DB, each table has 40M records, and the size for all the data files are about 200M. And during my testing, there is no difference for the response time no matter I access one tables or access 10 tables alternately. This time, the wa is always 10. 
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 2  0  70508 146860  24260 653572    0    0     0     0  212  2167 62 38  0  0

Thanks a lot!</description>
		<content:encoded><![CDATA[<p>Hi Peter,<br />
Thank you very much! </p>
<p>My server memory is 1G, but the size of the data file for these ten small tables are 1.7G(ten files and each 170M), and the index files are about 400M (ten files and each 40M). From the mysql manual, mysql only cache index, and the data will use the OS cache. If there is any possible that the memory of my server is two low to cache all the DB data. So when I tried to query from multiple tables, the OS need switch between the data files, and cause the performance get worse. </p>
<p>Today I also tested that reduce the data stored in DB, each table has 40M records, and the size for all the data files are about 200M. And during my testing, there is no difference for the response time no matter I access one tables or access 10 tables alternately. This time, the wa is always 10.<br />
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa<br />
 2  0  70508 146860  24260 653572    0    0     0     0  212  2167 62 38  0  0</p>
<p>Thanks a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/comment-page-1/#comment-344719</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Thu, 14 Aug 2008 23:16:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=467#comment-344719</guid>
		<description>MYD modification is buffered in OS cache and written to the hard drive asynchronously so if you have enough memory there are no IO related waits though writes do happen of course.</description>
		<content:encoded><![CDATA[<p>MYD modification is buffered in OS cache and written to the hard drive asynchronously so if you have enough memory there are no IO related waits though writes do happen of course.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/comment-page-1/#comment-344711</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Thu, 14 Aug 2008 23:01:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=467#comment-344711</guid>
		<description>huilingwei,

It is hard to comment on such issue for me without looking at in details. One thing I should note - the &quot;wa&quot; is very high in your test this means this is IO bound case which is very different story.</description>
		<content:encoded><![CDATA[<p>huilingwei,</p>
<p>It is hard to comment on such issue for me without looking at in details. One thing I should note &#8211; the &#8220;wa&#8221; is very high in your test this means this is IO bound case which is very different story.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yingkuan</title>
		<link>http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/comment-page-1/#comment-344690</link>
		<dc:creator>yingkuan</dc:creator>
		<pubDate>Thu, 14 Aug 2008 21:39:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=467#comment-344690</guid>
		<description>Hi Peter,
Correct me if I am wrong.
As I understand the MYISAM will only cache KEY in memory, when you do insert the actual data will write to table MYD file on disk directly. So in that sense, you can&#039;t achieve full memory workload, correct?</description>
		<content:encoded><![CDATA[<p>Hi Peter,<br />
Correct me if I am wrong.<br />
As I understand the MYISAM will only cache KEY in memory, when you do insert the actual data will write to table MYD file on disk directly. So in that sense, you can&#8217;t achieve full memory workload, correct?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/comment-page-1/#comment-344671</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Thu, 14 Aug 2008 20:25:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=467#comment-344671</guid>
		<description>Yingkuan,

In memory meaning tables were small enough to fit in memory completely.</description>
		<content:encoded><![CDATA[<p>Yingkuan,</p>
<p>In memory meaning tables were small enough to fit in memory completely.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: huilingwei</title>
		<link>http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/comment-page-1/#comment-344621</link>
		<dc:creator>huilingwei</dc:creator>
		<pubDate>Thu, 14 Aug 2008 08:40:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=467#comment-344621</guid>
		<description>Hi Peter,
We also met such issue that when multiple MyISAM tables are included, the performance is worse than only one MyISAM table. And even if we add cache the table index, things does not change. Could you please help to see what our problem is? Thanks a lot!

The cpu of hardware is 2.2 GHz, and the memory is 1G.

All the MyISAM tables are in the same structure, the data for them are also similar. Each table has 2M records.
The following is my MyISAM table information:

user_id &#124; int(11) 
call_id &#124; int(11) 
call_direct &#124; tinyint(4) 
my_number &#124; varchar(255)
start_time &#124; datetime 
end_time &#124; datetime 

The index for the table is: user_id+call_id

We tested to read data from the MyISAM tables with one thread and two threads. table_cache=495, Open_tables=120, Opened_tables=133.
1. Two threads and one table, the average response time is about 143ms
Thread1: access table t1 
Thread2: access table t1 
procs                      memory      swap          io     system         cpu
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 1  2  32296   8656  64572 815228    0    0  1788     0  684   692  8  4  0 88
 0  2  32296   8648  64572 815508    0    0  1792     0  678   566  2  2  0 96

2. Two thread and two tables, the average response time is about 338ms.
Thread1: access table t1 
Thread2: access table t2 
r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 2  2  30640   8764  64448 820976    0    0  1340     0  539   422  1  3  0 96
 2  2  30756   8652  64448 821040    4  116  1244   116  546   406  3  1  0 96

3. One thread and two tables, the average response time is about 137ms.

Thread1: access table t1 and table t2 alternately 

4. One thread and one table, the average response time is 77ms.

Thread1: only access table t1 

5. We tried use two thread to access MyISAM table and Innodb table, there is no such affect. Thread1 read data from t1, thread2 read data from innodb table test, the response time for thread1 is also about 80ms.

Thread1: access table t1 
Thread2: access table test (innodb)

After that, we tried cache the table index by following, but things does not change:
mysql&gt; CACHE INDEX user_call_log_entry_1, user_call_log_entry_2, user_call_log_entry_3,user_call_log_entry_4 IN  call_log_cache;
+---------------------------------+----------+----------+
&#124; Table      &#124; Op                 &#124; Msg_type &#124; Msg_text &#124;
+--------------------------------+----------+----------+
&#124; lps.user_1 &#124; assign_to_keycache &#124; status   &#124; OK       &#124;
&#124; lps.user_2 &#124; assign_to_keycache &#124; status   &#124; OK       &#124;
&#124; lps.user_3 &#124; assign_to_keycache &#124; status   &#124; OK       &#124;
&#124; lps.user_4 &#124; assign_to_keycache &#124; status   &#124; OK       &#124;
+---------------------------------+----------+----------+
4 rows in set (0.02 sec)

mysql&gt; LOAD INDEX INTO CACHE lps.user_1,lps.user_2,lps.user_3,lps.user_4 IGNORE LEAVES;
+------------+--------------+----------+----------+
&#124; Table      &#124; Op           &#124; Msg_type &#124; Msg_text &#124;
+------------+--------------+----------+----------+
&#124; lps.user_1 &#124; preload_keys &#124; status   &#124; OK       &#124;
&#124; lps.user_2 &#124; preload_keys &#124; status   &#124; OK       &#124;
&#124; lps.user_3 &#124; preload_keys &#124; status   &#124; OK       &#124;
&#124; lps.user_4 &#124; preload_keys &#124; status   &#124; OK       &#124;
+------------+--------------+----------+----------+
4 rows in set (2 min 1.85 sec)</description>
		<content:encoded><![CDATA[<p>Hi Peter,<br />
We also met such issue that when multiple MyISAM tables are included, the performance is worse than only one MyISAM table. And even if we add cache the table index, things does not change. Could you please help to see what our problem is? Thanks a lot!</p>
<p>The cpu of hardware is 2.2 GHz, and the memory is 1G.</p>
<p>All the MyISAM tables are in the same structure, the data for them are also similar. Each table has 2M records.<br />
The following is my MyISAM table information:</p>
<p>user_id | int(11)<br />
call_id | int(11)<br />
call_direct | tinyint(4)<br />
my_number | varchar(255)<br />
start_time | datetime<br />
end_time | datetime </p>
<p>The index for the table is: user_id+call_id</p>
<p>We tested to read data from the MyISAM tables with one thread and two threads. table_cache=495, Open_tables=120, Opened_tables=133.<br />
1. Two threads and one table, the average response time is about 143ms<br />
Thread1: access table t1<br />
Thread2: access table t1<br />
procs                      memory      swap          io     system         cpu<br />
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa<br />
 1  2  32296   8656  64572 815228    0    0  1788     0  684   692  8  4  0 88<br />
 0  2  32296   8648  64572 815508    0    0  1792     0  678   566  2  2  0 96</p>
<p>2. Two thread and two tables, the average response time is about 338ms.<br />
Thread1: access table t1<br />
Thread2: access table t2<br />
r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa<br />
 2  2  30640   8764  64448 820976    0    0  1340     0  539   422  1  3  0 96<br />
 2  2  30756   8652  64448 821040    4  116  1244   116  546   406  3  1  0 96</p>
<p>3. One thread and two tables, the average response time is about 137ms.</p>
<p>Thread1: access table t1 and table t2 alternately </p>
<p>4. One thread and one table, the average response time is 77ms.</p>
<p>Thread1: only access table t1 </p>
<p>5. We tried use two thread to access MyISAM table and Innodb table, there is no such affect. Thread1 read data from t1, thread2 read data from innodb table test, the response time for thread1 is also about 80ms.</p>
<p>Thread1: access table t1<br />
Thread2: access table test (innodb)</p>
<p>After that, we tried cache the table index by following, but things does not change:<br />
mysql&gt; CACHE INDEX user_call_log_entry_1, user_call_log_entry_2, user_call_log_entry_3,user_call_log_entry_4 IN  call_log_cache;<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br />
| Table      | Op                 | Msg_type | Msg_text |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br />
| lps.user_1 | assign_to_keycache | status   | OK       |<br />
| lps.user_2 | assign_to_keycache | status   | OK       |<br />
| lps.user_3 | assign_to_keycache | status   | OK       |<br />
| lps.user_4 | assign_to_keycache | status   | OK       |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br />
4 rows in set (0.02 sec)</p>
<p>mysql&gt; LOAD INDEX INTO CACHE lps.user_1,lps.user_2,lps.user_3,lps.user_4 IGNORE LEAVES;<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br />
| Table      | Op           | Msg_type | Msg_text |<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br />
| lps.user_1 | preload_keys | status   | OK       |<br />
| lps.user_2 | preload_keys | status   | OK       |<br />
| lps.user_3 | preload_keys | status   | OK       |<br />
| lps.user_4 | preload_keys | status   | OK       |<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br />
4 rows in set (2 min 1.85 sec)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yingkuan</title>
		<link>http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/comment-page-1/#comment-344604</link>
		<dc:creator>yingkuan</dc:creator>
		<pubDate>Thu, 14 Aug 2008 07:09:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=467#comment-344604</guid>
		<description>Peter,
why this is fully in memory workload since you said the inserts are on MYISAM tables?</description>
		<content:encoded><![CDATA[<p>Peter,<br />
why this is fully in memory workload since you said the inserts are on MYISAM tables?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/comment-page-1/#comment-344575</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Thu, 14 Aug 2008 02:56:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=467#comment-344575</guid>
		<description>This was 2 quad core Xeon CPUs

The disks - this was RAID array but it does not really matter as it was fully in memory workload.</description>
		<content:encoded><![CDATA[<p>This was 2 quad core Xeon CPUs</p>
<p>The disks &#8211; this was RAID array but it does not really matter as it was fully in memory workload.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jay yukes</title>
		<link>http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/comment-page-1/#comment-344476</link>
		<dc:creator>jay yukes</dc:creator>
		<pubDate>Wed, 13 Aug 2008 21:28:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=467#comment-344476</guid>
		<description>what hardware is that on??  how many disks?</description>
		<content:encoded><![CDATA[<p>what hardware is that on??  how many disks?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

