magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.45k stars 9.29k forks source link

GQL Custom field for ProductInterface is treated as attribute, wasting performance #38986

Closed adarshkhatri closed 1 week ago

adarshkhatri commented 1 month ago

Summary

Custom field for ProductInterface is treated as attribute by Magento. First it will check if this attribute exists and if it exists then it will try to load the data for a product.

This is unnecessary. This is impacting performance.

PS could be same for Category or any other types, I haven't tested it yet.

Examples

Take an example below:

interface ProductInterface {
    attribute_set_id: Int
        @doc(description: "ID of the attribute set assigned to the product")
}

In this example, Magento will do this query in the background:

INFO (6): SELECT `eav_attribute`.* FROM `eav_attribute` WHERE (`eav_attribute`.`attribute_code`='attribute_set_id') AND (entity_type_id = :entity_type_id)
INFO (6): {":entity_type_id":10}

As you can see, Magento is treating our custom field attribute_set_id as an attribute. It is checking if this attribute exists and if exists then it will try to load the data for a product.

Proposed solution

Do not treat them as attribute.

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 month ago

Hi @adarshkhatri. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

m2-assistant[bot] commented 1 month ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Hotel commented 1 month ago

Hello @adarshkhatri,

Thanks for the report and collaboration!

We have gone through the description and we can understand that you are concerned with the performance of Magento as the GQL Custom field for ProductInterface is treated as an attribute. But can you please let us know your use case in which you feel performance degradation? And the tool you used to calculate the performance.

Thanks

adarshkhatri commented 1 month ago

The performance impact would be for bigger databases/stores. When there are 100s of custom fields for the product interface, Magento is treating them as attributes. Running those 100s attribute queries (unnecessary queries) will impact the DB performance for the high visitor/transaction stores. In days like black Friday, system has to run precisely and should not lock the DB for no reason. With these queries running will definitely have the negative impact.

I don't have the number yet, I am on route to review the MySQL queries at the moment. Have been logging the queries and using NR to review them.

Should we focus on the degradation number (which will be diff for each instance), or should we discuss about the unnecessary DB impacts more?

engcom-Hotel commented 1 month ago

Hello @adarshkhatri,

Thank you for the detailed explanation.

Given the context of Magento 2, I believe it would be more beneficial to discuss the unnecessary impact on the database rather than focusing on specific degradation numbers, which can vary between instances. Understanding and addressing the root cause of these unnecessary queries will help us improve performance across all stores, especially during high-traffic periods like Black Friday.

Once you have the MySQL query logs and insights from New Relic, we can dive deeper into specific areas of improvement.

Looking forward to your findings and recommendations.

Thanks

engcom-Hotel commented 1 week ago

Dear @adarshkhatri,

We've observed that there haven't been any updates on this issue for quite some time. Therefore, we assume it's been resolved and will close it. Feel free to open a new ticket or reopen this one if you need more help.

Regards