swoole curl和協程http的性能比較

    function curl($ip){
        $ch = curl_init('http://'.$ip);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
        $rs = curl_exec($ch);
        curl_close($ch);
        return $rs;
    }
    function co_http($ip){
        $cli = new Swoole\Coroutine\Http\Client($ip, 80);
        $cli->get('/');
        return $cii->body;
    }

    $server = new swoole_http_server('0.0.0.0',9501);
    $server->set([
    'daemonize' => true,
    'worker_num' => 4,
    'backlog' => 128,
    'max_request' => 5000,
    'dispatch_mode' => 1,
    'max_conn' => 65535,
    
    ]);
    $server->on('request',function(swoole_http_request $request,swoole_http_response $response){
    $ip = '151.101.1.69';

    co_http($ip);  //協程http

    #curl($ip);      //curl

    $response->end('Hello World2');
    });
    $server->start();

1g 1cpu 1core 1m/s  centos環境的測試

14worker進程

(2)開啓輪詢模式

測試性能比較: ab -c 10 -n 100 -k http://120.27.141.163/

curl:


Swoole/coroutine/http/client



 測試結果 :

Curl :           6.47/s

Coroutine:   162.77/s

 



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章