压力测试 问题

luchuxue

用workman做的压力测试
代码如下
<?php
require DIR . '/vendor/autoload.php';
use Workerman\Worker;
use Workerman\Lib\Timer;
use Workerman\Connection\AsyncTcpConnection;

$worker = new Worker();
$worker->onWorkerStart = 'connect';
function connect()
{
static $count = 0;
// 20000个链接
if ($count++ >= 20000) return;
// 建立异步链接
$con = new AsyncTcpConnection('ws://127.0.0.1:5555');
$con->onConnect = function($con)
{
// 递归调用connect
connect();
};
$con->onMessage = function($con, $msg)
{
//echo "recv $msg\n";
};
$con->onClose = function($con)
{
echo "con close\n";
};
// 当前链接每10秒发个心跳包
Timer::add(10, function()use($con)
{
$con->send("ping");
});
$con->connect();
echo $count, " connections complete\n";

}
Worker::runAll();

311 2 0
2个回答

luchuxue

第一次测试 达到了6700
然后我换了2台机器 继续测试 一到1020就不动了
扩展我装了 也根据手册的内核优化操作了一遍

  • walkor 2022-07-01

    运行压力脚本的服务器也要优化内核,安装event扩展

  • luchuxue 2022-07-01

    谢谢

luchuxue

  • 暂无评论
🔝