环境:
64位Ubuntu14.04,i5-3230M
PHP5.4.31 with ZendOPcache
Node.JS 0.10.35
Node.JS 测试
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html;charset=UTF-8'});
res.write('
运行程序:
node t.js
查看系统CPU空闲率:
sar 1
压力测试,并发100,完成10万请求:
ab -c100 -n100000 http://127.0.0.1:8082/t.js
内存从11MB涨到61MB,系统CPU空闲率65%, RPS达到6049.
PHP CLI Server 测试
php header('Content-Type: text/html;charset=UTF-8'); ?>
运行程序:
php -S 127.0.0.1:8081 -t ./
查看系统CPU空闲率:
sar 1
压力测试,并发100,完成10万请求:
ab -c100 -n100000 http://127.0.0.1:8081/t.php
内存从19.6MB涨到20.0MB,系统CPU空闲率57%, RPS达到11405.
不开启OPCACHE时,内存从8.3MB涨到9.0MB,系统CPU空闲率57%,RPS达到8851.
PHP Swoole 测试
$http = new swoole_http_server("0.0.0.0", 9501);
$http->set([
'worker_num' => 5 //开启5个工作进程
]);
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) {
$response->header('Content-Type', 'text/html;charset=UTF-8');
$response->end('
运行程序:
php swoole.php
查看系统CPU空闲率:
sar 1
压力测试,并发100,完成20万请求:
ab -c100 -n200000 http://127.0.0.1:9501/swoole.php
测试后内存占用达到117MB,系统CPU空闲率39%, RPS达到19216.