AsyncTcpConnection并发连接测试,ChatGateway内存一直增长

TKOL

使用文档中给的AsyncTcpConnection并发连接测试,ChatGateway内存一直增长
时间越长,内存大小超过10G

----------------------------------------------GLOBAL STATUS----------------------------------------------------
Workerman version:3.5.11          PHP version:5.5.99-hiphop
start time:2018-07-02 18:00:49   run 0 days 0 hours
load average: 8.91, 10, 13       event-loop:\Workerman\Events\Select
4 workers       51 processes
worker_name        exit_status      exit_count
ChatBusinessWorker 0                0
ChatGateway        0                0
Register           0                0
WebServer          0                0
----------------------------------------------PROCESS STATUS---------------------------------------------------
pid memory  listening                worker_name        connections send_fail timers  total_request qps    status
3984    6.13M   none                     ChatBusinessWorker 25          0         1       25904         28     
3985    6.14M   none                     ChatBusinessWorker 25          0         1       25834         27     
...
4008    6.13M   none                     ChatBusinessWorker 25          0         1       25926         29     
4009    6.15M   none                     ChatBusinessWorker 25          0         1       25762         28     
4010    28.41M  websocket://0.0.0.0:8272 ChatGateway        455         0         3       680830        795    
4011    28.45M  websocket://0.0.0.0:8272 ChatGateway        455         0         3       680586        756    
...
4033    27.89M  websocket://0.0.0.0:8272 ChatGateway        402         0         3       672936        797    
4035    28.4M   websocket://0.0.0.0:8272 ChatGateway        451         0         3       680821        766    
4036    5.75M   text://0.0.0.0:8236      Register           48          0         0       1077          0      

----------------------------------------------PROCESS STATUS---------------------------------------------------
Summary 828M    -                        -                  11308       0         96      16924905      19481  

Press Ctrl+C to quit.

测试脚本:

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;
    echo $count . "\n";
    if ($count++ >= 10000) return;
    // 建立异步链接
    $con = new AsyncTcpConnection('ws://127.0.0.1:8272');
    $con->onConnect = function($con) {
        // 递归调用connect
        connect();
    };
    $con->onMessage = function($con, $msg) {
        $msgInfo = json_decode($msg, true);
        if(isset($msgInfo) && $msgInfo == 'ping'){
            $con->send('{"type":"pong"}');
        }
        echo "r $msg\n";
    };
    $con->onClose = function($con) {
        echo "con close\n";
    };

    Timer::add(5, function()use($con){
        $con->send('{"type":"pong"}');
    });
    $con->connect();
    echo $count, " connections complete\n";
}
Worker::$stdoutFile = '/home/work/im/workerman-chat/start_qa.log';
Worker::runAll();

event.php

use \GatewayWorker\Lib\Gateway;

class Events
{

    public static function onConnect($client_id)
    {
        $new_message = array(
            'id'=>$client_id,
        );

        Gateway::sendToCurrentClient(json_encode($new_message));
    }

   /**
    * 有消息时
    * @param int $client_id
    * @param mixed $message
    */
   public static function onMessage($client_id, $message)
   {
       Gateway::sendToCurrentClient( json_encode(Gateway::getAllClientIdCount()));
       return ;
   }

   /**
    * 当客户端断开连接时
    * @param integer $client_id 客户端id
    */
   public static function onClose($client_id)
   {
   }

}
阅读 2019
4个回答

walkor

根据手册,压测需要安装event扩展并按照手册优化linix内核

  • 暂无评论
TKOL

安装event扩展并按照手册优化linix内核就能解决这个问题了吗?
那就是说现在是正常现象是吗?

  • 暂无评论
walkor

安装event扩展并按照手册优化linix内核后不会占用无限增长。
没有安装event扩展,默认使用select IO复用,最多支持1000连接,超过1000的连接会造成内存泄漏。
内存无限增长肯定不是正常现象。

  • 暂无评论
TKOL

好的,那我优化后再试试,感谢

  • 暂无评论