-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[13.x] Default PendingRequest@pool() to use 2 for concurrency
#57972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| [$exception] = $this->factory->pool(function (Pool $pool) { | ||
| return [ | ||
| $pool->get('https://laravel.com'), | ||
| ]; | ||
| }); | ||
|
|
||
| $this->assertInstanceOf(StrayRequestException::class, $exception); | ||
| $this->assertEquals('Attempted request to [https://laravel.com] without a matching fake.', $exception->getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified this test to match how we are testing other pooled exceptions in this file. The exception was being thrown because the pool was running in series rather than actually as a pool. This behavior better lines up with how it should be used (in my opinion).
|
I'm not sure I'm seeing them execute serially on my end. For instance, on my machine this does not take 5 seconds: <?php
use Illuminate\Http\Client\Pool;
use Illuminate\Support\Benchmark;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
$time = Benchmark::measure(function () {
$responses = Http::pool(fn (Pool $pool) => [
$pool->get('http://laravel.test/test'),
$pool->get('http://laravel.test/test'),
$pool->get('http://laravel.test/test'),
$pool->get('http://laravel.test/test'),
$pool->get('http://laravel.test/test'),
]);
dump(collect($responses)->map(fn ($response) => (string) $response));
});
dd($time);
});
Route::get('/test', function () {
sleep(1);
return (string) random_int(1, 100);
}); |
The fact that this defaults to null feels like a major footgun. Developers will think that they are getting the benefit of concurrent requests when in fact they are just being executed in series. Within the underlying Guzzle library, passing null does mean to execute without a cap.
Is 2 the right number? I have no idea. But I think anything is better than just defaulting to serial execution. Or we could change it to pass
0which I think would allow for unbounded concurrency.