m6w6 / ext-http

Extended HTTP Support
BSD 2-Clause "Simplified" License
79 stars 22 forks source link

[Question] Migration from php curl to pecl http: five fold increase in processes #87

Closed Slind14 closed 3 years ago

Slind14 commented 5 years ago

Hi, we migrated from php's curl implementation to pecl-http in order to be able to reuse existing connections and avoid hitting limitations there.

With the migration we experienced a five fold increase of current processes. Are we missing something?

        $client = new http\Client('curl', 'globalHandle');
        $request = new http\Client\Request;
        $reqQuery = new http\QueryString("user=" . $config['username'] . "&password=" . $config['password'] . "&max_execution_time=3&enable_http_compression=1&query=".urlencode($queryParts[0] . 'VALUES'));
        $body = new http\Message\Body;
        $body->append($queryParts[1]);
        $request->setOptions([ 'timeout' => 1, 'connecttimeout' => 1 ]);
        $request->setRequestUrl($url);
        $request->setQuery($reqQuery);
        $request->setRequestMethod('POST');
        $request->setBody($body);
        $client->enqueue($request);
        $client->send();

(Migration happened on the 11th) image image Requests stayed (more or less) the same: image

m6w6 commented 5 years ago

Hi, this is probably due to the type of resolver libcurl was built with, i.e. threaded resolver.

Slind14 commented 5 years ago

Is there anything I could do to reduce this? I had to dump open files immensely.

m6w6 commented 5 years ago

I guess you could build libcurl with the threaded resolver disabled, or presumably better, with the async resolver (c-ares) instead.

Slind14 commented 5 years ago

So kinda like this? https://stackoverflow.com/a/41986646/2693017 I have never done anything like it yet.

m6w6 commented 5 years ago

How did it go?

Slind14 commented 5 years ago

I haven't found the time to do it yet.

m6w6 commented 5 years ago

Thinking again about it, the threaded resolver should have been already in use with ext/curl, so it seems unlikely the threaded resolver is the actual problem.

Where's the data from the graphs coming from? What's the big drop in the second one?

Slind14 commented 5 years ago

The data is from https://amplify.nginx.com/ The drop in the second one is from switching from php curl to pecl. (the php curl one doesn't reuse connections and didn't close them either)

m6w6 commented 5 years ago

Hm, sorry, still doesn't make a lot of sense to me...

m6w6 commented 5 years ago

Checking their docs and see if they help me understand...

m6w6 commented 5 years ago

max_child: The number of times, the process limit has been reached.

Okay, so the drop was just due to restart.

m6w6 commented 3 years ago

Don't hesitate to reopen when there are new insights.