Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced memory consumption #527

Merged
merged 3 commits into from
Nov 30, 2023

Conversation

nerg4l
Copy link
Contributor

@nerg4l nerg4l commented Nov 29, 2023

Reusing the file resource reduces the memory usage by almost 40%.

Peak memory usage:

  • 19573984 bytes without change, triggered GC twice.
  • 12002672 bytes with change, triggered GC twice.
  • 13291832 bytes with Guzzle client, triggered GC zero times.

@nerg4l nerg4l mentioned this pull request Nov 29, 2023
@nerg4l
Copy link
Contributor Author

nerg4l commented Nov 30, 2023

Time:

  • 01:03.780 without change, triggered GC twice.
  • 00:42.684 with change, triggered GC twice.
  • 00:08.776 with Guzzle client, triggered GC zero times.

This shows quite big difference between \Embed\Http\CurlClient and Guzzle client. Maybe it would make sense to add a getClientFactory and only fall back to CurlClient when it is necessary.

Also, I couldn't figure out what happens with the curl_multi_* commands because $connection->result is ignored and $connection->exec is called anyway. It looks like exec is called twice for each connection, once curl_multi_exec and later curl_exec, am I correct?

if ($info) {
foreach ($connections as $connection) {
if ($connection->curl === $info['handle']) {
$connection->result = $info['result'];
break;
}
}
}

@oscarotero oscarotero merged commit 8a5d7a1 into oscarotero:master Nov 30, 2023
0 of 3 checks passed
@oscarotero
Copy link
Owner

Thanks!
About $connection->exec, probably this is the reason of the bug.
It's called here: https://github.com/oscarotero/Embed/blob/master/src/Http/CurlDispatcher.php#L80 to construct the response, but the function also run curl_exec https://github.com/oscarotero/Embed/blob/master/src/Http/CurlDispatcher.php#L118

oscarotero added a commit that referenced this pull request Nov 30, 2023
@oscarotero
Copy link
Owner

oscarotero commented Nov 30, 2023

I just made this change 51b1aea
Can you test the memory usage?

@nerg4l nerg4l deleted the fix/memory-consumption branch December 10, 2023 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants