新聞中心
使用 Jemalloc 優(yōu)化 Mysql 和 PHP 內(nèi)存占用

創(chuàng)新互聯(lián)建站專注于企業(yè)成都全網(wǎng)營銷、網(wǎng)站重做改版、樂清網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5高端網(wǎng)站建設(shè)、成都做商城網(wǎng)站、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為樂清等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
Jemalloc 是一個高效的內(nèi)存分配器,它可以替代默認(rèn)的 glibc malloc 和 free,通過使用 Jemalloc,可以顯著減少 Mysql 和 PHP 的內(nèi)存占用,提高系統(tǒng)的性能。
1、安裝 Jemalloc
在 Linux 系統(tǒng)中,可以通過以下命令安裝 Jemalloc:
sudo aptget install libjemallocdev
2、編譯并安裝帶有 Jemalloc 的 Mysql
從 MySQL 官方下載源代碼包,然后執(zhí)行以下步驟:
解壓源代碼包 tar xvf mysql5.7.35.tar.gz cd mysql5.7.35 配置編譯選項,指定使用 Jemalloc CFLAGS="DWITH_JEMALLOC=1" CXXFLAGS="DWITH_JEMALLOC=1" LDFLAGS="ljemalloc" ./configure prefix=/usr/local/mysql withcharset=utf8mb4 withcollation=utf8mb4_unicode_ci enablethreadsafeclient enablelocalinfile withplugins=innobase,csv,myisam,shared 編譯并安裝 Mysql make && make install
3、編譯并安裝帶有 Jemalloc 的 PHP
從 PHP 官方下載源代碼包,然后執(zhí)行以下步驟:
解壓源代碼包 tar xvf php7.4.0.tar.gz cd php7.4.0 配置編譯選項,指定使用 Jemalloc export CFLAGS="DWITH_JEMALLOC=1" CXXFLAGS="DWITH_JEMALLOC=1" LDFLAGS="ljemalloc" ./configure prefix=/usr/local/php enablefpm withconfigfilepath=/usr/local/php/etc enableinlineoptimization withcurl withmysqli withpdo_mysql withzlib enablezip enablembstring enablesockets enableexif enablesoap enablexmlreader enablexmlwriter enablesimplexml enablecalendar enablesysvsem enablesysvshm enablepcntl enableftp enablegd withjpegdir=/usr/local withpngdir=/usr/local withfreetypedir=/usr/local withzlib withopenssl withmcrypt withgettext withmysqli=mysqlnd withmysql=mysqlnd 編譯并安裝 PHP make && make install
4、重啟 Mysql 和 PHP 服務(wù)
sudo service mysql restart sudo service php7.4fpm restart
問題與解答:
Q1: 我使用的是其他版本的 Mysql 或 PHP,如何進(jìn)行優(yōu)化?
A1: 對于其他版本的 Mysql 或 PHP,可以參考上述步驟,修改相應(yīng)的源代碼包版本和編譯選項,對于 Mysql,可以從官方下載相應(yīng)版本的源代碼包,然后執(zhí)行 ./configure 時指定正確的版本號,對于 PHP,可以從官方下載相應(yīng)版本的源代碼包,然后執(zhí)行 ./configure 時指定正確的版本號,按照上述步驟編譯并安裝即可。
網(wǎng)頁題目:使用Jemalloc優(yōu)化Mysql和PHP內(nèi)存占用
網(wǎng)頁網(wǎng)址:http://www.dlmjj.cn/article/dheccii.html


咨詢
建站咨詢
