Skip to content

Automatically disable http client tracing / logging when approaching memory limit #45974

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

Closed
Tobion opened this issue Apr 7, 2022 · 12 comments
Closed
Labels
Cache Feature HttpClient RFC RFC = Request For Comments (proposals about features that you want to be discussed) Stalled

Comments

@Tobion
Copy link
Contributor

Tobion commented Apr 7, 2022

Description

I consume API responses in parallel that can be very big and also multiplex the response handling using the Symfony HTTP client which works great. You can run into memory limits easily which is understandable and which I can tune by selecting which request/responses to process in parallel. This is under my control.

But I've noticed that the even bigger problem for the memory limit is the tracing of the profiler and the SQL logger in the dev environment. So things can easily work in prod mode but in dev mode even twice the amount of memory won't be enough. This is kind of annoying and makes it hard to estimate how much memory is needed or how to tune things when developing.

There are two memory offenders:

  1. http tracing which adds the response body to the profiler. This can be disabled manually with
$this->client->request('GET', '...', [
    'extra' => ['trace_content' => false],
]);
  1. Since I cache the data in an SQL database the DoctrineDbalAdapter will execute SQL statements with big params. So the logging additionally also consumes alot of memory. In this past it seems there was a way to disable SQL logging for certain parts by removing the SqlLogger on the connection configuration. See Recommended approach for disabling the logging in some occurrences doctrine/DoctrineBundle#787 or https://stackoverflow.com/questions/35192173/how-to-disable-query-logging-in-console-while-load-doctrine-fixtures
    This does not seem to work anymore since Introduce logging middleware doctrine/dbal#4967 which always logs the sql statements.

So even if there were workarounds for these problems, it still requires alot of debugging and manual solutions.
I think it should be possible to have good profiling and logs while not overdo it to prevent out of memory issues.
What I would propose:
The http client and the cache component would measure the memory consumption in debug mode when doing http requests or inserting cache items and if the used memory is approaching the memory limit, then they should automatically disable content tracing and logging for those items. Or it could at least truncate the data.

This approach would probably also work for other parts of the dev profiling. As the http client and cache can process large amounts of data, I think this is a good first step.

@Tobion Tobion added Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) Cache HttpClient labels Apr 7, 2022
@gggeek
Copy link

gggeek commented Apr 10, 2022

I agree that this can be a problem. Especially when writing cli code such as daemons, batch jobs, migrations or such, which can do a huge amount of calls.

Otoh I am not too sure about the proposed solution: I think that either a dev has the need to trace all calls, or he does not need the trace at all. Often one is interested in call nr. 357.432 out of 1.000.000, but without knowing its exact position in advance.
Which means that having a trace only contain the first N calls might not be useful, and actually introduce more complexity - "how do I enable tracing of the remaining 900K calls?".

We might of f.e. start spooling to disk as soon as close to memory_limit, but A) that is not a safe science. There is always the risk of going over it by fetching data, and B) even disks get full

@nicolas-grekas
Copy link
Member

We could go with a FIFO approach for traces, with a buffer of eg 10000 items max. That would apply to any collection of data collected for the profiler.

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@Tobion
Copy link
Contributor Author

Tobion commented Nov 7, 2022

Lets keep it open

@carsonbot carsonbot removed the Stalled label Nov 7, 2022
@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@carsonbot
Copy link

Just a quick reminder to make a comment on this. If I don't hear anything I'll close this.

@Tobion
Copy link
Contributor Author

Tobion commented Jul 5, 2023

Keep

@carsonbot carsonbot removed the Stalled label Jul 5, 2023
@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@tarlepp
Copy link
Contributor

tarlepp commented Jan 17, 2024

I think this is still open - https://symfony-devs.slack.com/archives/C3EQ7S3MJ/p1705526254152239

@carsonbot carsonbot removed the Stalled label Jan 17, 2024
@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@carsonbot
Copy link

Friendly ping? Should this still be open? I will close if I don't hear anything.

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cache Feature HttpClient RFC RFC = Request For Comments (proposals about features that you want to be discussed) Stalled
Projects
None yet
Development

No branches or pull requests

5 participants