elastic / elasticsearch-php

Official PHP client for Elasticsearch.
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
MIT License
5.26k stars 965 forks source link

Elasticsearch\Common\Exceptions\Curl\CouldNotConnectToHost cURL error 7: #1225

Closed ajrpayne closed 2 years ago

ajrpayne commented 2 years ago

We are using SimpleConnectionPool, multiHandler, future mode off, to index single documents, not using bulk(Can't change this currently). During periods of high ingest we get the below error.

Elasticsearch\Common\Exceptions\Curl\CouldNotConnectToHost cURL error 7:

With no further details as to what the curl 7 error is. Everything seems to be running normally on elasticsearch, and the requests continue to flow as normal after the period of high ingest. Hoping to find some direction here.

System details

ezimuel commented 2 years ago

@ajrpayne the cURL error 7 is Failed to connect() to host or proxy. Are you using a proxy/firewall? If you have this issue only in high traffic scenario I think this can be related to the time wait TCP settings. I found an interesting discussion about this issue here. How many connections do you see in high ingest scenario using netstat command? A possible fix is to set the tcp_tw_reuse to 1 but this can affect the TCP especially using NAT.

sudo sysctl -w net.ipv4.tcp_tw_reuse=1

The tcp_tw_reuse allow to reuse TIME_WAIT sockets for new connections when it is safe from protocol viewpoint. Here you can read a very detailed explanation of this settings. Changing this settings can be dangerous, you can definitely try if the PHP application is isolated from other services. A better aprroach maybe is to scale your PHP application using another server. In this way, you can spread the HTTP connections using multiple sources.