您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman类TcpConnection的maxSendBufferSize属性(缓冲区过载的影响因素)
发布时间:2021-12-03 21:55:50编辑:雪饮阅读()
maxSendBufferSize
说明:
int Connection::$maxSendBufferSize
每个连接都有一个单独的应用层发送缓冲区,如果客户端接收速度小于服务端发送速度,数据会在应用层缓冲区暂存等待发送。
此属性用来设置当前连接的应用层发送缓冲区大小。不设置默认为Connection::defaultMaxSendBufferSize(1MB)。
此属性影响onBufferFull回调。
实例:maxSendBufferSize为1024时候
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
$count=0;
$worker = new Worker('websocket://0.0.0.0:8484');
$worker->onConnect = function(TcpConnection $connection)
{
global $count;
// 设置当前连接的应用层发送缓冲区大小为1024字节
$connection->maxSendBufferSize = 1024;
for($i=0;$i<10000;$i++){
$count=$i;
$connection->send($i);
}
};
$worker->onBufferFull=function(){
global $count;
echo "\r\n";
var_dump("缓冲区过载! count:".$count);
echo "\r\n";
};
// 运行worker
Worker::runAll();
?>
自然数字顺序测试最大承载226(有websocket连接时):
[root@izj6c2jeancylo0ppo4vz5z workerman]# php test.php start
Workerman[test.php] start in DEBUG mode
------------------------------------------- WORKERMAN --------------------------------------------
Workerman version:4.0.22 PHP version:7.0.33
-------------------------------------------- WORKERS ---------------------------------------------
proto user worker listen processes status
tcp root none websocket://0.0.0.0:8484 1 [OK]
--------------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
string(28) "缓冲区过载! count:226"
实例:maxSendBufferSize为1025时候
[root@izj6c2jeancylo0ppo4vz5z workerman]# php test.php start
Workerman[test.php] start in DEBUG mode
------------------------------------------- WORKERMAN --------------------------------------------
Workerman version:4.0.22 PHP version:7.0.33
-------------------------------------------- WORKERS ---------------------------------------------
proto user worker listen processes status
tcp root none websocket://0.0.0.0:8484 1 [OK]
--------------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
string(28) "缓冲区过载! count:226"
string(28) "缓冲区过载! count:227"
出现多次缓冲区过载,怀疑是第一次缓冲区过载后,很短时间内正好超载的那个边界值又完成了发送,然后接下来立马又向缓冲区填充了新的数据导致再次过载。
具体原理这里不晓得。
也有可能是send并发导致。(可能几率小)。
关键字词:workerman,TcpConnection,maxSendBufferSize
相关文章
- workerman类TcpConnection的maxPackageSize属性(最大
- workerman类TcpConnection的defaultMaxSendBufferSize
- workerman类AsyncTcpConnection的__construct方法实现
- workerman类AsyncTcpConnection的__construct方法实现
- workerman接口listen实现内外部通信(管理后台或系统向w
- php或workerman利用posix_getpid函数获取进程id
- workerman回调onBufferFull(缓冲区溢出)
- workerman回调onBufferFull默认缓冲区大小配置
- workerman回调onClose
- workerman回调onConnect获取远端ip