<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[张宴的博客]]></title> 
<link>http://zyan.cc/index.php</link> 
<description><![CDATA[Web系统架构与底层研发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[张宴的博客]]></copyright>
<item>
<link>http://zyan.cc/post/349/</link>
<title><![CDATA[使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[数据库技术]]></category>
<pubDate>Sat, 31 May 2008 01:53:06 +0000</pubDate> 
<guid>http://zyan.cc/post/349/</guid> 
<description>
<![CDATA[ 
	　　[文章作者：张宴 本文版本：v1.1 最后修改：2008.06.02 转载请注明出自：<a href="http://blog.zyan.cc" target="_blank">http://blog.zyan.cc</a>]<br/><br/>　　TCMalloc（Thread-Caching Malloc）是google开发的开源工具──“<a href="http://code.google.com/p/google-perftools/" target="_blank">google-perftools</a>”中的成员。与标准的glibc库的malloc相比，TCMalloc在内存的分配上效率和速度要高得多，可以在很大程度上提高MySQL服务器在高并发情况下的性能，降低系统负载。<br/><br/>　　TCMalloc的实现原理和测试报告请见一篇文章：《<a href="http://shiningray.cn/tcmalloc-thread-caching-malloc.html" target="_blank">TCMalloc：线程缓存的Malloc</a>》<br/><br/>　　<strong>为MySQL添加TCMalloc库的安装步骤（Linux环境）：</strong><br/><br/>　　1、64位操作系统请先安装libunwind库，32位操作系统不要安装。libunwind库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能，其中包括用于输出堆栈跟踪的API、用于以编程方式辗转开解堆栈的API以及支持C++异常处理机制的API。<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">wget <a href="http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz" target="_blank">http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz</a><br/>tar zxvf libunwind-0.99-alpha.tar.gz<br/>cd libunwind-0.99-alpha/<br/>CFLAGS=-fPIC ./configure<br/>make CFLAGS=-fPIC<br/>make CFLAGS=-fPIC install</div><br/><br/>　　2、安装google-perftools：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">wget <a href="http://google-perftools.googlecode.com/files/google-perftools-0.97.tar.gz" target="_blank">http://google-perftools.googlecode.com/files/google-perftools-0.97.tar.gz</a><br/>tar zxvf google-perftools-0.97.tar.gz<br/>cd google-perftools-0.97/<br/>./configure<br/>make && make install<br/><br/>echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf<br/>/sbin/ldconfig</div><br/><br/>　　3、修改MySQL启动脚本（根据你的MySQL安装位置而定）：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">vi /usr/local/mysql/bin/mysqld_safe</div><br/>　　在# executing mysqld_safe的下一行，加上：<div class="quote"><div class="quote-title">引用</div><div class="quote-content">export LD_PRELOAD=/usr/local/lib/libtcmalloc.so</div></div><br/>　　保存后退出，然后重启MySQL服务器。<br/><br/><br/>　　4、使用lsof命令查看tcmalloc是否起效：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/usr/sbin/lsof -n &#124; grep tcmalloc</div><br/>　　如果发现以下信息，说明tcmalloc已经起效：<br/>　　<span style="color: #008000;">mysqld &nbsp; &nbsp;10847 &nbsp; mysql &nbsp;mem &nbsp; &nbsp; &nbsp; REG &nbsp; &nbsp; &nbsp; &nbsp;8,5 &nbsp;1203756 &nbsp; 20484960 /usr/local/lib/libtcmalloc.so.0.0.0 &nbsp; </span><br/><br/><hr/><br/>　　注：2008年6月2日，修正了libunwind在x86_64位操作系统下的编译错误，TCMalloc无法加载等问题。<br/><br/>　　涉及修改内容：<br/>　　1、libunwind的编译参数改为：<br/>　　CFLAGS=-fPIC ./configure<br/>　　make CFLAGS=-fPIC<br/>　　make CFLAGS=-fPIC install<br/><br/>　　2、增加：<br/>　　echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf<br/>　　/sbin/ldconfig<br/><br/>　　3、修改MySQL加载TCMalloc的语句：<br/>　　export LD_PRELOAD=/usr/local/lib/libtcmalloc.so<br/><br/>　　感谢网友router。<br/><br/><br/>Tags - <a href="http://zyan.cc/tags/linux/" rel="tag">linux</a> , <a href="http://zyan.cc/tags/mysql/" rel="tag">mysql</a> , <a href="http://zyan.cc/tags/google/" rel="tag">google</a> , <a href="http://zyan.cc/tags/tcmalloc/" rel="tag">tcmalloc</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1103</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>router &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 31 May 2008 15:45:28 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1103</guid> 
<description>
<![CDATA[ 
	make 报错啊，老大，怎么办？<br/><br/>gcc: unrecognized option &#96;-static-libcxa&#039;<br/>/usr/bin/ld: dwarf/.libs/Lfind_proc_info-lsb.o: relocation R_X86_64_PC32 against &#96;_ULx86_64_dwarf_search_unwind_table&#039; can not be used when making a shared object; recompile with -fPIC<br/>/usr/bin/ld: final link failed: Bad value<br/>collect2: ld returned 1 exit status<br/>make[2]: *** [libunwind.la] Error 1<br/>make[2]: Leaving directory &#96;/usr/local/src/libunwind-0.99-alpha/src&#039;<br/>make[1]: *** [all] Error 2<br/>make[1]: Leaving directory &#96;/usr/local/src/libunwind-0.99-alpha/src&#039;<br/>make: *** [all-recursive] Error 1
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1107</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>router &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sun, 01 Jun 2008 10:37:39 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1107</guid> 
<description>
<![CDATA[ 
	我是64位系统啊
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1108</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>router &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sun, 01 Jun 2008 13:13:41 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1108</guid> 
<description>
<![CDATA[ 
	解决了64位libunwind编译不成功的问题<br/>加上<br/>CFLAGS=-fPIC ./configure<br/>make CFLAGS=-fPIC<br/>make CFLAGS=-fPIC install<br/><br/>就可以了
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1109</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>router &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sun, 01 Jun 2008 13:17:28 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1109</guid> 
<description>
<![CDATA[ 
	新问题：<br/>加入export LD_PRELOAD = &quot;/usr/local/lib/libtcmalloc.so&quot; 后启动mysql<br/>/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/usr/local/webserver/mysql/my.cnf &amp;<br/><br/>报错<br/><br/>/usr/local/webserver/mysql/bin/mysqld_safe: line 12: export: &#96;=&#039;: not a valid identifier<br/>/usr/local/webserver/mysql/bin/mysqld_safe: line 12: export: &#96;/usr/local/lib/libtcmalloc.so&#039;: not a valid identifier<br/>Starting mysqld daemon with databases from /usr/local/webserver/mysql/data
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1110</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>router &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sun, 01 Jun 2008 13:27:40 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1110</guid> 
<description>
<![CDATA[ 
	将export LD_PRELOAD = &quot;/usr/local/lib/libtcmalloc.so&quot;更改为LD_PRELOAD = &quot;/usr/local/lib/libtcmalloc.so&quot;<br/><br/>则提示<br/>LD_PRELOAD: command not found<br/><br/>mysql版本为5.0.22<br/>老大帮忙解决下啊
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1111</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>router &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sun, 01 Jun 2008 13:39:55 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1111</guid> 
<description>
<![CDATA[ 
	把启动的问题解决了，如下：<br/><br/># 修改 mysql 啟動, 讓他使用 TCMalloc<br/># 修改 第 387 行, 於此行最前面加入 LD_PRELOAD=&quot;/usr/lib/libtcmalloc.so&quot;(在 mysql 啟動前先載入環境變數(mysql 啟動的 script 就是 /usr/bin/mysqld_safe), 讓 tcmalloc = glibc 的 malloc(), 於最前面加入環境變數即可)<br/>387 行就是 mysql start 的那行命令, 此行修改完成如下:<br/><br/> &nbsp; &nbsp;LD_PRELOAD=&quot;/usr/lib/libtcmalloc.so&quot; $NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file &nbsp; &nbsp;=$pid_file --skip-external-locking 2&gt;&amp;1 &#124; $ERR_LOGGER -t mysqld &amp; wait<br/><br/>但新问题又来了<br/>使用lsof命令查看tcmalloc是否起效：<br/>/usr/sbin/lsof -n &#124; grep tcmalloc<br/>没有发现tcmalloc
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1113</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>router &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sun, 01 Jun 2008 16:24:27 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1113</guid> 
<description>
<![CDATA[ 
	哎，忙活了一晚上，还是不行<br/><br/>试着编译mysql <br/> ./configure --prefix=/usr/local/webserver/mysql/ --without-debug --with-unix-socket-path=/tmp/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=&quot;-all-static -ltcmalloc&quot; --enable-assembler --with-extra-charsets=gbk,gb2312,utf8 --with-pthread --enable-thread-safe-client<br/><br/>make提示<br/>/lib/libtcmalloc.a(stacktrace.o)(.text+0xdf): In function &#96;GetStackTrace(void**, int, int)&#039;:<br/>src/stacktrace_libunwind-inl.h:65: undefined reference to &#96;_ULx86_64_init_local&#039;<br/>/usr/local/lib/libtcmalloc.a(stacktrace.o)(.text+0x103):src/stacktrace_libunwind-inl.h:70: undefined reference to &#96;_ULx86_64_get_reg&#039;<br/>/usr/local/lib/libtcmalloc.a(stacktrace.o)(.text+0x115):src/stacktrace_libunwind-inl.h:78: undefined reference to &#96;_ULx86_64_step&#039;<br/>/usr/local/lib/libtcmalloc.a(stacktrace.o)(.text+0x28f): In function &#96;GetStackFrames(void**, int*, int, int)&#039;:<br/>src/stacktrace_libunwind-inl.h:126: undefined reference to &#96;_ULx86_64_init_local&#039;<br/>/usr/local/lib/libtcmalloc.a(stacktrace.o)(.text+0x2a4):src/stacktrace_libunwind-inl.h:130: undefined reference to &#96;_ULx86_64_step&#039;<br/>/usr/local/lib/libtcmalloc.a(stacktrace.o)(.text+0x2be):src/stacktrace_libunwind-inl.h:130: undefined reference to &#96;_ULx86_64_get_reg&#039;<br/>/usr/local/lib/libtcmalloc.a(stacktrace.o)(.text+0x2e8):src/stacktrace_libunwind-inl.h:137: undefined reference to &#96;_ULx86_64_get_reg&#039;<br/>/usr/local/lib/libtcmalloc.a(stacktrace.o)(.text+0x2f4):src/stacktrace_libunwind-inl.h:139: undefined reference to &#96;_ULx86_64_step&#039;<br/>/usr/local/lib/libtcmalloc.a(stacktrace.o)(.text+0x30e):src/stacktrace_libunwind-inl.h:139: undefined reference to &#96;_ULx86_64_get_reg&#039;<br/><br/>重新写参数<br/>CFLAGS=-fPIC LDFLAGS=&quot;-lunwind -lunwind-ULx86_64&quot; ./configure........<br/>make LDFLAGS=&quot;-lunwind -lunwind-ULx86_64&quot; CFLAGS=-fPIC<br/>提示<br/>/usr/bin/ld: cannot find -lunwind-ULx86_64<br/>于是<br/>ln -s /usr/local/lib/libunwind-x86_64.so.7.0.0 /usr/local/lib/libunwind-ULx86_64.so<br/>还是提示/usr/bin/ld: cannot find -lunwind-ULx86_64<br/><br/>估计是google这个工具CPU参数是x86_64而我服务器参数是ULx86_64造成的这个bug<br/>崩溃了！老大救命啊！
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1115</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>router &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 02 Jun 2008 03:54:10 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1115</guid> 
<description>
<![CDATA[ 
	老大，mysql采用的静态编译with-mysqld-ldflags=-all-static <br/>是不是不能使用外挂方式哦？<br/>LD_PRELOAD=/usr/local/lib/libtcmalloc.so<br/>能否告知我您的gtalk QQ 或者msn等联系方式，我想请教下，我的email gtalk : keaideala@gmail.com
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1118</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>jack &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 02 Jun 2008 06:09:36 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1118</guid> 
<description>
<![CDATA[ 
	应该是采用了with-mysqld-ldflags=-all-static 就不行！我也遇到同样问题！
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1119</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>router &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 02 Jun 2008 09:18:07 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1119</guid> 
<description>
<![CDATA[ 
	请问张老师，我本来想用编译到mysql的方式使用TCMalloc，但无法编译成功mysql，报错undefined reference to &#96;_ULx86_64_init_local&#039;<br/>然后我在make加上参数make LDFLAGS=&quot;-lunwind -lunwind-ULx86_64&quot; CFLAGS=-fPIC<br/>报错/usr/bin/ld: cannot find -lunwind-ULx86_64，lib里面没有unwind-ULx86_64.so类似的文件，只有unwind-x86_64，我打算放弃编译，采用外挂的方式使用TCMalloc，但以前的mysql采用的with-mysqld-ldflags=-all-static 方式编译，不支持外挂，请问应该怎么重新编译mysql才能支持外挂
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1121</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>router &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 02 Jun 2008 16:18:52 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1121</guid> 
<description>
<![CDATA[ 
	编译不成功<br/>但外挂搞好了<br/>sh &nbsp; &nbsp; &nbsp; &nbsp;29861 &nbsp; &nbsp;root &nbsp;mem &nbsp; &nbsp; &nbsp; REG &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;253,0 &nbsp; 1598671 &nbsp; &nbsp;7646979 /usr/local/lib/libtcmalloc.so.0.0.0<br/>mysqld &nbsp; &nbsp;29882 &nbsp; mysql &nbsp;mem &nbsp; &nbsp; &nbsp; REG &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;253,0 &nbsp; 1598671 &nbsp; &nbsp;7646979 /usr/local/lib/libtcmalloc.so.0.0.0<br/>lsof &nbsp; &nbsp; &nbsp;29913 &nbsp; &nbsp;root &nbsp;mem &nbsp; &nbsp; &nbsp; REG &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;253,0 &nbsp; 1598671 &nbsp; &nbsp;7646979 /usr/local/lib/libtcmalloc.so.0.0.0<br/>grep &nbsp; &nbsp; &nbsp;29914 &nbsp; &nbsp;root &nbsp;mem &nbsp; &nbsp; &nbsp; REG &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;253,0 &nbsp; 1598671 &nbsp; &nbsp;7646979 /usr/local/lib/libtcmalloc.so.0.0.0<br/>lsof &nbsp; &nbsp; &nbsp;29915 &nbsp; &nbsp;root &nbsp;mem &nbsp; &nbsp; &nbsp; REG &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;253,0 &nbsp; 1598671 &nbsp; &nbsp;7646979 /usr/local/lib/libtcmalloc.so.0.0.0<br/><br/>具体步骤和张老师的一模一样，只是重新编译了mysql<br/>取消掉静态链接。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1127</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>odinxu &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Wed, 04 Jun 2008 16:27:10 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1127</guid> 
<description>
<![CDATA[ 
	终于也安装成功了，和 router 说的一样，<br/>需要重新编译一次MYSQL，<br/>configure时要去掉这一个参数 with-mysqld-ldflags=-all-static <br/>我的环境：CentOS 4.6 32bit，不需要安装libunwind库。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1132</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>freeke &lt;myfreeke@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 05 Jun 2008 05:09:38 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1132</guid> 
<description>
<![CDATA[ 
	有没有不需要重新编译的办法,对于运营系统不能随便动啊!
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1134</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>freeke &lt;myfreeke@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 05 Jun 2008 05:11:27 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1134</guid> 
<description>
<![CDATA[ 
	有没有不需要重新编译MYSQL的办法呢?因为运营系统哪能随便重新编译程序呢?
]]>
</description>
</item><item>
<link>http://zyan.cc/post/349/#blogcomment1133</link>
<title><![CDATA[[评论] 使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>freeke &lt;myfreeke@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 05 Jun 2008 05:12:09 +0000</pubDate> 
<guid>http://zyan.cc/post/349/#blogcomment1133</guid> 
<description>
<![CDATA[ 
	请教博主帮忙!
]]>
</description>
</item>
</channel>
</rss>