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

已解決 GuzzleHttpPool 并發(fā)請(qǐng)求 沒有生效,并發(fā)請(qǐng)求時(shí)間是 正常一次的疊加,很奇怪呀

tanhongbin

問題描述

按照文檔中并發(fā)請(qǐng)求 使用的,結(jié)果確實(shí)時(shí)間疊加,并沒有速度快
這里寫問題描述

$client = new Client();

        $requests = function ($total) {
            $uri = 'http://www.baidu.com';
            for ($i = 0; $i < $total; $i++) {
                yield new GRequest('GET', $uri);
            }
        };

        $pool = new Pool($client, $requests(10), [
            'concurrency' => 10,
            'fulfilled' => function ($response, $index) {
                // this is delivered each successful response
            },
            'rejected' => function ($reason, $index) {
                // this is delivered each failed request
            },
        ]);

// Initiate the transfers and create a promise
        $promise = $pool->promise();

// Force the pool of requests to complete.
        $promise->wait();
1960 2 1
2個(gè)回答

nitron

你那個(gè)GRequest里面是不是用requestAsync請(qǐng)求?

  • tanhongbin 2023-05-05

    這個(gè)文檔中的源碼 ,在webman中 有Request 沖突 所以用了 as 別名,就是文檔中的源碼,但是請(qǐng)求10次的時(shí)間 是 請(qǐng)求一次的時(shí)間 的10倍,發(fā)現(xiàn)并發(fā)沒起作用

  • nitron 2023-05-05

    你那個(gè)GRequest里面是不是用requestAsync請(qǐng)求?

    
    $requests = function () use ($client, $total) {
        $uri = 'http://www.baidu.com';
            for ($i = 0; $i < $total; $i++) {
                 yield function() use ($client, $uri) {
                return $client->requestAsync('GET', $uri);
                 };
            }
    };
    
  • tanhongbin 2023-05-05

    不是呀,這個(gè)是文檔中的 yield new Request('GET', $uri); Request 不是我封裝的,這個(gè)和webman 的support\Request有名字沖突,就起了個(gè)別名

  • nitron 2023-05-05

    用你代碼試了,沒這個(gè)疊加的問題
    本機(jī)測(cè)試,total = 1 , 耗時(shí)70ms, total 1-10 耗時(shí) 350ms . total 10以上 約等于 total / 10 * 350

  • tanhongbin 2023-05-05

    這不就是疊加嘛,并發(fā)請(qǐng)求應(yīng)該是 total=1 和total = 10 時(shí)間差不多的

  • nitron 2023-05-05

    我concurrency用的5

  • nitron 2023-05-05

    total10的時(shí)候,concurrency用的1-10都差不多時(shí)間,你調(diào)整total和concurrency,你會(huì)發(fā)現(xiàn)到達(dá)一個(gè)閾值的時(shí)候,就是疊加,猜測(cè)是本身并concurrency有上限

  • tanhongbin 2023-05-05

    按照道理來說,請(qǐng)求一次和請(qǐng)求五次 應(yīng)該是時(shí)間一致的,不會(huì)相差很大

  • tanhongbin 2023-05-05

    你可以測(cè)試一下請(qǐng)求一次和請(qǐng)求五次,concurrency 設(shè)置成5試試,如果時(shí)間基本一致,那就是對(duì)了,如果還是時(shí)間疊加,那就不對(duì)

  • lobtao 2023-07-27

    用swoole或者workerman 原始的方式試試

小W

這就是官方的示例,最后怎么解決的

年代過于久遠(yuǎn),無法發(fā)表回答
??