> 比武不招亲规则:双方开启webserver服务,使用ab命令进行测试,相同条件下,耗时少者获胜
## 1.来看woo代码:
>这次比武中,我们来比较与php的性能,总共请求2w,每次并发1k(多出1k,系统提示打开过多文件句柄,有兴趣的可以改下内核参数测试看看)
~~~woo|lua
woo.exe -r "woo.http:new():listen(':3005','_out(\'hello world!\')')"
~~~
看看woo武功怎么样:
使用ab命令:` ab -k -n 20000 -c 1000 http://127.0.0.1:3005/`
```
ab -n 20000 -c 1000 -k http://127.0.0.1:3005/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests
Server Software: fasthttp
Server Hostname: 127.0.0.1
Server Port: 3005
Document Path: /
Document Length: 12 bytes
Concurrency Level: 1000
Time taken for tests: 0.487 seconds
Complete requests: 20000
Failed requests: 0
Keep-Alive requests: 20000
Total transferred: 3420000 bytes
HTML transferred: 240000 bytes
Requests per second: 41031.20 [#/sec] (mean)
Time per request: 24.372 [ms] (mean)
Time per request: 0.024 [ms] (mean, across all concurrent requests)
Transfer rate: 6851.89 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 8.3 0 53
Processing: 0 21 7.1 20 52
Waiting: 0 21 7.1 20 51
Total: 0 23 12.2 20 89
Percentage of the requests served within a certain time (ms)
50% 20
66% 21
75% 24
80% 26
90% 34
95% 47
98% 69
99% 73
100% 89 (longest request)
```
## 2.来看php代码:
php单进程使用`php -S 127.0.0.1:3008 ` 启动服务,目录中有个index.php文件,代码为
```php
<?php
echo 'hello world!';
```
再看看php的武功如何:`ab -k -n 20000 -c 1000 http://127.0.0.1:3008/index.php`
```
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests
Server Software:
Server Hostname: 127.0.0.1
Server Port: 3008
Document Path: /index.php
Document Length: 12 bytes
Concurrency Level: 1000
Time taken for tests: 2.188 seconds
Complete requests: 20000
Failed requests: 0
Keep-Alive requests: 0
Total transferred: 3660000 bytes
HTML transferred: 240000 bytes
Requests per second: 9142.31 [#/sec] (mean)
Time per request: 109.382 [ms] (mean)
Time per request: 0.109 [ms] (mean, across all concurrent requests)
Transfer rate: 1633.83 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 25 152.2 0 1043
Processing: 7 29 121.0 12 1072
Waiting: 0 29 121.0 12 1072
Total: 11 54 261.5 12 2102
Percentage of the requests served within a certain time (ms)
50% 12
66% 13
75% 15
80% 16
90% 17
95% 60
98% 1025
99% 2070
100% 2102 (longest request)
```
## 3.让我们看看php的王者插件:php(swoole)
>特地安装编译一个swoole来测试下
swoole代码:
```
<?php
$http = new swoole_http_server("0.0.0.0",8811);
$http->set(
[
'enable_static_handler'=>true,
'document_root'=>"/home/data"
]
);
$http->on('request', function ($request, $response) {
// 异步文件写入
$response->end("hello world!");
});
$http->start();
```
使用`ab -n 20000 -c 1000 -k http://127.0.0.1:8811/ `
```
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests
Server Software: swoole-http-server
Server Hostname: 127.0.0.1
Server Port: 8811
Document Path: /
Document Length: 12 bytes
Concurrency Level: 1000
Time taken for tests: 0.483 seconds
Complete requests: 20000
Failed requests: 0
Keep-Alive requests: 20000
Total transferred: 3300000 bytes
HTML transferred: 240000 bytes
Requests per second: 41369.75 [#/sec] (mean)
Time per request: 24.172 [ms] (mean)
Time per request: 0.024 [ms] (mean, across all concurrent requests)
Transfer rate: 6666.02 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 7.4 0 43
Processing: 5 21 5.9 21 51
Waiting: 0 21 5.9 21 51
Total: 5 23 10.2 21 80
Percentage of the requests served within a certain time (ms)
50% 21
66% 22
75% 23
80% 24
90% 32
95% 48
98% 61
99% 64
100% 80 (longest request)
```
## 4.结果
在此与php的比试中,2w次请求:
| 语言 | 总耗时 | 每秒请求 |
| --- | --- | --- |
| woo | `0.487`秒 | `41031.20`次 |
| php单进程 | `2.188`秒 | `9142.31`次 |
| php(fpm) (安装麻烦,启动麻烦需要nginx,没测试) | - | - |
| php(swoole) | `0.483`秒 | `41369.75`次 |
>### 结论:woo的webserver服务性能和php swoole相当,非常适合用来开发web server服务
>ps 测试中有时候woo耗时小于swoole,有时候高于swoole,棋鼓相当,结果随机取到
- 序言
- 安装
- 可视化编辑器
- woo 命令行参数详解
- 测试用例
- 简单http服务
- 正则
- gpio控制硬件设备
- 比武不招亲
- 和php比WebServer
- woo语法
- 语法简介
- 基本语法
- woo数据类型
- woo变量
- woo循环
- woo流程控制
- woo函数
- woo运算符
- woo字符串
- 类
- 类的继承
- 模块
- 数组
- 迭代
- table
- 元表(魔术方法)
- 错误处理
- 面向对象
- woo开发必须注意事项
- 函数/模块
- 内置函数
- webServer专属函数
- 内置模块
- gd-2d绘图库
- 2D图形例子
- websockets用例
- buffer缓存
- http
- orm数据库连接
- redis-ssdb连接
- queue队列
- 其他特别函数
- sockets
- 启动线程如何
- Murphy-http Web框架
- 简介
- 全局函数
- model
- view
- controller
- 消息队列
- 全局线程锁
- 包管理器/coder wooyri package manager
- 最ok的包上榜名单
- woo栗子
- 函数传参
- 编码解码
- http模块用例
- 移动读写文件流用例
- 文件下载用例
- 数组迭代
- 进制转换
- _choose用例
- 日期时间用例
- 注明
- wop 码包|coder wooyri peogram
- 码人激励计划