I have not found much information about concurrency option in Pool.
If this is a number of TCP sockets which could be opened on server, then the question is "What number of concurrency could I use in order to handle requests quicker?".
I have this example of using Pool:
// I am using Laravel, this is basically retrieving entities from DB
$exchangers = Exchanger::all();
$client = new Guzzlelient();
$requests = [];
foreach ($exchangers as $exchanger)
{
$requests[$exchanger->id] = new Request('GET', $exchanger->xml_feed_url);
}
$pool = new Pool($client, $requests, [
'concurrency' => 5,
'options' => [
'verify' => false
],
'fulfilled' => function ($response, $index) {
echo "fulfilled: " . $index."\n";
},
'rejected' => function ($reason, $index) {
echo "rejected: " . $index. "\n";
},
]);
// Initiate the transfers and create a promise
$promise = $pool->promise();
// Force the pool of requests to complete.
$promise->wait();
It took about 10 seconds to go over ~20 sites with concurrency set to 5. Now I'm thinking like, "Okay, this is number of sockets. Sockets ~ Ports. I have 65535 ports. Cool, why not set concurrency 50 and I should get all results in a second or so?". Nice, I set it to 50 and... it took 8 seconds. However an hour ago the results were like 18 seconds vs 24 (for 50 concurrency, so it's even slower).
So the question is:
- How to determine which concurrency I could use in order to optimize the proccess and make it faster as it possible to do?
- What is concurrency anyway?