全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
楼主: pigicoffee
打印 上一主题 下一主题

请教spawn-fcgi的性能不如php-fpm吗?

[复制链接]
11#
发表于 2009-11-17 17:22:24 | 只看该作者

回复 10# 的帖子

我去看看,完了捣鼓下。

优缺点
本方案的优点是使用CentOS5自带的php和mysql,扩展性好,php的各种扩展yum库里面都有,都可以直接使用;另外,由于使用系统自带的php和mysql,安全性要好一些,如果有什么漏洞都可以直接升级为centos官方的最新版本。由于使用spawn-fcgi,所以无须重新编译php。

本方案的缺点有:

php和mysql都是centos自带的版本,不是最新版本,万一用到php最新版本的某些特性则就不行了。
spawn-fcgi的性能不如php-fpm,如果想用php-fpm,请参考 http://rashost.com/blog/centos5-vps-nginx-solution2
安装Nginx
http://rashost.com/download 下载nginx-0.7.61-1.x86_64.rpm

安装命令:

rpm -ivh nginx-0.7.61-1.x86_64.rpm
chkconfig --list nginx
chkconfig nginx on
/etc/init.d/nginx start
rpm -ql nginx

上面的rpm -ql nginx命令是看看nginx的文件都安装在哪些目录下面了,可以看到nginx的缺省网页目录应该是/usr/share/nginx/html/

通过浏览器访问,应该能看到nginx的缺省网页了,说明nginx正常工作了!

安装MySQL
yum install -y mysql-server
chkconfig --list mysqld
chkconfig mysqld on
/etc/init.d/mysqld start

运行mysql -uroot命令,应该可以正常连接到MySQL

安装PHP
yum install -y php-cgi php-mysql

安装spawn-fcgi
http://rashost.com/download 下载 spawn-fcgi-1.6.2-1.32.x86_64.rpm

rpm -ivh spawn-fcgi-1.6.2-1.32.x86_64.rpm


然后在/etc/rc.local里面加入spawn-fcgi的启动命令:

spawn-fcgi -C 10 -a 127.0.0.1 -p 9000 -u nginx -d /tmp -f php-cgi

其中的-C 10参数是指启动的php fastcgi的进程数目,这个数值可以根据网站的访问量和内存大小修改。

然后先手工启动一下php:

spawn-fcgi -C 10 -a 127.0.0.1 -p 9000 -u nginx -d /tmp -f php-cgi

整合
首先在/usr/share/nginx/html目录下创建文件test.php,其内容很简单,只要下面一行:

<?phpinfo();?>

假设所在VPS的地址是centos5.rashost.com,这时通过浏览器访问http://centos5.rashost.com/test.php是得不到正确的显示结果的。

修改nginx的配置文件/etc/nginx/nginx.conf,在文件内搜索fastcgi_pass,修改该部分内容为:

      location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
            include        fastcgi_params;
        }

然后重启nginx:

/etc/init.d/nginx/restart

然后在浏览器中访问test.php页面,就应该能正确显示了,reboot VPS测试一下,各个模块应该都能自带启动。大功告成,该来些瓶啤酒庆祝一下了!

贴到这里收藏来慢慢看。
12#
发表于 2009-11-17 17:23:44 | 只看该作者
性能不至于差太远吧……
我也觉得用系统的好点。
13#
发表于 2009-11-17 17:24:07 | 只看该作者
原帖由 cpuer 于 2009-11-17 17:19 发表
spawn-fcgi 我也想捣鼓,怎么玩?

/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 端口 -C 进程数 -u 用户名 -f "/usr/local/php/bin/php-cgi -d open_basedir=网站目录"

然后nginx.conf里设置相应的端口就行了
14#
发表于 2009-11-17 17:25:57 | 只看该作者

回复 13# 的帖子

这个命令方式确实简单不少
15#
 楼主| 发表于 2009-11-17 17:28:43 | 只看该作者
发现这方面的资料不多 archlinux的更少 郁闷
16#
发表于 2009-11-17 17:29:23 | 只看该作者

回复 15# 的帖子

所以要你做领头人
17#
发表于 2009-11-17 17:34:53 | 只看该作者
原帖由 gdtv 于 2009-11-17 17:24 发表

/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 端口 -C 进程数 -u 用户名 -f "/usr/local/php/bin/php-cgi -d open_basedir=网站目录"

然后nginx.conf里设置相应的端口就行了

就在开机启动里面加这条命令就行了?
话说写个完整的使用spawn-fcgi来驱动lnmp的教程吧。
18#
发表于 2009-11-17 17:35:59 | 只看该作者

回复 17# 的帖子

直接在SSH里面命令运行就行了哈。
19#
 楼主| 发表于 2009-11-17 17:47:16 | 只看该作者

php-fpm测试

1. 软件版本
Nginx 0.7.17
php 5.2.6
php-fpm 0.5.9
编译参数
./configure –prefix=/usr/local/webserver/php \
–with-config-file-path=/usr/local/webserver/conf \
–enable-fastcgi \
–enable-fpm \
–with-fpm-conf=/usr/local/webserver/conf/php-fpm.conf \
–enable-force-cgi-redirect \
–with-gd \
–with-jpeg-dir \
–with-png-dir \
–enable-gd-native-ttf \
–with-freetype-dir \
–with-mysql=/usr/local/webserver/mysql \
–with-libxml-dir \
–with-mcrypt \
–with-mhash \
–with-curl \
–with-curlwrappers \
–with-zlib-dir \
–with-zlib \
–with-pear \
–with-openssl \
–without-pdo-sqlite \
–without-sqlite \
–disable-debug \
–disable-rpath \
–without-iconv \
–enable-bcmath \
–enable-pcntl \
–enable-mbstring \
–enable-exif \
–enable-zip \
–enable-ftp

3. 补丁安装方法
下载fpm补丁
将fpm加入php
patch -p1 < php-5.2.6-fpm-0.5.9.diff
在./configure后加入–enable-fastcgi –enable-fpm 以启用fpm

4.测试方法
取服务端的一个页面
var_dump($_SERVER);
phpinfo();
?>
另一台服务器发起请求
./http_load -parallel 25 -seconds 10 urls

5.CPU以及内存使用情况
对使用fpm启动的php-cgi以及spawn-fcgi启动的php-cgi进行比对
使用http_load对两者进行访问
然后获取服务器内的内存使用以及响应速度
fpm的使用后CPU下降的比较缓慢.而spawn-cgi的进程cpu下降很快.
很多情况下是使用完后进程CPU便回到0.0

php-fpm
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
root 27724 0 1.2 103468 3400 ? Ss 02:45 00:00
nobody 27725 0.6 2.1 103988 5672 ? S 02:45 00:00
nobody 27726 0.5 2.1 103988 5672 ? S 02:45 00:00
nobody 27727 0.6 2 103988 5352 ? S 02:45 00:00
nobody 27728 0.7 2 103988 5348 ? S 02:45 00:00
nobody 27729 0.5 2 103988 5348 ? S 02:45 00:00
nobody 27730 0.6 2 103988 5348 ? S 02:45 00:00
nobody 27731 0.5 2 103988 5348 ? S 02:45 00:00
nobody 27732 0.7 2 103988 5344 ? S 02:45 00:00
nobody 27733 0.5 2 103988 5344 ? S 02:45 00:00
nobody 27734 0.2 2 103988 5340 ? S 02:45 00:00
nobody 27735 0.7 2 103988 5348 ? S 02:45 00:00
nobody 27736 0.3 2 103988 5344 ? S 02:45 00:00
nobody 27737 0.7 2 103988 5348 ? S 02:45 00:00
nobody 27738 0.5 2 103988 5348 ? S 02:45 00:00
nobody 27739 0.7 2 103988 5348 ? S 02:45 00:00
nobody 27740 0.8 2 103988 5352 ? S 02:45 00:00
nobody 27741 0.4 2 103988 5348 ? S 02:45 00:00
nobody 27742 0.5 2 103988 5344 ? S 02:45 00:00
nobody 27743 0.6 2 103988 5344 ? S 02:45 00:00
nobody 27744 0.5 2 103988 5348 ? S 02:45 00:00
nobody 27745 0.7 2 103988 5352 ? S 02:45 00:00
nobody 27746 0.4 2 103988 5348 ? S 02:45 00:00
nobody 27747 0.5 2 103988 5344 ? S 02:45 00:00
nobody 27748 0.6 2 103988 5348 ? S 02:45 00:00
nobody 27749 0.7 2 103988 5352 ? S 02:45 00:00

spwan-cgi
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
www 27760 0 2.4 103452 6320 ? Ss 02:47 00:00
www 27761 0.2 2.1 103976 5548 ? S 02:47 00:00
www 27762 0.2 1.9 103980 5212 ? S 02:47 00:00
www 27763 0.2 1.9 103980 5212 ? S 02:47 00:00
www 27764 0.2 1.9 103980 5212 ? S 02:47 00:00
www 27765 1.4 1.9 103980 5224 ? S 02:47 00:00
www 27766 0.2 1.9 103980 5212 ? S 02:47 00:00
www 27767 0.4 1.9 103980 5220 ? S 02:47 00:00
www 27768 0.5 1.9 103980 5212 ? S 02:47 00:00
www 27769 0.5 1.9 103980 5216 ? S 02:47 00:00
www 27770 2.4 1.9 103980 5236 ? S 02:47 00:01
www 27771 3.1 2 103980 5248 ? S 02:47 00:01
www 27772 2.4 1.9 103980 5236 ? S 02:47 00:01
www 27773 1.3 1.9 103980 5224 ? S 02:47 00:00
www 27774 0.4 1.9 103980 5212 ? S 02:47 00:00
www 27775 0.4 1.9 103980 5212 ? S 02:47 00:00
www 27776 0.3 1.9 103980 5216 ? S 02:47 00:00
www 27777 0.1 1.9 103980 5212 ? S 02:47 00:00
www 27778 0.2 1.9 103980 5212 ? S 02:47 00:00
www 27779 0.2 1.9 103980 5212 ? S 02:47 00:00
www 27780 0.1 1.9 103980 5212 ? S 02:47 00:00
www 27781 0.1 1.9 103980 5212 ? S 02:47 00:00
www 27782 0.1 1.9 103980 5212 ? S 02:47 00:00
www 27783 0 1.9 103980 5212 ? S 02:47 00:00
www 27784 0 1.9 103980 5212 ? S 02:47 00:00
www 27785 0 1.9 103980 5212 ? S 02:47 00:00

6.反应时间
fetches/sec
php-fpm
264.468
269.657
266.5
267.7
267.334
spawn-cgi
246.153
258.742
256.1
256.9
251.6

7.测试结果
php-fpm的使用非常方便,配置都是在php-fpm.ini的文件内
而启动,重启都可以从php/sbin/php-fpm中进行
更方便的是修改php.ini后可以直接使用php-fpm reload进行加载
无需杀掉进程就可以完成php.ini的修改加载
结果显示使用php-fpm可以使php有不小的性能提升
php-fpm控制的进程.cpu回收的速度比较慢.内存分配的很均匀
而spawn-cgi控制的进程CPU下降的很快.而内存分配的比较不均匀.
有很多进程似乎未分配到,而另外一些却占用很高.
可能是由于进程任务分配的不均匀导致的.而这也导致了总体响应速度的下降
而php-fpm合理的分配.导致总体响应的提到以及任务的平均
20#
发表于 2009-11-17 18:06:31 | 只看该作者

回复 19# 的帖子

php-fpm控制的进程.cpu回收的速度比较慢.内存分配的很均匀
spawn-cgi控制的进程CPU下降的很快.而内存分配的比较不均匀.

spawn-cgi CPU控制得比较好那样的话。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2026-1-14 07:49 , Processed in 0.058700 second(s), 6 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表