按照文檔中并發(fā)請求 使用的,結(jié)果確實時間疊加,并沒有速度快
這里寫問題描述
$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();
你那個GRequest里面是不是用requestAsync請求?
這個文檔中的源碼 ,在webman中 有Request 沖突 所以用了 as 別名,就是文檔中的源碼,但是請求10次的時間 是 請求一次的時間 的10倍,發(fā)現(xiàn)并發(fā)沒起作用
你那個GRequest里面是不是用requestAsync請求?
$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);
};
}
};
不是呀,這個是文檔中的 yield new Request('GET', $uri); Request 不是我封裝的,這個和webman 的support\Request有名字沖突,就起了個別名
用你代碼試了,沒這個疊加的問題
本機測試,total = 1 , 耗時70ms, total 1-10 耗時 350ms . total 10以上 約等于 total / 10 * 350
total10的時候,concurrency用的1-10都差不多時間,你調(diào)整total和concurrency,你會發(fā)現(xiàn)到達一個閾值的時候,就是疊加,猜測是本身并concurrency有上限