ab工具测试 swoole 和 ngixn+php-fpm 的并发对比
测试样例:执行的一条sql记录的1w次插入
分两组: 一组用nginx+pfm 来执行, 一组用swoole 来执行
公平性保证前提:
@1.为了保证公平性, 在nginx里把 access_log, error_log都关掉.
vim nginx.conf 的http模块
access_log off;
error_log off;
rewrite_log off;
@2. ulimit -n 10240 把进程的可操作文件描述符数调大, 默认才1024(我这每次并发都1k了) 和nginx 里设置 worker_rlimit_nofile 30000;
@3. max_connections=2048 mysql的最大可连接数开到2048
@4. php-fpm 数量为5个, swoole的工作进程也只开5个.
nginx + fpm 组:
测试代码如下:
<?php
$link = mysqli_connect("192.168.0.7","root","root", "testdb") or die(mysql_error());
$sql = "INSERT INTO test (`user_id`,`date`,`fee`) VALUE('100','2018-09-21',300)";
$result = mysqli_query($link, $sql) or die(mysqli_error($link)); ?>
脚本执行的只是一条sql记录的插入:
ab -n 10000 -c 1000 http://proxy.com/press.php [http://proxy.com 就是ip 192.168.0.7的nginx虚拟主机]
-n 表示总共执行1w次请求, -c 表示每次并发数, 即每次并发1000条,总共1w条
然后开始执行nginx + php-fpm 组合版的压测
[root@07 server]# ab -n 10000 -c 1000 http://proxy.com/press.php
Server Software: nginx
Server Hostname: proxy.com
Server Port: 80
Document Path: /press.php
Document Length: 0 bytes
Concurrency Level: 1000
Time taken for tests: 111.796 seconds
Complete requests: 10000
Failed requests: 1368
(Connect: 0, Receive: 0, Length: 1368, Exceptions: 0)
Write errors: 0
Non-2xx responses: 1368
Total transferred: 1985628 bytes
HTML transferred: 231368 bytes
Requests per second: 89.45 [#/sec] (mean)
Time per request: 11179.624 [ms] (mean)
Time per request: 11.180 [ms] (mean, across all concurrent requests)
Transfer rate: 17.34 [Kbytes/sec] received
看上面的结果,1w个请求总花费了64s才执行完,但失败的请求就达到 7777 , 即成功的只有2223个.每秒的并发数只有155个
[nginx没有打印任何log, 数据库插入也确实只有2223条记录]
然后轮到swoole组了
ab -n 10000 -c 1000 http://127.0.0.1:9501/
完整代码如下:
<?php
// Server
class Server
{
private $serv; public function __construct() {
$this->serv = new swoole_server("0.0.0.0", 9501);
$this->serv->set(array(
'worker_num' => 5, //fpm只开了5个, swoole也只开5个子进程
'daemonize' => false,
)); $this->serv->on('Start', array($this, 'onStart'));
$this->serv->on('Connect', array($this, 'onConnect'));
$this->serv->on('Receive', array($this, 'onReceive'));
$this->serv->on('Close', array($this, 'onClose')); $this->serv->start();
} public function onStart( $serv ) {
echo "Start\n";
} public function onConnect( $serv, $fd, $from_id ) {
} public function onReceive( swoole_server $serv, $fd, $from_id, $data ) {
$link = mysqli_connect("192.168.0.7","root","root", "testdb");
$sql = "INSERT INTO test (`user_id`,`date`,`fee`) VALUE('100','2018-09-21',300)";
$result = mysqli_query($link, $sql) or die(mysqli_error($link));
$serv->close($fd);
} public function onClose( $serv, $fd, $from_id ) { } }
// 启动服务器 Start the server
$server = new Server(); ?>
然后就是执行压测:
[root@07 server]# ab -n 10000 -c 1000 http://127.0.0.1:9501/
Server Software: Server
Hostname: 127.0.0.1
Server Port: 9501
Document Path: /
Document Length: 0 bytes
Concurrency Level: 1000
Time taken for tests: 18.626 seconds <----
Complete requests: 10000
Failed requests:
Write errors: 0
Total transferred: 0 bytes
HTML transferred: 0 bytes
Requests per second: 536.88 [#/sec] (mean) <---
Time per request: 1862.614 [ms] (mean)
Time per request: 1.863 [ms] (mean, across all concurrent requests)
Transfer rate: 0.00 [Kbytes/sec] received
来总结两者的对比就会发现swoole的强大得有点可怕 ...
| field | nginx | swoole |
|---|---|---|
| 总耗时 | 111s | 18s |
| 请求失败数 | 1368 | 0 |
| 每秒并发数 | 89 | 536 |
ab工具测试 swoole 和 ngixn+php-fpm 的并发对比的更多相关文章
- ab测试swoole和ngixn+php-fpm对比
做个swoole http_server和ngixn+php7-fpm测试 nginx swoole卓越的性能让我惊呆了 如需应用可nginx反代, swoole作为http_server, 不用 ...
- Nginx网络架构实战学习笔记(五):大访问量优化整体思路、ab压力测试及nginx性能统计模块、nginx单机1w并发优化
文章目录 大访问量优化整体思路 ab压力测试及nginx性能统计模块 ab压力测试及nginx性能统计模块 ab压力测试 nginx性能统计模块 nginx单机1w并发优化 整装待发: socket ...
- apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104))
apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104)) 今天用apache 自带的ab工具测试,当并发量达到1000多的时 ...
- apache ab压力测试报错apr_socket_recv
apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104)) apache 自带的ab工具测试,当并发量达到1000多的时候报错如下 ...
- 4分钟apache自带ab压力测试工具使用: 2015.10.4
2015.10.44分钟apache自带ab压力测试工具使用:win8.1 wampserver2.5 -Apache-2.4.9-Mysql-5.6.17-php5.5.12-64b 可以参考一下部 ...
- win8.1上wamp环境中利用apache自带ab压力测试工具使用超简单讲解
2015.10.4apache自带ab压力测试工具使用:本地环境:win8.1 wampserver2.5 -Apache-2.4.9-Mysql-5.6.17-php5.5.12-64b 可以参考一 ...
- 超实用压力测试工具-ab工具
在学习ab工具之前,我们需了解几个关于压力测试的概念 吞吐率(Requests per second)概念:服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求 ...
- ab压力测试工具-批量压测脚本
ab(Apache benchmark)是一款常用的压力测试工具.简单易用,ab的命令行一次只能支持一次测试.如果想要批量执行不同的测试方式,并自动对指标进行分析,那么单靠手工一条一条命令运行ab,估 ...
- apache ab工具对网站进行压力测试
Apache -- ab工具主要测试网站的(并发性能) 这个工具非常的强大. 基本语法 : cmd>ab.exe –n 请求总次数 -c 并发数 请求页面的url 进入到ab.ex ...
随机推荐
- CSP学习之导出密钥BLOB 解析
通过CryptExportKey( hKey, NULL, PUBLICKEYBLOB,0, NULL, &dwBlobLen) 函数导出的公钥信息如下: 06 02 00 00 00 A4 ...
- Django——model进阶(待完成)
https://www.cnblogs.com/yuanchenqi/articles/7570003.html 一.QuerySet 1.可切片 使用Python 的切片语法来限制查询集记录的数目 ...
- Web站点如何防范XSS、CSRF、SQL注入攻击
XSS跨站脚本攻击 XSS跨站脚本攻击指攻击者在网页中嵌入客户端脚本(例如JavaScript),当用户浏览此网页时,脚本就会在用户的浏览器上执行,从而达到攻击者的目的,比如获取用户的Cookie,导 ...
- Appium Android 元素定位方法 原生+H5
APPIUM Android 定位方式 1.定位元素应用元素 1.1通过id定位元素 Android里面定位的id一般为resrouce-id: 代码可以这样写: WebElement eleme ...
- mantis统计报表和图形报表出现乱码问题的解决方法
Mantis 报表中文乱码 1.安装Mantis图表 1.0插件 administrator登录-------管理------插件管理,安装插件 2.上传字体simhei.ttf simsun.tt ...
- 【Leetcode】【Easy】Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- Nginx+Tomcat+Session 高性能群集搭建
随着IT行业的发展,linux服务器在企业中应用广泛,人们对linux上的应用服务要求也越来越高,早先的apache服务器.apache有优点也 有不足,apache渐渐不能满足人们的要求,目前ngi ...
- aws查看官方centos镜像imageid
aws ec2 describe-images --owners aws-marketplace --filters Name=product-code,Values=aw0evgkw8e5c1q41 ...
- HttpClient拉取连载小说
上午刚入手的小说,下午心血来潮想从网站上拉取下来做成电子书,呵呵,瞎折腾-说做就做- [抓包] 这一步比什么都重要,如果找不到获取真正资源的那个请求,就什么都不用做了- 先是打算用迅雷把所有页面都下载 ...
- numpy cheat sheet
numpy cheat sheet https://files.cnblogs.com/files/lion-zheng/Numpy_Python_Cheat_Sheet.pdf