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 ...
随机推荐
- IDEA安装及破解永久版教程————鹏鹏
---恢复内容开始--- 首先我们先来介绍下什么是IDEA? IDEA 全称 IntelliJ IDEA,是java编程语言开发的集成环境.IntelliJ在业界被公认为最好的java开发工具之一,尤 ...
- hibernate事务管理 (jdbc jta)
hibernate的两种事务管理jdbc 和jta方式.下边说说两者的区别一.说明一下jdbc和jta方式事务管理的区别:JDBC事务由Connnection管理,也就是说,事务管理实际上是在JDBC ...
- 2018.10.23NOIP模拟赛解题报告
心路历程 预计得分:\(100 + 50 + (10 \sim 50)\) 实际得分:\(100 + 10 + 50\) 这可能是我打的最懵逼的一场考试没有之一.. T1两个小时才做出来也是醉了. T ...
- Android 实现电话录音(窃听)
配置文件 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android=&qu ...
- Android自定义之流式布局
流式布局,好处就是父类布局可以自动的判断子孩子是不是需要换行,什么时候需要换行,可以做到网页版的标签的效果.今天就是简单的做了自定义的流式布局. 具体效果: 原理: 其实很简单,Measure La ...
- 对于在gti操作遇见detached Head时
1.什么是detached HEAD 在git中,这是一个处于”游离“状态的标签 2.使用git branch <new_branch_name> <HEAD_code> 为这 ...
- Entity Framework:“无法加载指定的元数据资源
System.Data.Entity.Core.MetadataException:“无法加载指定的元数据资源 CodeFirst方式使用EF,写入数据时报错.System.Data.Entity.C ...
- wxPython控件学习之wx.grid.Grid 表格控件
wxPython控件学习之wx.grid.Grid (包括对GridCellEditor和GridCelRender的扩展,以支持更多的grid cell 样式, 以GridCellColorEdit ...
- To find names containing exactly five characters, use “^”and “$”to match the beginning and end of the name, and five instances of “.”in between: mysql
To find names containing exactly five characters, use “^”and “$”to match the beginning and end of th ...
- 在linux代码中打印函数调用的堆栈的方法
之前一直有这样的需求,当时问到,也没搜到方法,现在竟然既问到了,也搜到了,哎,世事真是不能强求啊! 在Linux内核调试中,经常用到的打印函数调用堆栈的方法非常简单,只需在需要查看堆栈的函数中加入: ...