Reputation: 727
Whilst profiling my product that uses the ElasticSearch PHP Client i noticed that natively it uses the CurlMulti adapter from Guzzle when performing a request.
This seems to cause alot of overhead and comparing timings between this Client and my own cURL downloader shows ES\Client is almost 10x slower. It looks like it's purely to do with using multi.
How can i update the adapter to use an inline curl Request?
I cant seem to find the section in the documentation that lets me change this.
Upvotes: 1
Views: 531
Reputation: 9721
Sorry, it isn't currently well documented. Your benchmark is accurate - the usage of Guzzle introduces a fairly significant overhead. The overhead is actually due to autoloading costs of various Guzzle classes. You can replace the Guzzle Connection with a CurlMultiConnection class, which is a lightweight replacement.
You can enable it with:
$params['connectionClass'] = '\Elasticsearch\Connections\CurlMultiConnection';
$client = new Client($params);
Using this syntax, you could also write your own replacement Connection class. It just needs to follow the ConnectionInterface
interface.
Based on my benchmarks (admittedly fairly old at this point):
Guzzle
No Network: 7.095 ms
Network Ping: 15.856 ms
CurlMultiConnection
No Network: 4.345 ms
Network Ping: 7.122 ms
Based on profiling, the difference in speed is almost entirely autoloading. Once loaded, both Connection classes perform network operations at the same throughput. The execution speed improves dramatically for both Connection classes when used with APC or HHVM.
Upvotes: 1