-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[redis cache] mysterious millions of class metadata queries #3838
Comments
@flaushi hi, which version of Symfony 4 do you use? |
Hi, I am using 4.3.9 |
Potentially related to something like |
So, should I use
|
I think it needs to be a reference to this:
|
...which is |
If I understood your comment in the other issue correctly, the problem is not about Carbon, it also affects original DateTime instances? 😳 |
It affects any |
Ok, thanks. I annotated all |
Not sure: it's designed to work that way, since the ORM is trying to type-guess what was given, and first checking if it is an entity from which we need to extract metadata. What could be done, is making a map of types to be excluded from metadata lookup (in the metadata factory) |
So you mean a pre-population of |
More like a "miss" list, together with a "hit" list. Whenever metadata is not found in the metadata driver, a second lookup should fail immediately. |
Sounds like caching the metadata cache results to me... I think for datetime the lookup can just be omitted completely. Same as for scalars... BTW at which point in the code are scalars handled differently? Exactly this position should also be the forking point for datetime... |
|
I understand your view. I think this might turn into a philosophical discussion about whether or not one should handle very frequent special cases explicitly. Yes, DateTime is an object, but no, it's no entity, since for DBAL it is always converted into a string representation and then given to the DB. BTW: Could I just use |
That would work, but then you lose the advantage of conversion. All you're required to do to bypass metadata lookups is to provide the type of the parameter (third argument). Otherwise, the ORM will just try its best effort at finding a fitting type. |
Yes, absolutely, I already added the third parameter everywhere. I was just saying that the need for this third parameter (just for the DateTime case and to prevent the lookup) is counterintuitive. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug Report
My setup:
I am using redis as cache provider (metadata and query cache) in my symfony 4 application.
I have rewritten the doctrine DBAL
datetime
type to automatically hydrateCarbon
instances.By chance, I looked into
redis-cli
and inspected theMONITOR
command which prints each executed command on the redis server. So I found this output:This shows that the app is querying class meta data for Carbon instances over and over.
I assume these queries must have a performance impact.
Even worse, this behaviour does not only occur once per request, I found this during one console command, so doctrine seems to query the class metadata for each fetched object.
Summary
The DBAL issues many cache queries for Carbon class metadata. They are so frequent that it gives a performance impact.
How to reproduce
My entities are annotated in a standard fashion, e.g.:
Here is my symfony config and the custom Carbon type:
Here is the custom type:
Expected behaviour
The queries should not happen in that frequency
The text was updated successfully, but these errors were encountered: