Skip to content

Commit

Permalink
Add stress test.
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Apr 8, 2018
1 parent d9a46be commit de9233b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@ $response = Saber::psr()
echo $response->getBody();
```

### 压力测试

> 测试机器为最低配MacBookPro, 请求服务器为本地echo服务器.
0.9秒完成6666个请求, 成功率100%.

```php
co::set(['max_coroutine' => 8191]);
go(function () {
$requests = [];
for ($i = 6666; $i--;) {
$requests[] = ['uri' => 'http://127.0.0.1'];
}
$res = Saber::requests($requests);
echo "use {$res->time}s\n";
echo "success: $res->success_num, error: $res->error_num";
});
// on MacOS
// use 0.91531705856323s
// success: 6666, error: 0
```

<br>

------
Expand Down
23 changes: 23 additions & 0 deletions examples/stress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Copyright: Swlib
* Author: Twosee <twose@qq.com>
* Date: 2018/4/7 下午6:11
*/

use Swlib\Saber;

require __DIR__ . '/../vendor/autoload.php';
co::set(['max_coroutine' => 8191]);
go(function () {
$requests = [];
for ($i = 6666; $i--;) {
$requests[] = ['uri' => 'http://127.0.0.1'];
}
$res = Saber::requests($requests);
echo "use {$res->time}s\n";
echo "success: $res->success_num, error: $res->error_num";
});
// on MacOS
// use 0.91531705856323s
// success: 6666, error: 0

0 comments on commit de9233b

Please sign in to comment.