简体   繁体   中英

ElasticSearch\Client in PHP uses MultiCurl

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM