使用方法/系统安装与升级/性能优化

来自康健生活

性能优化

恩,怎么说呢,有段时间不上这个网站了,因为浏览网页速度特别的卡顿。查了下服务器,MySQL 进程占用过高。也许是页面缓存写进了 MySQL 里面么?

所以查阅了一些优化策略,分为一二三步

第一点是安装 opcache。跑了下命令,发现已经被内置在了 PHP8.1 里面,应该是以前安装过吧。

/home/kwy
sudo apt install php-opcache

修改配置文件

/etc/php/8.1/apache2/php.ini
zend_extension=opcache
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.fast_shutdown=1

然后重启生效

/home/kwy
sudo systemctl restart apache2
sudo systemctl restart php8.1-fpm

第二步,安装 Memcached。默认配置直接安装并启动服务。

/home/kwy
sudo apt install php-memcached
sudo apt install memcached libmemcached-tools
sudo systemctl status memcached

修改配置文件

LocalSettings.php
##### memcached
$wgMainCacheType = CACHE_MEMCACHED;
$wgParserCacheType = CACHE_MEMCACHED; // 非必填
$wgMessageCacheType = CACHE_MEMCACHED; // 非必填
$wgMemCachedServers = [ '127.0.0.1:11211' ];

# $wgSessionsInObjectCache = true; // 非必填--已在1.33版以上移除
$wgSessionCacheType = CACHE_MEMCACHED; // 非必填

安装 meidiawiki 的 Memcached 扩展可以验证服务状态