使用文檔中給的AsyncTcpConnection并發(fā)連接測試,ChatGateway內(nèi)存一直增長
時間越長,內(nèi)存大小超過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) {
// 遞歸調(diào)用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)
{
}
}