国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

使用 workerman 做TCP client 做服務(wù)器的壓力測試

aidong_wang

物聯(lián)網(wǎng)業(yè)務(wù)單純測試 TCP 連接數(shù)量已經(jīng)沒用意義,所以需要做壓力測試的時候模擬真實業(yè)務(wù),比如有5萬臺設(shè)備,每分鐘內(nèi)都上傳一次 GPS 數(shù)據(jù)等。這時候測試的不再是 workerman 框架自身的性能,而是 Server 端整體的性能。

昨天開始嘗試用 workerman 作為 TCP Client 與 server 對接(server 端也是 wokerman-gatewway),通信協(xié)議是基于 TCP 的自定義協(xié)議,下面是示例代碼:

<?php

    use Protocols\LindeProtocol;
    use Workerman\Lib\Timer;
    use \Workerman\Worker;
    use \Workerman\Connection\AsyncTcpConnection;

    require_once __DIR__ . '/Autoloader.php';

    $deviceMaxNumber = 10;

    for ($i = 0; $i < $deviceMaxNumber; $i++) {

        $task = new Worker();

        $deviceId = "99999888887777$i";

        $task->onWorkerStart = function ($task) use ($deviceId) {

            require_once __DIR__ . '/SmartLinkBusinessWorker.php';
            $busWorker     = new \Workerman\SmartLinkBusinessWorker($deviceId);
            $time_interval = 1;
            Timer::add($time_interval,
                function () use ($busWorker) {
                    $busWorker->timerTick();
                }
            );

            $connection = new AsyncTcpConnection('lindeProtocol://_._._._:*);
            // 當(dāng)連接建立成功時
            $connection->onConnect    = ;
            $connection->onMessage    = ;
            $connection->onClose      = ;
            $connection->onError      = ;
            $connection->onWorkerStop = ;
            $connection->connect();
        };
    }

// 運行worker
    Worker::runAll();

目前是模擬10個客戶端沒有問題,如果想模擬一萬個客戶端,能否繼續(xù)使用上面的方法(只把 deviceMaxNumber 從10改成10000)?

或者能否指點一下更優(yōu)的方案?

10012 4 0
4個回答

keytehu

http://wenda.workerman.net/?/question/1453
直接new 多個 AasyncTcpConnection,類似這樣估計可行。

  • 暫無評論
phpcreeper

個人認(rèn)為作者這個方案不是很好,因為 deviceMaxNumber 的數(shù)量直接決定了啟動的子進程數(shù)量,而且每個子進程只維持了一個AsyncTcpConnection連接,隨著deviceMaxNumber 數(shù)量的增加,進程啟動開銷隨之增加,其實可以將進程分組,每組進程內(nèi)維持N個鏈接,類似負(fù)載均衡效果。

  • 暫無評論
aidong_wang

大家試過workerman/gateway-worker 做為 server 端,能保持多少 TCP 鏈接嗎?
我的情況:

服務(wù)器:

Centos 6.8
4核心
16G 內(nèi)存
已經(jīng)完全按照 Linux 內(nèi)核調(diào)優(yōu)參數(shù)章節(jié)進行了調(diào)優(yōu)

但成功建立 TCP 鏈接始終不超過兩千,達到一千多以后,AsyncTcpConnection的 onError 函數(shù)頻繁被觸發(fā):Error code:1 msg:connect 115.159.77.248:20073 fail after 127.281 seconds

    $task = new Worker();

    $task->count = 50;

    $task->onWorkerStart = function ($task) {

        $deviceMaxNumber = 100;
        for ($i = 0; $i < $deviceMaxNumber; $i  ) {

            $taskId = $task->id;

            $deviceId = "99999$taskId" . "888887777$i";

            require_once __DIR__ . '/SmartLinkBusinessWorker.php';
            $busWorker = new \Workerman\SmartLinkBusinessWorker($deviceId);

            $connection = new AsyncTcpConnection('lindeProtocol://_._._._:*');
            // 當(dāng)連接建立成功時
            $connection->onConnect    = ;
            $connection->onMessage    = ;
            $connection->onClose      = ;
            $connection->onError      = ;
            $connection->onWorkerStop = ;
            $connection->connect();

            //sleep(1);

        }
    };

現(xiàn)在是開啟50個進程,每個進程維護100個連接。

這是 “/etc/sysctl.conf” 配置

fs.file-max=6815744
net.ipv4.tcp_max_tw_buckets = 20000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv4.tcp_max_syn_backlog = 262144
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 65535
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_fin_timeout = 20
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_syncookies = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle=0
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.ip_local_port_range = 1024 65000
net.nf_conntrack_max = 6553500
net.netfilter.nf_conntrack_max = 6553500
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_established = 3600
net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.lo.disable_ipv6 = 0

客戶端連接失敗時,workerman/gateway-worker 端沒有觸發(fā)任何錯誤信息,看起來狀態(tài)良好

----------------------------------------------GLOBAL STATUS----------------------------------------------------
Workerman version:3.5.11          PHP version:7.1.10
start time:2018-08-06 23:08:06   run 0 days 9 hours
load average: 0, 0, 0            event-loop:\Workerman\Events\Event
4 workers       83 processes
worker_name       exit_status      exit_count
linde_test_worker 0                0
linde_gateway     0                0
internalGateway   0                0
Register          0                0
----------------------------------------------PROCESS STATUS---------------------------------------------------
pid     memory  listening                     worker_name       connections send_fail timers  total_request qps    status
13458   6M      none                          linde_test_worker 53          0         0       5538          0      
13459   6M      none                          linde_test_worker 53          0         0       11943         0      
13460   6M      none                          linde_test_worker 53          0         0       10641         0      
13461   6M      none                          linde_test_worker 53          0         0       17033         0      
13462   6M      none                          linde_test_worker 53          0         0       14599         0      
13463   6M      none                          linde_test_worker 53          0         0       6763          0      
13464   6M      none                          linde_test_worker 53          0         0       13083         0      
13466   6M      none                          linde_test_worker 53          0         0       15920         0      
13467   6M      none                          linde_test_worker 53          0         0       15398         0      
13468   6M      none                          linde_test_worker 53          0         0       15713         0      
13469   6M      none                          linde_test_worker 53          0         0       11995         0      
13470   6M      none                          linde_test_worker 53          0         0       14709         0      
13471   6M      none                          linde_test_worker 53          0         0       18411         0      
13472   6M      none                          linde_test_worker 53          0         0       18084         0      
13473   6M      none                          linde_test_worker 53          0         0       13224         0      
13474   6M      none                          linde_test_worker 53          0         0       14478         0      
13475   6M      none                          linde_test_worker 53          0         0       10551         0      
13476   6M      none                          linde_test_worker 53          0         0       16148         0      
13479   6M      none                          linde_test_worker 53          0         0       26092         0      
13480   6M      none                          linde_test_worker 53          0         0       19470         0      
13481   6M      none                          linde_test_worker 53          0         0       26773         0      
13482   6M      none                          linde_test_worker 53          0         0       19910         0      
13483   6M      none                          linde_test_worker 53          0         0       14391         0      
13484   6M      none                          linde_test_worker 53          0         0       13781         0      
13486   6M      none                          linde_test_worker 53          0         0       7992          0      
13487   6M      none                          linde_test_worker 53          0         0       6793          0      
13488   6M      none                          linde_test_worker 53          0         0       11859         0      
13489   6M      none                          linde_test_worker 53          0         0       13144         0      
13490   6M      none                          linde_test_worker 53          0         0       12420         0      
13491   6M      none                          linde_test_worker 53          0         0       16900         0      
13492   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1730          0      
13493   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1740          0      
13494   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1760          0      
13495   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1740          0      
13497   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       4302          0      
13498   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       4330          0      
13499   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       4318          0      
13500   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1740          0      
13501   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1745          0      
13502   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1735          0      
13503   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       6904          0      
13505   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       6898          0      
13506   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1735          0      
13507   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1740          0      
13509   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1735          0      
13510   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1741          0      
13511   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1735          0      
13512   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1730          0      
13513   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1755          0      
13514   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1730          0      
13515   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1746          0      
13516   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       4322          0      
13517   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       4309          0      
13518   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1735          0      
13521   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1750          0      
13522   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1745          0      
13523   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       14851         0      
13524   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       4342          0      
13525   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       4322          0      
13526   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       4325          0      
13527   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       4335          0      
13528   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       4305          0      
13529   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       1735          0      
13530   2M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       4312          0      
13531   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       12079         0      
13532   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       6929          0      
13533   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     33          0         0       43721         0      
13534   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       9568          0      
13535   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       19957         0      
13536   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     33          0         0       38502         0      
13537   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       17961         0      
13538   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       66837         0      
13539   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     32          0         0       33455         0      
13540   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       85416         0      
13541   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       32825         0      
13542   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       12241         0      
13543   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     32          0         0       151696        0      
13544   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       95544         0      
13545   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     32          0         0       193222        0      
13546   4M      lindeProtocol://0.0.0.0:20073 linde_gateway     31          0         0       17377         0      
13547   2M      text://127.0.0.1:7274         internalGateway   31          0         0       1730          0      
13548   2M      text://127.0.0.1:7274         internalGateway   31          0         0       1730          0      
13549   4M      text://0.0.0.0:1410           Register          82          0         0       82            0      
----------------------------------------------PROCESS STATUS---------------------------------------------------
Summary 330M    -                             -                 3291        0         0       1385605       0              

客戶端維持每10秒發(fā)送一次心跳,煩請大家?guī)兔纯?/p>

  • 暫無評論
walkor 打賞

客戶端所在服務(wù)器也要按照workerman手冊調(diào)優(yōu)內(nèi)核,安裝event擴展。

  • 暫無評論
年代過于久遠,無法發(fā)表回答
??