{"id":1077,"date":"2018-08-07T16:35:31","date_gmt":"2018-08-07T08:35:31","guid":{"rendered":"http:\/\/www.siediyer.cn\/?p=1077"},"modified":"2018-08-07T16:35:31","modified_gmt":"2018-08-07T08:35:31","slug":"jemalloc%e4%bc%98%e5%8c%96mysql%e5%92%8cnginx","status":"publish","type":"post","link":"https:\/\/www.siediyer.cn\/?p=1077","title":{"rendered":"Jemalloc\u4f18\u5316MySQL\u548cNginx"},"content":{"rendered":"<p>Redis 2.4\u7248\u672c\u4e4b\u540e\uff0c\u9ed8\u8ba4\u4f7f\u7528jemalloc\u6765\u505a\u5185\u5b58\u7ba1\u7406\uff1btengine\u4e5f\u6574\u5408jemalloc\u3002jemalloc\u4ece\u5404\u65b9\u8bc4\u6d4b\u7684\u7ed3\u679c\u53ef\u89c1\u4e0egoogle tcmalloc\u90fd\u4e0d\u76f8\u4f2f\u4ef2\uff0c\u7686\u4e3a\u5185\u5b58\u7ba1\u7406\u5668\u9886\u57df\u6700\u9ad8\u6c34\u5e73\u3002\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1078\" src=\"http:\/\/www.siediyer.cn\/wp-content\/uploads\/2018\/08\/06113147_0rcf.jpg\" width=\"720\" height=\"531\" alt=\"\" srcset=\"https:\/\/qiniu.shijitianchen.com\/2018\/08\/06113147_0rcf.jpg 720w, https:\/\/qiniu.shijitianchen.com\/2018\/08\/06113147_0rcf-300x221.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/p>\n<p>\u56fe\u7247\u6765\u6e90\uff1a\u00a0<a href=\"https:\/\/www.facebook.com\/notes\/facebook-engineering\/scalable-memory-allocation-using-jemalloc\/480222803919\" target=\"_blank\" rel=\"nofollow\">facebook<\/a><\/p>\n<p>\u6700\u5de6\u8fb9\u7684\u5c31\u662fglibc\u7684malloc\uff0c\u6700\u53f3\u8fb9\u7684\u5c31\u662fjemalloc\u3002\u4ece\u56fe\u8868\u4e0a\u53ef\u4ee5\u770b\u51fa\uff0cjemalloc\u7684\u6027\u80fd\u6709glibc\u7684\u4e24\u500d\u4ee5\u4e0a\u3002\u975e\u5e38\u538b \u5012\u6027\u7684\u6027\u80fd\u5dee\u5f02\u3002\u56e0\u6b64\uff0c\u4f7f\u7528\u4e86jemalloc\u7684\u5e94\u7528\u7a0b\u5e8f\u81ea\u7136\u4f1a\u5feb\u5f88\u591a\u3002Jemalloc\u65c1\u8fb9\u7684\u5c31\u662ftcmalloc\u3002Tcmalloc\u7684\u6027\u80fd\u4e0e\u5176\u76f8\u5dee\u751a \u5fae\uff0c\u4f4ejemalloc2.1.0\u61624.5%\u3002\u56fe\u4e0a\u548ctcmalloc\u76841.4\u7248\u672c\uff0c\u800c\u73b0\u5728\u5df2\u7ecf\u52302.1\u7248\u672c\uff0c\u56e0\u6b64\u5b9e\u9645\u4e0a\u8fd9\u4e24\u8005\u5e94\u8be5\u662f\u4e0d\u76f8\u4ef2\u4f2f\u7684\u3002 Jemalloc\u7684\u521b\u59cb\u4ebajason evans\u4e5f\u610f\u8bc6\u5230\u8fd9\u4e00\u70b9\uff0c\u8bf4\u5728cpu core 8\u4ee5\u4e0a\u7684\u8ba1\u7b97\u673a\u4e0ajemalloc\u6548\u7387\u66f4\u9ad8\u3002<\/p>\n<p>MySQL\u6027\u80fd\u6d4b\u8bd5\u2013jemalloc\u5185\u5b58\u7ba1\u7406\uff1a<a href=\"http:\/\/www.linuxeye.com\/Linux\/1914.html\" target=\"_blank\" rel=\"nofollow\">http:\/\/www.linuxeye.com\/Linux\/1914.html<\/a><\/p>\n<h2 id=\"h2_1\"><strong>\u5b89\u88c5jemalloc<\/strong><\/h2>\n<pre class=\"brush:shell;toolbar: true; auto-links: false;\"><code class=\"hljs bash\"><span class=\"hljs-built_in\">cd<\/span>\u00a0lnmp\/src\r\nwget\u00a0http:\/\/www.canonware.com\/download\/jemalloc\/jemalloc-3.4.0.tar.bz2\r\ntar\u00a0xjf\u00a0jemalloc-3.4.0.tar.bz2\r\n<span class=\"hljs-built_in\">cd<\/span>\u00a0jemalloc-3.4.0\u00a0.\/configure\r\nmake\u00a0&amp;&amp;\u00a0make\u00a0install\r\n<span class=\"hljs-built_in\">echo<\/span>\u00a0<span class=\"hljs-string\">'\/usr\/local\/lib'<\/span>\u00a0&gt;\u00a0\/etc\/ld.so.conf.d\/local.conf\r\nldconfig<\/code><\/pre>\n<h2 id=\"h2_2\"><strong>\u4f7f\u7528jemalloc\u4f18\u5316MySQL<\/strong><\/h2>\n<h3 id=\"h3_3\">\u65b9\u6cd51.<\/h3>\n<p>MySQL\/MaridDB 5.5\u7f16\u8bd1\u65b9\u6cd5\uff0ccmake\u9884\u7f16\u8bd1\u65f6\u52a0\u4e0a\u4e0b\u9762\u53c2\u6570<\/p>\n<pre class=\"brush:shell;toolbar: true; auto-links: false;\"><code class=\"hljs ini\"><span class=\"hljs-attr\">-DCMAKE_EXE_LINKER_FLAGS<\/span>=<span class=\"hljs-string\">\"-ljemalloc\"<\/span>\u00a0-DWITH_SAFEMALLOC=<span class=\"hljs-literal\">OFF<\/span><\/code><\/pre>\n<h3 id=\"h3_4\">\u65b9\u6cd52.<\/h3>\n<p>\u4fee\u6539mysqld_safe\u76f4\u63a5\u52a0\u8f7d:<\/p>\n<p>\u67e5\u627e\u6587\u4ef6 \/usr\/local\/mysql\/bin\/mysqld_safe<br \/>\n\u5728#executing mysqld_safe \u4e0b\u9762\u52a0\u4e0a<\/p>\n<pre><code class=\"hljs ruby\">\u00a0\u00a0LD_PRELOAD=<span class=\"hljs-regexp\">\/usr\/local<\/span><span class=\"hljs-regexp\">\/lib\/libjemalloc<\/span>.so<\/code><\/pre>\n<p>\u91cd\u65b0\u542f\u52a8MYSQL<\/p>\n<p>\u4f7f\u7528\u4e0b\u9762\u4ee3\u7801\u81ea\u52a8\u4fee\u6539mysqld_safe\u6587\u4ef6<\/p>\n<pre class=\"brush:shell;toolbar: true; auto-links: false;\"><code class=\"hljs nginx\"><span class=\"hljs-attribute\">sed<\/span>\u00a0-i\u00a0<span class=\"hljs-string\">'s<span class=\"hljs-variable\">@executing<\/span>\u00a0mysqld_safe<span class=\"hljs-variable\">@executing<\/span>\u00a0mysqld_safe\\nexport\u00a0LD_PRELOAD=\/usr\/local\/lib\/libjemalloc.so@'<\/span>\u00a0\/usr\/local\/mysql\/bin\/mysqld_safe\r\nservice\u00a0mysqld\u00a0restart<\/code><\/pre>\n<hr \/>\n<h2 id=\"h2_5\"><strong>\u4f7f\u7528jemalloc\u4f18\u5316Nginx<\/strong><\/h2>\n<p>\u7f16\u8bd1NGINX\u65f6\u6dfb\u52a0\u4ee5\u4e0b\u53c2\u6570:<\/p>\n<pre><code class=\"hljs ini\"><span class=\"hljs-attr\">--with-ld-opt<\/span>=<span class=\"hljs-string\">\"-ljemalloc\"<\/span>\r\n<\/code><\/pre>\n<p>\u5177\u4f53\u5b9e\u73b0\uff1a<\/p>\n<pre class=\"brush:css;toolbar: true; auto-links: false;\"><code class=\"hljs javascript\">cd\u00a0lnmp\/src\/nginx<span class=\"hljs-number\">-1.4<\/span><span class=\"hljs-number\">.2<\/span>\r\nmake\u00a0clean\r\n.\/configure\u00a0--prefix=<span class=\"hljs-regexp\">\/usr\/<\/span>local\/nginx\u00a0--user=www\u00a0--group=www\u00a0\\\u00a0\u00a0\r\n--<span class=\"hljs-keyword\">with<\/span>-http_stub_status_module\u00a0--<span class=\"hljs-keyword\">with<\/span>-http_ssl_module\u00a0--<span class=\"hljs-keyword\">with<\/span>-http_flv_module\u00a0\\\u00a0\r\n--<span class=\"hljs-keyword\">with<\/span>-http_gzip_static_module\u00a0--<span class=\"hljs-keyword\">with<\/span>-ld-opt=<span class=\"hljs-string\">\"-ljemalloc\"<\/span>\r\nmake\u00a0&amp;&amp;\u00a0make\u00a0install<\/code><\/pre>\n<p><strong>\u00a0\u9a8c\u8bc1 jemalloc \u662f\u5426\u8fd0\u884c:<\/strong><\/p>\n<pre><code class=\"hljs perl\">lsof\u00a0-n\u00a0|\u00a0<span class=\"hljs-keyword\">grep<\/span>\u00a0jemalloc<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Redis 2.4\u7248\u672c\u4e4b\u540e\uff0c\u9ed8\u8ba4\u4f7f\u7528jemalloc\u6765\u505a\u5185\u5b58\u7ba1\u7406\uff1btengine\u4e5f\u6574\u5408jemalloc\u3002jem [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1078,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1077","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1077"}],"version-history":[{"count":1,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1077\/revisions"}],"predecessor-version":[{"id":1079,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1077\/revisions\/1079"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/media\/1078"}],"wp:attachment":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}