Skip to content

Commit ab2bfc5

Browse files
committed
Fix config for 3x rtt
1 parent 1f7d723 commit ab2bfc5

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Per default in most PHP applications, a new curl handle is created for each outgoing request, which will require a new TCP connection to be established, and a TLS handshake to be performed if the request is made over HTTPS.
66

7-
The TLS handshake can be a big performance penalty for applications that strive for low latency, as it requires 2 round trips between the client and the server. This can easily reach 100ms and more depending on your round trip latency to the server.
7+
The TLS handshake can be a big performance penalty for applications that strive for low latency, as it requires 2 round trips between the client and the server for the TLS handshake, and one round trip for the TCP connection. This can easily reach 100ms and more depending on your round trip latency to the server.
88

99
# Solution
1010

@@ -26,23 +26,26 @@ composer require cego/curl-handle-reuse-laravel-octane
2626
Feel free to open issues or pull requests if you have any suggestions or improvements. Remember to run php-cs-fixer, unittests and phpstan before opening a pull request.
2727

2828
# Performance
29-
You can expect to reduce the latency of outgoing requests by 2 times the latency roundtrip. The speedup factor will depend on the latency of the server you are connecting to, compared to the execution time of the endpoint you are calling.
29+
You can expect to reduce the latency of outgoing requests by 3 times the latency roundtrip. The speedup factor will depend on the latency of the server you are connecting to, compared to the execution time of the endpoint you are calling.
3030

3131
For example if you have a server with a 100ms roundtrip latency, and the endpoint takes 100ms to execute, then you are likely to see a speedup from 400ms to 200ms.
3232

3333
## Benchmarks
34-
See tests/Benchmark for a simple PHPBench setup that pings github.com/robots.txt 50 times with and without the package. With the package, a prewarmed curl handle is used.
34+
See tests/Benchmark for a simple PHPBench setup that pings github.com/robots.txt 50 times with and without the package. With the package, a prewarmed curl handle is used. The round-trip latency was measured to approximately 19.5ms.
3535

3636
```
37-
+-----------------+------------------------------------+----------+----------+----------+----------+--------+---------+
38-
| benchmark | subject | memory | min | max | mode | rstdev | stdev |
39-
+-----------------+------------------------------------+----------+----------+----------+----------+--------+---------+
40-
| HttpReusedBench | benchHttpWithReusedCurlHandle () | 16.448mb | 25.870ms | 25.870ms | 25.870ms | ±0.00% | 0.000μs |
41-
| HttpBench | benchHttpWithoutServiceProvider () | 16.411mb | 76.186ms | 76.186ms | 76.186ms | ±0.00% | 0.000μs |
42-
+-----------------+------------------------------------+----------+----------+----------+----------+--------+---------+
43-
37+
+---------------------------+----------------------------------------------------+----------+-----------+-----------+-----------+--------+---------+
38+
| benchmark | subject | memory | min | max | mode | rstdev | stdev |
39+
+---------------------------+----------------------------------------------------+----------+-----------+-----------+-----------+--------+---------+
40+
| HttpReusedCurlHandleBench | benchHttpWithoutReusedCurlHandle () | 16.581mb | 77.222ms | 77.222ms | 77.222ms | ±0.00% | 0.000μs |
41+
| HttpReusedCurlHandleBench | benchHttpWithReusedCurlHandle () | 16.607mb | 20.812ms | 20.812ms | 20.812ms | ±0.00% | 0.000μs |
42+
| HttpReusedCurlHandleBench | benchHttpWithReusedCurlHandleMultipleOrigins () | 18.103mb | 47.237ms | 47.237ms | 47.237ms | ±0.00% | 0.000μs |
43+
| HttpReusedCurlHandleBench | benchHttpWithoutReusedCurlHandleMultipleOrigins () | 18.078mb | 181.377ms | 181.377ms | 181.377ms | ±0.00% | 0.000μs |
44+
+---------------------------+----------------------------------------------------+----------+-----------+-----------+-----------+--------+---------+
4445
```
4546

47+
As can be seen, the benchmark of querying github.com/robots.txt 50 times is reduced from 77.222ms to 20.812ms, which is approximately 3x roundtrip latency of 19.5ms. (it would be equivalent to roundtrip latency of 18.8ms)
48+
4649

4750
## See also
4851
Aaron Francis has covered this topic in a video on his YouTube channel, where he explains the performance benefits of reusing curl handles in Laravel Octane. You can watch the video here:

src/CurlHandleReuseLaravelOctaneServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function register(): void
1111
{
1212
$this->mergeConfigFrom(__DIR__ . '/../config/curl-handle-reuse-laravel-octane.php', 'curl-handle-reuse-laravel-octane');
1313
$this->app->instance(ReusedCurlHandle::class, new ReusedCurlHandle(
14-
config('curl-handle-reuse-laravel-octane.max_handles', 1000),
14+
config('curl-handle-reuse-laravel-octane.max_handles'),
1515
));
1616
$this->app->bind(Factory::class, ReusedCurlHandleFactory::class);
1717
}

tests/Benchmark/HttpReusedCurlHandleBench.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public function prewarmWithServiceProvider(): void
3535
#[BeforeMethods('prewarm'), Revs(50)]
3636
public function benchHttpWithoutReusedCurlHandle()
3737
{
38-
Http::get('https://ventraip.com.au/robots.txt');
38+
Http::get('https://github.com/robots.txt');
3939
}
4040

4141
#[BeforeMethods('prewarmWithServiceProvider'), Revs(50)]
4242
public function benchHttpWithReusedCurlHandle()
4343
{
44-
Http::get('https://ventraip.com.au/robots.txt');
44+
Http::get('https://github.com/robots.txt');
4545
}
4646

4747
#[BeforeMethods('prewarmWithServiceProvider'), Revs(50)]

0 commit comments

Comments
 (0)